Commit 54318e6a authored by cnguyen2's avatar cnguyen2
Browse files

Update endpoints and annotations for OpenAPI

parent ed3a2eec
Pipeline #159660 passed with stages
in 12 minutes and 47 seconds
......@@ -12,10 +12,10 @@
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus-plugin.version>1.4.2.Final</quarkus-plugin.version>
<quarkus-plugin.version>1.9.2.Final</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>1.4.2.Final</quarkus.platform.version>
<quarkus.platform.version>1.9.2.Final</quarkus.platform.version>
<surefire-plugin.version>2.22.1</surefire-plugin.version>
</properties>
<dependencyManagement>
......
package de.unigoettingen.ibeetlebase;
package de.unigoettingen.ibeetlebase.geneinfo;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
......
package de.unigoettingen.ibeetlebase.geneinfo;
import javax.ws.rs.core.Application;
import org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition;
import org.eclipse.microprofile.openapi.annotations.info.Info;
@OpenAPIDefinition(
info = @Info(title = "Gene Info Service",
description = "Get general information for fly and tribolium genes.",
version = "1.0")
)
public class GeneinfoApplication extends Application {
}
package de.unigoettingen.ibeetlebase.geneinfo.model;
import java.util.Set;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public class FlybaseGene {
private String id;
private String taxanomyId;
private String type;
private String symbol;
private String fullname;
private String annotationId;
private String transcriptType;
private Set<String> transcriptIds;
public FlybaseGene(String id, String taxanomyId, String type, String symbol,
String fullname, String annotationId, String transcriptType,
Set<String> transcriptIds) {
super();
this.id = id;
this.taxanomyId = taxanomyId;
this.type = type;
this.symbol = symbol;
this.fullname = fullname;
this.annotationId = annotationId;
this.transcriptType = transcriptType;
this.transcriptIds = transcriptIds;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTaxanomyId() {
return taxanomyId;
}
public void setTaxanomyId(String taxanomyId) {
this.taxanomyId = taxanomyId;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getSymbol() {
return symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getAnnotationId() {
return annotationId;
}
public void setAnnotationId(String annotationId) {
this.annotationId = annotationId;
}
public String getTranscriptType() {
return transcriptType;
}
public void setTranscriptType(String transcriptType) {
this.transcriptType = transcriptType;
}
public Set<String> getTranscriptIds() {
return transcriptIds;
}
public void setTranscriptId(Set<String> transcriptIds) {
this.transcriptIds = transcriptIds;
}
}
package de.unigoettingen.ibeetlebase.api.core;
package de.unigoettingen.ibeetlebase.geneinfo.model;
import java.util.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
public class Gene {
private String format = "flybase"; // Identifier for the source database which also implies a certain format of the contained information
......
package de.unigoettingen.ibeetlebase.geneinfo.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public class TriboliumGene {
private String id;
private String taxonomyId;
private String seqname;
private String source;
private String feature;
private String start;
private String end;
private String score;
private String strand;
private String frame;
private String locusTag;
public TriboliumGene(String id, String taxonomyId, String seqname, String source,
String feature, String start, String end, String score,
String strand, String frame, String locusTag) {
super();
this.id = id;
this.taxonomyId = taxonomyId;
this.seqname = seqname;
this.source = source;
this.feature = feature;
this.start = start;
this.end = end;
this.score = score;
this.strand = strand;
this.frame = frame;
this.locusTag = locusTag;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getSeqname() {
return seqname;
}
public void setSeqname(String seqname) {
this.seqname = seqname;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getFeature() {
return feature;
}
public void setFeature(String feature) {
this.feature = feature;
}
public String getStart() {
return start;
}
public void setStart(String start) {
this.start = start;
}
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
public String getScore() {
return score;
}
public void setScore(String score) {
this.score = score;
}
public String getStrand() {
return strand;
}
public void setStrand(String strand) {
this.strand = strand;
}
public String getFrame() {
return frame;
}
public void setFrame(String frame) {
this.frame = frame;
}
public String getLocusTag() {
return locusTag;
}
public void setLocusTag(String locusTag) {
this.locusTag = locusTag;
}
public String getTaxonomyId() {
return taxonomyId;
}
public void setTaxonomyId(String taxonomyId) {
this.taxonomyId = taxonomyId;
}
}
package de.unigoettingen.ibeetlebase.api;
package de.unigoettingen.ibeetlebase.geneinfo.resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import io.quarkus.runtime.Quarkus;
import io.quarkus.runtime.QuarkusApplication;
import io.quarkus.runtime.annotations.QuarkusMain;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.ws.rs.GET;
......@@ -15,18 +14,26 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.eclipse.microprofile.metrics.annotation.Metered;
import de.unigoettingen.ibeetlebase.api.core.FlyBase;
import de.unigoettingen.ibeetlebase.api.core.Gene;
import de.unigoettingen.ibeetlebase.api.core.OrthoAPI;
import de.unigoettingen.ibeetlebase.api.core.Tribolium;
@Path("/geneinfo")
import org.eclipse.microprofile.metrics.annotation.Metered;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.enums.ParameterIn;
import org.eclipse.microprofile.openapi.annotations.media.ExampleObject;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import de.unigoettingen.ibeetlebase.geneinfo.model.FlybaseGene;
import de.unigoettingen.ibeetlebase.geneinfo.model.Gene;
import de.unigoettingen.ibeetlebase.geneinfo.model.TriboliumGene;
import de.unigoettingen.ibeetlebase.geneinfo.service.FlyBase;
import de.unigoettingen.ibeetlebase.geneinfo.service.OrthoAPI;
import de.unigoettingen.ibeetlebase.geneinfo.service.Tribolium;
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
@QuarkusMain
public class GeneinfoResource implements QuarkusApplication {
//@QuarkusMain
public class GeneResource { //implements QuarkusApplication {
private static final String VERSION_STRING = "/{dataversion : [0-9]{6}|current}/v1";
// private static final String VERSION_STRING = "/{dataversion : [0-9]{6}|current}/v1";
@Inject
FlyBase fb;
......@@ -35,57 +42,67 @@ public class GeneinfoResource implements QuarkusApplication {
@Inject
OrthoAPI oa;
/**
* REST Endpoint for the Flybase data
* @param dataversion Version ID of the requested data - Required so older versions can be requested in the future
* @param fbgn The flybase identifier that information is requested for
* @return Gene information for all matching flybase gene identifiers (FBgn)
*/
@GET
@Metered
@Path(VERSION_STRING + "/flybase/{fbgn: FBgn[0-9]{7}}")
public Gene getFlybaseInfo(@PathParam("dataversion") final String dataversion, @PathParam("fbgn") final String fbgn) {
if (!checkFBgnID(fbgn)) {
return null;
}
return fb.retrieve(fbgn);
@Path("/flybase/genes/{id: FBgn[0-9]{7}}")
@Operation(summary = "Get information for a fly gene.")
public FlybaseGene getFlybaseGene(
@Parameter(
description = "Flybase gene identifier in format FBgn[0-9]{7}.",
example = "FBgn0000015")
@PathParam("id") String id) {
return Optional.ofNullable(fb.retrieve(id)).map(this::convertToFlybaseGene).orElse(null);
}
@GET
@Metered
@Path("/flybase/genes")
@Operation(summary = "Get information for a list of fly genes")
public List<FlybaseGene> getFlybaseGenes(
@Parameter(
in = ParameterIn.QUERY,
description = "Flybase gene identifiers in format FBgn[0-9]{7}",
examples = @ExampleObject(name = "FBgn0000015", value = "FBgn0000015"))
@QueryParam("ids") Set<String> ids) {
return ids.stream()
.filter(id -> checkFBgnID(id))
.map(id -> fb.retrieve(id))
.filter(gene -> gene != null)
.map(this::convertToFlybaseGene)
.collect(Collectors.toList());
}
/**
* REST Endpoint for the Tribolium data (from the iBB gff file)
* @param dataversion Version ID of the requested data - Required so older versions can be requested in the future
* @param tc The TC identifier that information is requested for
* @return Gene information for all matching tribolium gene identifiers (TC)
*/
@GET
@Metered
@Path(VERSION_STRING + "/tribolium/{tc: TC[0-9]{6}}")
public Gene getTriboliumInfo(@PathParam("dataversion") final String dataversion, @PathParam("tc") final String tc) {
if (!checkTCID(tc)) {
return null;
}
return tb.retrieve(tc);
@Path("/tribolium/genes/{id: TC[0-9]{6}}")
@Operation(summary = "Get information for a tribolium gene.")
public TriboliumGene getTriboliumGene(
@Parameter(
description = "Tribolium gene identifier in format TC[0-9]{6}}.",
example = "TC001906")
@PathParam("id") String tc) {
return Optional.ofNullable(tb.retrieve(tc)).map(this::convertToTriboliumGene).orElse(null);
}
/**
* Accepts multiple comma-separated gene IDs and returns the resulting gene information.
* @param ids The list of IDs
* @return Gene information for each queried ID
*/
@GET
@Metered
@Path(VERSION_STRING + "/gene")
public List<Gene> getInfo(@QueryParam("ids") final String ids) {
List<Gene> result_list = new ArrayList<Gene>();
for (String id : ids.split(",")) {
if (checkTCID(id)) {
result_list.add(tb.retrieve(id));
}
else if (checkFBgnID(id)) {
result_list.add(fb.retrieve(id));
}
}
return result_list;
@Path("/tribolium/genes")
@Operation(summary = "Get information for a list of fly genes")
public List<TriboliumGene> getTriboliumGenes(
@Parameter(
in = ParameterIn.QUERY,
description = "Tribolium gene identifiers in format TC[0-9]{6}",
examples = @ExampleObject(name = "TC001906", value = "TC001906"))
@QueryParam("ids") Set<String> ids) {
return ids.stream()
.filter(id -> checkTCID(id))
.map(id -> tb.retrieve(id))
.filter(gene -> gene != null)
.map(this::convertToTriboliumGene)
.collect(Collectors.toList());
}
/**
......@@ -111,24 +128,28 @@ public class GeneinfoResource implements QuarkusApplication {
* @param dataversion Version ID of the requested data - Required so older versions can be requested in the future
* @return All flybase gene identifiers and their according gene names
*/
/*
@GET
@Metered
@Path(VERSION_STRING + "/flybase/identifiers")
public Map<String, String> getAllFlybaseIDs(@PathParam("dataversion") final String dataversion) {
@Path("/flybase/identifiers")
public Map<String, String> getAllFlybaseIDs() {
return fb.getAllIDs();
}
*/
/**
* REST Endpoint that returns all tribolium gene identifiers and their according gene names
* @param dataversion Version ID of the requested data - Required so older versions can be requested in the future
* @return All TC gene identifiers and their according gene names
*/
/*
@GET
@Metered
@Path(VERSION_STRING + "/tribolium/identifiers")
public Map<String, String> getAllTriboliumIDs(@PathParam("dataversion") final String dataversion) {
@Path("/tribolium/identifiers")
public Map<String, String> getAllTriboliumIDs() {
return tb.getAllIDs();
}
*/
/**
* This function (requiring Quarkus 1.4.2) is called when the application is started
......@@ -136,6 +157,7 @@ public class GeneinfoResource implements QuarkusApplication {
* @param args The command line arguments
* @return The exit status (0)
*/
/*
@Override
public int run(String... args) throws Exception {
......@@ -147,5 +169,54 @@ public class GeneinfoResource implements QuarkusApplication {
Quarkus.waitForExit();
return 0;
}
*/
private FlybaseGene convertToFlybaseGene(Gene gene) {
Map<String, Collection<String>> info = gene.getInformation();
return new FlybaseGene(gene.getGeneID(),
collectionToString(organismToTaxonomyId(info.get("organism"))),
collectionToString(info.get("gene_type")),
collectionToString(info.get("gene_symbol")),
collectionToString(info.get("gene_fullname")),
collectionToString(info.get("annotation_ID")),
collectionToString(info.get("transcript_Type")),
info.get("transcript_ID").stream().collect(Collectors.toSet()));
}
private TriboliumGene convertToTriboliumGene(Gene gene) {
Map<String, Collection<String>> info = gene.getInformation();
return new TriboliumGene(gene.getGeneID(),
"7070",
collectionToString(info.get("seqname")),
collectionToString(info.get("source")),
collectionToString(info.get("feature")),
collectionToString(info.get("start")),
collectionToString(info.get("end")),
collectionToString(info.get("score")),
collectionToString(info.get("strand")),
collectionToString(info.get("frame")),
collectionToString(info.get("locus_tag")));
}
private Collection<String> organismToTaxonomyId(Collection<String> organisms) {
return organisms.stream().map(o -> {
switch (o) {
case "Dana":
return "7217";
case "Dmel":
return "7227";
case "Dvir":
return "7244";
case "Dpse":
return "7237";
case "Dsim":
return "7240";
}
return null;
}).collect(Collectors.toList());
}
private String collectionToString(Collection<String> items) {
return items.stream().collect(Collectors.joining(", "));
}
}
\ No newline at end of file
package de.unigoettingen.ibeetlebase.api.core;
package de.unigoettingen.ibeetlebase.geneinfo.service;
import java.io.BufferedReader;
import java.io.FileReader;
......@@ -9,7 +9,9 @@ import java.util.Map;
import java.util.LinkedList;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import de.unigoettingen.ibeetlebase.AppServiceBean;
import de.unigoettingen.ibeetlebase.geneinfo.AppServiceBean;
import de.unigoettingen.ibeetlebase.geneinfo.model.Gene;
@ApplicationScoped
public class FlyBase implements GeneSource {
......
package de.unigoettingen.ibeetlebase.api.core;
package de.unigoettingen.ibeetlebase.geneinfo.service;
import de.unigoettingen.ibeetlebase.geneinfo.model.Gene;
public interface GeneSource {
......
package de.unigoettingen.ibeetlebase.api.core;
package de.unigoettingen.ibeetlebase.geneinfo.service;
import java.util.*;
import javax.enterprise.context.ApplicationScoped;
......
package de.unigoettingen.ibeetlebase.api.core;
package de.unigoettingen.ibeetlebase.geneinfo.service;
import java.io.BufferedReader;
import java.io.FileReader;
......@@ -9,7 +9,9 @@ import java.util.Map;
import java.util.LinkedList;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import de.unigoettingen.ibeetlebase.AppServiceBean;
import de.unigoettingen.ibeetlebase.geneinfo.AppServiceBean;
import de.unigoettingen.ibeetlebase.geneinfo.model.Gene;
@ApplicationScoped
public class Tribolium implements GeneSource {
......
# Configuration file
# key = value
quarkus.http.cors=true
\ No newline at end of file
quarkus.http.cors=true
quarkus.http.root-path=/geneinfo/v1
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment