diff --git a/src/main/java/edu/ucsf/rbvi/stringApp/internal/model/Annotation.java b/src/main/java/edu/ucsf/rbvi/stringApp/internal/model/Annotation.java index cb2757ee..5fc5efd9 100644 --- a/src/main/java/edu/ucsf/rbvi/stringApp/internal/model/Annotation.java +++ b/src/main/java/edu/ucsf/rbvi/stringApp/internal/model/Annotation.java @@ -1,14 +1,15 @@ package edu.ucsf.rbvi.stringApp.internal.model; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; + import org.json.simple.JSONArray; import org.json.simple.JSONObject; -import edu.ucsf.rbvi.stringApp.internal.model.Species; import edu.ucsf.rbvi.stringApp.internal.utils.ModelUtils; public class Annotation { @@ -77,9 +78,9 @@ public String toString() { public boolean isResolved() {return resolved;} public void setResolved(boolean resolved) {this.resolved = resolved;} - public static Map> getAnnotations(JSONObject json, String queryTerms, Species species) { + public static Map> getAnnotations(JSONObject json, String queryTerms, Species species, String useDATABASE) { Map> map = new HashMap<>(); - return getAnnotations(json, queryTerms, map, species); + return getAnnotations(json, queryTerms, map, species, useDATABASE); } public static boolean allResolved(List annotations) { @@ -91,9 +92,11 @@ public static boolean allResolved(List annotations) { } public static Map> getAnnotations(JSONObject json, String queryTerms, - Map> map, Species species) { + Map> map, Species species, String useDATABASE) { String[] terms = queryTerms.trim().split("\n"); JSONArray annotationArray = ModelUtils.getResultsFromJSON(json, JSONArray.class); + if (useDATABASE.equals(Databases.JENSENLAB.getAPIName())) + annotationArray = (JSONArray) annotationArray.get(0); Integer version = ModelUtils.getVersionFromJSON(json); // If we switch the API back to use a start of 0, this will need to change @@ -110,13 +113,16 @@ public static Map> getAnnotations(JSONObject json, Stri String taxonName = null; int taxId = -1; int queryIndex = -1; + String query = null; String uniprot = null; String sequence = null; String image = null; String color = null; + // Fields coming from string-db if (ann.containsKey("preferredName")) preferredName = (String)ann.get("preferredName"); + // annotation contains the description of the entity as it comes from STRING-DB if (ann.containsKey("annotation")) annotation = (String)ann.get("annotation"); if (ann.containsKey("stringId")) @@ -143,6 +149,7 @@ public static Map> getAnnotations(JSONObject json, Stri species.setOfficialName(taxonName); } } + // Fields coming from string-db with csdata=1 if (ann.containsKey("uniprot")) uniprot = (String)ann.get("uniprot"); if (ann.containsKey("sequence")) @@ -152,6 +159,30 @@ public static Map> getAnnotations(JSONObject json, Stri if (ann.containsKey("image")) image = (String)ann.get("image"); + // Fields coming from jensenlab + if(ann.containsKey("primary")) { + preferredName = (String)ann.get("primary"); + if (description != null && !description.equals("")) + annotation = description; + } + // TODO: type is actually the taxId, but do we need it? + //if (ann.containsKey("type")) + // taxId = (Long)ann.get("type"); + if(ann.containsKey("id")) { + if (ann.containsKey("type") && (Long)ann.get("type") != -1) + stringId = (Long)ann.get("type") + "." +(String)ann.get("id"); + else + stringId = (String)ann.get("id"); + } + // TODO: [N] Currently, we still get both CIDm and CIDs + // We only have networks for the CIDm, so we ignore the others for now + if (stringId.startsWith("CIDs")) + continue; + if(ann.containsKey("query")) { + query = (String)ann.get("query"); + queryIndex = Arrays.asList(terms).indexOf(query); + } + // Temporary HACK // if (stringId.startsWith("-1.CID1")) // stringId = stringId.replaceFirst("-1.CID1","CIDm"); diff --git a/src/main/java/edu/ucsf/rbvi/stringApp/internal/model/Databases.java b/src/main/java/edu/ucsf/rbvi/stringApp/internal/model/Databases.java index f66b6e4d..1cdb623a 100644 --- a/src/main/java/edu/ucsf/rbvi/stringApp/internal/model/Databases.java +++ b/src/main/java/edu/ucsf/rbvi/stringApp/internal/model/Databases.java @@ -10,7 +10,8 @@ public enum Databases { // AGOTOOL("aGOtool", "agotool") VIRUSES("Viruses", "viruses"), STITCH("Stitch", "stitch"), - STRINGDB("String-db", "string-db"); + STRINGDB("String-db", "string-db"), + JENSENLAB("Jensenlab", "jensenlab"); String dbName; String apiName; diff --git a/src/main/java/edu/ucsf/rbvi/stringApp/internal/model/StringNetwork.java b/src/main/java/edu/ucsf/rbvi/stringApp/internal/model/StringNetwork.java index a4dd9e82..850185e8 100644 --- a/src/main/java/edu/ucsf/rbvi/stringApp/internal/model/StringNetwork.java +++ b/src/main/java/edu/ucsf/rbvi/stringApp/internal/model/StringNetwork.java @@ -391,48 +391,72 @@ private Map> getAnnotationBatch(Species species, final try { results = HttpUtils.postJSON(url, args, manager); // System.out.println(results.toString()); + if (results != null) { + // System.out.println("Got results"); + annotations = Annotation.getAnnotations(results, encTerms, annotations, species, Databases.STRING.getAPIName()); + // System.out.println("Get annotations returns "+annotations.size()); + } } catch (ConnectionException ex) { if (ex instanceof UnknownSpeciesException && manager.isVirusesEnabled() && annotations.size() == 0 && includeViruses) { // also call the viruses API // http://viruses.string-db.org/cgi/webservice_handler.pl?species=11320&identifiers=NS1_I34A1 // &caller_identity=string_app_v1_1_1&output=json&request=resolveList - url = manager.getResolveURL(Databases.VIRUSES.getAPIName()); + //url = manager.getResolveURL(Databases.VIRUSES.getAPIName()); + //args = new HashMap<>(); + //args.put("species", speciesId); + //args.put("identifiers", encTerms); + //args.put("caller_identity", StringManager.CallerIdentity); + //args.put("output", "json"); + //args.put("request", "resolveList"); + //manager.info("URL:" + url + "?species=" + speciesId + "&caller_identity=" + // + StringManager.CallerIdentity + "&identifiers=" + HttpUtils.truncate(encTerms)); + + url = manager.getEntityQueryURL(); args = new HashMap<>(); - args.put("species", speciesId); - args.put("identifiers", encTerms); - args.put("caller_identity", StringManager.CallerIdentity); - args.put("output", "json"); - args.put("request", "resolveList"); - manager.info("URL:" + url + "?species=" + speciesId + "&caller_identity=" - + StringManager.CallerIdentity + "&identifiers=" + HttpUtils.truncate(encTerms)); + args.put("limit", "5"); + args.put("types", speciesId); + args.put("format", "json"); + args.put("query", encTerms); + manager.info("URL: "+url+"?types=" + speciesId + "&limit=5&format=json"+"&identifiers="+HttpUtils.truncate(encTerms)); + // Get the results // System.out.println("Getting VIRUSES term resolution"); results = HttpUtils.postJSON(url, args, manager); + if (results != null) { + // System.out.println("Got results"); + annotations = Annotation.getAnnotations(results, encTerms, annotations, species, Databases.JENSENLAB.getAPIName()); + // System.out.println("Get annotations returns "+annotations.size()); + } } } - if (results != null) { - // System.out.println("Got results"); - annotations = Annotation.getAnnotations(results, encTerms, annotations, species); - // System.out.println("Get annotations returns "+annotations.size()); - } results = null; // then, call other APIs to get resolve them // resolve compounds if (useDATABASE.equals(Databases.STITCH.getAPIName())) { - url = manager.getResolveURL(Databases.STITCH.getAPIName())+"json/resolveList"; + //url = manager.getResolveURL(Databases.STITCH.getAPIName())+"json/resolveList"; + //args = new HashMap<>(); + //args.put("species", "CIDm"); + //args.put("identifiers", encTerms); + //args.put("caller_identity", StringManager.CallerIdentity); + // manager.info("URL: "+url+"?species="+speciesId+"&caller_identity="+StringManager.CallerIdentity+"&identifiers="+HttpUtils.truncate(encTerms)); + + url = manager.getEntityQueryURL(); args = new HashMap<>(); - args.put("species", "CIDm"); - args.put("identifiers", encTerms); - args.put("caller_identity", StringManager.CallerIdentity); - manager.info("URL: "+url+"?species="+speciesId+"&caller_identity="+StringManager.CallerIdentity+"&identifiers="+HttpUtils.truncate(encTerms)); + // we ask for 10 since half of them are CIDs, which we ignore + args.put("limit", "10"); + args.put("types", "-1"); + args.put("format", "json"); + args.put("query", encTerms); + manager.info("URL: "+url+"?types=-1&limit=10&format=json"+"&identifiers="+HttpUtils.truncate(encTerms)); + // Get the results // System.out.println("Getting STITCH term resolution"); results = HttpUtils.postJSON(url, args, manager); if (results != null) { - updateAnnotations(results, encTerms, species); + updateAnnotations(results, encTerms, species, Databases.JENSENLAB.getAPIName()); } results = null; } @@ -526,9 +550,9 @@ public List combineIds(Map reverseMap) { return ids; } - private void updateAnnotations(JSONObject results, String terms, Species species) { + private void updateAnnotations(JSONObject results, String terms, Species species, String useDATABASE) { Map> newAnnotations = Annotation.getAnnotations(results, - terms, species); + terms, species, useDATABASE); for (String newAnn : newAnnotations.keySet()) { List allAnn = new ArrayList(newAnnotations.get(newAnn)); if (annotations.containsKey(newAnn)) { diff --git a/src/main/java/edu/ucsf/rbvi/stringApp/internal/tasks/ExpandNetworkTask.java b/src/main/java/edu/ucsf/rbvi/stringApp/internal/tasks/ExpandNetworkTask.java index 69d53bf1..231e1455 100644 --- a/src/main/java/edu/ucsf/rbvi/stringApp/internal/tasks/ExpandNetworkTask.java +++ b/src/main/java/edu/ucsf/rbvi/stringApp/internal/tasks/ExpandNetworkTask.java @@ -194,7 +194,7 @@ public void run(TaskMonitor monitor) { Map args = new HashMap<>(); if (selectedType.equals(ModelUtils.COMPOUND)) { useDatabase = Databases.STITCH.getAPIName(); - args.put("filter", "CIDm%%"); + args.put("filter", "CIDm%"); args.put("existing",existing.trim()); args.put("score", conf.toString()); args.put("database", database); @@ -215,7 +215,7 @@ public void run(TaskMonitor monitor) { } else { useDatabase = Databases.STRING.getAPIName(); filterString = String.valueOf(selSpecies.getTaxId()); - args.put("filter", filterString + ".%%"); + args.put("filter", filterString + ".%"); args.put("existing",existing.trim()); args.put("score", conf.toString()); args.put("database", database); diff --git a/src/main/java/edu/ucsf/rbvi/stringApp/internal/tasks/LoadInteractions.java b/src/main/java/edu/ucsf/rbvi/stringApp/internal/tasks/LoadInteractions.java index 7a034bb7..2f871f78 100644 --- a/src/main/java/edu/ucsf/rbvi/stringApp/internal/tasks/LoadInteractions.java +++ b/src/main/java/edu/ucsf/rbvi/stringApp/internal/tasks/LoadInteractions.java @@ -121,9 +121,9 @@ else if (useDATABASE.equals(Databases.STRINGDB.getAPIName())) if (additionalNodes > 0) { args.put("additional", Integer.toString(additionalNodes)); if (useDATABASE.equals(Databases.STRING.getAPIName())) { - args.put("filter", String.valueOf(species.getTaxId()) + ".%%"); + args.put("filter", String.valueOf(species.getTaxId()) + ".%"); } else { - args.put("filter", String.valueOf(species.getTaxId()) + ".%%|CIDm%%"); + args.put("filter", String.valueOf(species.getTaxId()) + ".%|CIDm%"); } } } diff --git a/src/main/java/edu/ucsf/rbvi/stringApp/internal/tasks/LoadTermsTask.java b/src/main/java/edu/ucsf/rbvi/stringApp/internal/tasks/LoadTermsTask.java index e6b0605b..1f0a46ea 100644 --- a/src/main/java/edu/ucsf/rbvi/stringApp/internal/tasks/LoadTermsTask.java +++ b/src/main/java/edu/ucsf/rbvi/stringApp/internal/tasks/LoadTermsTask.java @@ -118,9 +118,9 @@ public void run(TaskMonitor monitor) { if (additionalNodes > 0) { args.put("additional", Integer.toString(additionalNodes)); if (useDATABASE.equals(Databases.STRING.getAPIName())) { - args.put("filter", taxString + ".%%"); + args.put("filter", taxString + ".%"); } else if (useDATABASE.equals(Databases.STITCH.getAPIName())) { - args.put("filter", taxString + ".%%|CIDm%%"); + args.put("filter", taxString + ".%|CIDm%"); } } } diff --git a/src/main/java/edu/ucsf/rbvi/stringApp/internal/ui/GetTermsPanel.java b/src/main/java/edu/ucsf/rbvi/stringApp/internal/ui/GetTermsPanel.java index 997c8d07..8dda05d2 100644 --- a/src/main/java/edu/ucsf/rbvi/stringApp/internal/ui/GetTermsPanel.java +++ b/src/main/java/edu/ucsf/rbvi/stringApp/internal/ui/GetTermsPanel.java @@ -506,14 +506,16 @@ private void showTableRow(JTable table, String term, Map a } @Override - public int getColumnCount() { return 3; } + public int getColumnCount() { return 4; } @Override public int getRowCount() { @@ -48,6 +48,8 @@ public String getColumnName(int columnIndex) { case 1: return "Name"; case 2: + return "ID"; + case 3: return "Description"; } return ""; @@ -62,6 +64,8 @@ public Class getColumnClass(int columnIndex) { return String.class; case 2: return String.class; + case 3: + return String.class; } return null; } @@ -75,6 +79,8 @@ public Object getValueAt(int rowIndex, int columnIndex) { case 1: return ann.getPreferredName(); case 2: + return ann.getStringId(); + case 3: return ann.getAnnotation(); } return null;