Skip to content

Commit

Permalink
Create a POST endpoint for annotating single variants.
Browse files Browse the repository at this point in the history
  • Loading branch information
janeliutw authored and holtgrewe committed Oct 3, 2023
1 parent bbb0a7e commit 4a4fc98
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Jannovar Changelog

## v0.42

### jannovar-cli
- Add a `/annotate-var` endpoint to the rest server that accepts POST method for annotating single variants.
* Launch with `jannovar-cli rest-server -d data/hg19_refseq.ser -d data/hg19_ensembl.ser`
* Then, query with request body
`{ "source": "refseq", "assembly" : "hg19", "chr": "chr1", "pos": "111926150", "ref" : "GGCACTCCAGGGGACTA", "alt" : "G" }`
or `{ "source": "ensembl", "assembly" : "hg19", "chr": "chr1", "pos": "111926150", "ref" : "GGCACTCCAGGGGACTA", "alt" : "G" }`
* `?no-3-prime-shifting` can also be sent as a query param to temporarily disable the shifting.

## v0.41

### jannovar-core
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package de.charite.compbio.jannovar.cmd.rest_server;

import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
import static spark.Spark.get;
import static spark.Spark.post;
import static spark.Spark.ipAddress;
import static spark.Spark.port;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import de.charite.compbio.jannovar.JannovarException;
import de.charite.compbio.jannovar.annotation.*;
import de.charite.compbio.jannovar.annotation.builders.AnnotationBuilderOptions;
Expand All @@ -18,6 +23,7 @@
import de.charite.compbio.jannovar.data.SerializationException;
import de.charite.compbio.jannovar.hgvs.AminoAcidCode;
import de.charite.compbio.jannovar.htsjdk.InvalidCoordinatesException;
import de.charite.compbio.jannovar.impl.parse.InvalidAttributeException;
import de.charite.compbio.jannovar.reference.GenomePosition;
import de.charite.compbio.jannovar.reference.GenomeVariant;
import de.charite.compbio.jannovar.reference.PositionType;
Expand Down Expand Up @@ -73,6 +79,30 @@ public RestServerCommand(String argv[], Namespace args) throws CommandLineParsin
res.type("application/json");
return new Gson().toJson(result);
});

post("/annotate-var", (req, res) -> {
try {
ObjectMapper mapper = new ObjectMapper();
String body = req.body();
Variant payload = mapper.readValue(body, Variant.class);
if (!payload.isValid()) {
throw new InvalidAttributeException("Missing required data");
}
final boolean threePrimeShifting = !req.queryMap().hasKey("no-3-prime-shifting") && isNt3PrimeShifting;
final String key = Joiner.on("/").join(payload.source, payload.assembly);
final JannovarData jvData = jvDatas.get(key);

final List<VariantAnnotationInfo> result = getVariantAnnotations(
payload.chr, payload.pos, payload.ref, payload.alt, threePrimeShifting, jvData);

res.type("application/json");
return new Gson().toJson(result);
} catch (JsonParseException | UnrecognizedPropertyException |
InvalidAttributeException | InvalidCoordinatesException e) {
res.status(HTTP_BAD_REQUEST);
return e.getMessage();
}
});
}

private static List<VariantAnnotationInfo> getVariantAnnotations(
Expand Down Expand Up @@ -140,4 +170,43 @@ public VariantAnnotationInfo(String transcriptId, Collection<String> variantEffe
}
}

private static class Variant {
private String source;
private String assembly;
private String chr;
private int pos;
private String ref;
private String alt;

public void setSource(String source) {
this.source = source;
}

public void setAssembly(String assembly) {
this.assembly = assembly;
}

public void setChr(String chr) {
this.chr = chr;
}

public void setPos(int pos) {
this.pos = pos;
}

public void setRef(String ref) {
this.ref = ref;
}

public void setAlt(String alt) {
this.alt = alt;
}

public boolean isValid() {
return source != null && !source.isEmpty() && assembly != null && !assembly.isEmpty() &&
chr != null && !chr.isEmpty() && pos > 0 && ref != null && !ref.isEmpty() &&
alt != null && !alt.isEmpty();
}
}

}

0 comments on commit 4a4fc98

Please sign in to comment.