Commit 89ab964b authored by tim.tucholski's avatar tim.tucholski
Browse files

Added REST Endpoints that returns gene identifiers

parent 9ac8feb8
......@@ -12,18 +12,33 @@ public class AppServiceBean {
private static final Logger LOGGER = Logger.getLogger("ListenerBean");
/**
* Standard constructor for the service bean
*/
public AppServiceBean(){
super();
}
/**
* Logs the service start
* @param ev The event observed by the Logger
*/
void onStart(@Observes StartupEvent ev) {
LOGGER.info("The application is starting...");
}
/**
* Logs the service shutdown
* @param ev The event observed by the Logger
*/
void onStop(@Observes ShutdownEvent ev) {
LOGGER.info("The application is stopping...");
}
/**
* Returns the relative data directory path depending on the working directory
* @return The data directory
*/
public String getDataDir(){
if (System.getProperty("user.dir").endsWith("target")){
return "../data";
......
......@@ -4,19 +4,7 @@ import org.de.unigoettingen.ibeetlebase.api.core.FlyBase;
import org.de.unigoettingen.ibeetlebase.api.core.Tribolium;
import org.de.unigoettingen.ibeetlebase.api.core.Gene;
import org.eclipse.microprofile.metrics.annotation.Metered;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonNumber;
import javax.json.JsonObject;
import javax.json.JsonString;
import javax.json.JsonValue;
import javax.json.JsonValue.ValueType;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
......@@ -68,30 +56,6 @@ public class GeneinfoResource {
return tb.retrieve(tc);
}
@GET
@Metered
@Path(VERSION_STRING + "/flybase/all")
public JsonObject getFlybaseIDs(@PathParam("dataversion") final String dataversion) {
JsonObject resultObject = Json.createObjectBuilder().build();
int id_counter = 0;
Map<String, String> ids = fb.getAllIDs();
for (String gene_key: ids.keySet()) {
JsonArray gene_name = Json.createArrayBuilder().build();
gene_name.add(Json.createObjectBuilder().add(gene_key, ids.get(gene_key)).build());
resultObject.put(Integer.toString(id_counter), gene_name);
}
return resultObject;
}
@GET
@Metered
@Path(VERSION_STRING + "/tribolium/all")
public JsonObject getTriboliumIDs(@PathParam("dataversion") final String dataversion) {
return tb.getAllIDs();
}
/**
* Checks if a FlyBase gene identifier (FBgn) is in the right format
* @param fbgn The Flybase gene identifier to be checked
......@@ -110,5 +74,28 @@ public class GeneinfoResource {
return tc.matches("TC[0-9]{6}");
}
/**
* REST Endpoint that returns all flybase 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 flybase gene identifiers and their according gene names
*/
@GET
@Metered
@Path(VERSION_STRING + "/flybase/all")
public Map<String, String> getAllFlybaseIDs(@PathParam("dataversion") final String dataversion) {
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/all")
public Map<String, String> getAllTriboliumIDs(@PathParam("dataversion") final String dataversion) {
return tb.getAllIDs();
}
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ import org.de.unigoettingen.ibeetlebase.AppServiceBean;
public class FlyBase implements GeneSource {
private static final String SOURCE = "flybase";
private Map<String, Gene> database;
private Map<String, String> id_list;
private Map<String, String> id_list = new HashMap<>();
@Inject
AppServiceBean service;
......@@ -93,7 +93,9 @@ public class FlyBase implements GeneSource {
/* Check if the gene denoted by fbgn_id exists and add if needed */
Gene new_gene = database_flybase.get(fbgn_id);
if (new_gene == null){
id_list.put(wordsArray[2], wordsArray[3]); //Adds gene identifier and full name to the id list
if (wordsArray[2] != null && wordsArray[3] != null) {
id_list.put(wordsArray[2], wordsArray[3]); //Adds gene identifier and full name to the id list
}
new_gene = new Gene(fbgn_id, "flybase");
database_flybase.put(fbgn_id, new_gene);
}
......@@ -122,7 +124,12 @@ public class FlyBase implements GeneSource {
return null;
}
/**
* Returns a list of all identifiers and gene names
* @return A list containing identifiers and the according gene names
*/
public Map<String, String> getAllIDs() {
getDB();
return id_list;
}
......
......@@ -2,7 +2,18 @@ package org.de.unigoettingen.ibeetlebase.api.core;
public interface GeneSource {
/**
* Method that prompts information retrieval for a passed gene identifier
* @param gene_id The gene identifier that information is requested for
* @return The search results
*/
public Gene retrieve(String gene_id);
/**
* Method that searches for database matches given a gene identifier and appends them to a result Gene entity
* @param gene_id The gene identifier that information is requested for
* @param resultObject A Gene entity with the identifier and according database source already included
* @return A Gene entity containing information for the requested identifier, or null if none is found
*/
public Gene search(String gene_id, Gene resultObject);
}
\ No newline at end of file
......@@ -17,6 +17,7 @@ public class Tribolium implements GeneSource {
private Map<String, Gene> database;
private Map<String, String> id_list = new HashMap<>();
@Inject
AppServiceBean service;
......@@ -151,6 +152,7 @@ public class Tribolium implements GeneSource {
* @return A list containing identifiers and the according gene names
*/
public Map<String, String> getAllIDs() {
getDB();
return id_list;
}
}
\ 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