From 2da36f2ca07cd5e0dc22bced4ba330179c982c13 Mon Sep 17 00:00:00 2001 From: Charles Ofoegbu Date: Tue, 21 Oct 2014 13:30:14 +0100 Subject: [PATCH] Added support for different intermine database variants --- src/jalview/ws/SequenceFetcher.java | 7 +- src/jalview/ws/dbsources/FlyMine.java | 22 ++++ src/jalview/ws/dbsources/Intermine.java | 139 ++++++++++++-------- src/jalview/ws/dbsources/ModMine.java | 21 +++ src/jalview/ws/dbsources/MouseMine.java | 21 +++ src/jalview/ws/dbsources/RatMine.java | 22 ++++ src/jalview/ws/dbsources/YeastMine.java | 23 ++++ src/jalview/ws/intermine/IntermineFetchClient.java | 86 ------------ 8 files changed, 198 insertions(+), 143 deletions(-) create mode 100644 src/jalview/ws/dbsources/FlyMine.java create mode 100644 src/jalview/ws/dbsources/ModMine.java create mode 100644 src/jalview/ws/dbsources/MouseMine.java create mode 100644 src/jalview/ws/dbsources/RatMine.java create mode 100644 src/jalview/ws/dbsources/YeastMine.java delete mode 100644 src/jalview/ws/intermine/IntermineFetchClient.java diff --git a/src/jalview/ws/SequenceFetcher.java b/src/jalview/ws/SequenceFetcher.java index 1c9e6c1..0f2c64d 100644 --- a/src/jalview/ws/SequenceFetcher.java +++ b/src/jalview/ws/SequenceFetcher.java @@ -67,7 +67,12 @@ public class SequenceFetcher extends ASequenceFetcher // PFAM addDBRefSourceImpl(jalview.ws.dbsources.RfamFull.class); addDBRefSourceImpl(jalview.ws.dbsources.RfamSeed.class); - addDBRefSourceImpl(jalview.ws.dbsources.Intermine.class); + + addDBRefSourceImpl(jalview.ws.dbsources.FlyMine.class); + addDBRefSourceImpl(jalview.ws.dbsources.ModMine.class); + addDBRefSourceImpl(jalview.ws.dbsources.MouseMine.class); + addDBRefSourceImpl(jalview.ws.dbsources.RatMine.class); + addDBRefSourceImpl(jalview.ws.dbsources.YeastMine.class); if (addDas) { registerDasSequenceSources(); diff --git a/src/jalview/ws/dbsources/FlyMine.java b/src/jalview/ws/dbsources/FlyMine.java new file mode 100644 index 0000000..d597608 --- /dev/null +++ b/src/jalview/ws/dbsources/FlyMine.java @@ -0,0 +1,22 @@ +package jalview.ws.dbsources; + +import jalview.datamodel.AlignmentI; + +public class FlyMine extends Intermine +{ + public FlyMine() + { + this.name = "FlyMine"; + this.baseUrl = "http://www.flymine.org/query"; + this.domain = "7227"; + this.testQuery = "2L"; + } + + @Override + public AlignmentI getSequenceRecords(String queries) throws Exception + { + return getAlignmentData(baseUrl, queries, domain, seqStart, + seqEnd); + } + +} diff --git a/src/jalview/ws/dbsources/Intermine.java b/src/jalview/ws/dbsources/Intermine.java index 0d9ce02..d319c50 100644 --- a/src/jalview/ws/dbsources/Intermine.java +++ b/src/jalview/ws/dbsources/Intermine.java @@ -1,23 +1,35 @@ package jalview.ws.dbsources; import jalview.datamodel.Alignment; -import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefSource; import jalview.datamodel.Sequence; -import jalview.io.FormatAdapter; -import jalview.io.IdentifyFile; -import jalview.ws.intermine.IntermineFetchClient; +import jalview.ws.HttpClientUtils; import jalview.ws.seqfetcher.DbSourceProxyImpl; +import java.io.IOException; import java.util.Iterator; +import java.util.StringTokenizer; +import org.apache.http.client.ClientProtocolException; import org.json.simple.JSONArray; import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; import com.stevesoft.pat.Regex; -public class Intermine extends DbSourceProxyImpl // implements DbSourceProxy +public abstract class Intermine extends DbSourceProxyImpl { + protected int seqStart = 1; + + protected int seqEnd = 500; + + protected String domain = "7227"; + + protected String name = "Intermine"; + + protected String baseUrl = ""; + + protected String testQuery = ""; @Override public String getDbSource() @@ -28,15 +40,16 @@ public class Intermine extends DbSourceProxyImpl // implements DbSourceProxy @Override public String getDbName() { - return "Intermine"; + return "INTERMINE_" + this.name; } @Override public String getDbVersion() { - return "0"; + return baseUrl; } + @Override public String getAccessionSeparator() { @@ -49,12 +62,10 @@ public class Intermine extends DbSourceProxyImpl // implements DbSourceProxy return null; } - @Override public String getTestQuery() { - // TODO Auto-generated method stub - return "http://www.flymine.org/query/service/jbrowse/7227/features/2L?start=100000&end=100200&reference=true"; + return testQuery; } @Override @@ -64,67 +75,83 @@ public class Intermine extends DbSourceProxyImpl // implements DbSourceProxy } @SuppressWarnings("unchecked") - @Override - public AlignmentI getSequenceRecords(String query) throws Exception + public Alignment getAlignmentData(String baseUrl, String query, + String domain, int seqStart, int seqEnd) { - startQuery(); - String jsonString = IntermineFetchClient.fetchData(query); - Sequence[] retrievedSeq = null; - String sequence = ""; - String name = ""; - System.out.println("Found json: " + jsonString); - org.json.simple.parser.JSONParser jsonParser = new org.json.simple.parser.JSONParser(); + + StringTokenizer queries = new StringTokenizer(query, ";"); + + int count = 0; + Sequence[] retrievedSeq = new Sequence[queries.countTokens()]; try { - JSONObject jobj = (JSONObject) jsonParser.parse(jsonString); - JSONArray responses = (JSONArray) jobj.get("features"); - int count = 0; - for (Iterator rvals = responses.iterator(); rvals - .hasNext();) + while (queries.hasMoreTokens()) { - retrievedSeq = new Sequence[responses.size()]; - - JSONObject feature = rvals.next(); - // name = feature.get("name").toString(); - name = "name"; - sequence = feature.get("seq").toString(); - int start = Integer.valueOf(feature.get("start").toString()); - int end = Integer.valueOf(feature.get("end").toString()); - - retrievedSeq[count++] = new Sequence(name, sequence, start, end); - - System.out.println("Sequence : " + sequence); - + String uniquequery = queries.nextToken(); + String seqRef = uniquequery; + // StringTokenizer queryParam = new StringTokenizer(uniquequery, ":"); + String[] queryParam = uniquequery.split(":"); + if (queryParam.length > 1) + { + seqRef = queryParam[0]; + String[] positions = queryParam[1].split("-"); + if (positions.length > 1) + { + seqStart = Integer.valueOf(positions[0]); + seqEnd = Integer.valueOf(positions[1]); + } + } + + startQuery(); + String rawSequenceData = fetchData(baseUrl, + seqRef, domain, + seqStart, seqEnd, true); + String rawAnnotationData = fetchData(baseUrl, + uniquequery, domain, seqStart, seqEnd, false); + stopQuery(); + + String sequenceString = ""; + + // System.out.println("Sequence data: " + rawSequenceData); + // System.out.println("Annotation data : " + rawAnnotationData); + JSONParser jsonParser = new JSONParser(); + JSONObject rawSeqJson = (JSONObject) jsonParser + .parse(rawSequenceData); + // JSONObject rawAnotJson = (JSONObject) + // jsonParser.parse(rawAnnotationData); + JSONArray rawSeqJsonArray = (JSONArray) rawSeqJson.get("features"); + for (Iterator sequenceIter = rawSeqJsonArray.iterator(); sequenceIter + .hasNext();) + { + // retrievedSeq = new Sequence[rawSeqJsonArray.size()]; + JSONObject feature = sequenceIter.next(); + sequenceString = feature.get("seq").toString(); + int start = Integer.valueOf(feature.get("start").toString()); + int end = Integer.valueOf(feature.get("end").toString()); + + retrievedSeq[count++] = new Sequence(uniquequery, sequenceString, + start, + end); + } } } catch (Exception e) { e.printStackTrace(); } - stopQuery(); - return parseResult(retrievedSeq); - } - - @Override - protected Alignment parseResult(String result) throws Exception - { - Alignment sequences = null; - String format = new IdentifyFile().Identify(result, "Paste"); - if (FormatAdapter.isValidFormat(format)) - { - sequences = new FormatAdapter().readFile(result, "Paste", - format); - } - return sequences; + return new Alignment(retrievedSeq); } - private Alignment parseResult(Sequence[] seqs) + private static String fetchData(String baseUrl, String seqRef, + String domain, int start, int end, Boolean fetchRef) + throws ClientProtocolException, IOException { - Alignment sequences = new Alignment(seqs); - return sequences; + String resourceUrl = baseUrl + "/service/jbrowse/" + domain + + "/features/" + seqRef + "?start=" + start + "&end=" + end + + "&reference=" + fetchRef; + return HttpClientUtils.doHttpUrlGet(resourceUrl); } - @Override public int getTier() { diff --git a/src/jalview/ws/dbsources/ModMine.java b/src/jalview/ws/dbsources/ModMine.java new file mode 100644 index 0000000..c8c0d0d --- /dev/null +++ b/src/jalview/ws/dbsources/ModMine.java @@ -0,0 +1,21 @@ +package jalview.ws.dbsources; + +import jalview.datamodel.AlignmentI; + +public class ModMine extends Intermine +{ + public ModMine() + { + this.name = "ModMine"; + this.baseUrl = "http://intermine.modencode.org/modminetest"; + this.domain = "7227"; + this.testQuery = "2L"; + } + + @Override + public AlignmentI getSequenceRecords(String queries) throws Exception + { + return getAlignmentData(baseUrl, queries, domain, seqStart, seqEnd); + } + +} diff --git a/src/jalview/ws/dbsources/MouseMine.java b/src/jalview/ws/dbsources/MouseMine.java new file mode 100644 index 0000000..15306c11 --- /dev/null +++ b/src/jalview/ws/dbsources/MouseMine.java @@ -0,0 +1,21 @@ +package jalview.ws.dbsources; + +import jalview.datamodel.AlignmentI; + +public class MouseMine extends Intermine +{ + public MouseMine() + { + this.name = "MouseMine"; + this.baseUrl = "http://www.mousemine.org/mousemine"; + this.domain = "7227"; + this.testQuery = ""; + } + + @Override + public AlignmentI getSequenceRecords(String queries) throws Exception + { + return getAlignmentData(baseUrl, queries, domain, seqStart, seqEnd); + } + +} diff --git a/src/jalview/ws/dbsources/RatMine.java b/src/jalview/ws/dbsources/RatMine.java new file mode 100644 index 0000000..25dfb46 --- /dev/null +++ b/src/jalview/ws/dbsources/RatMine.java @@ -0,0 +1,22 @@ +package jalview.ws.dbsources; + +import jalview.datamodel.AlignmentI; + +public class RatMine extends Intermine +{ + + public RatMine() + { + this.name = "RatMine"; + this.baseUrl = "http://ratmine.mcw.edu/ratmine"; + this.domain = "7227"; + this.testQuery = ""; + } + + @Override + public AlignmentI getSequenceRecords(String queries) throws Exception + { + return getAlignmentData(baseUrl, queries, domain, seqStart, seqEnd); + } + +} diff --git a/src/jalview/ws/dbsources/YeastMine.java b/src/jalview/ws/dbsources/YeastMine.java new file mode 100644 index 0000000..15fa8fe --- /dev/null +++ b/src/jalview/ws/dbsources/YeastMine.java @@ -0,0 +1,23 @@ +package jalview.ws.dbsources; + +import jalview.datamodel.AlignmentI; + +public class YeastMine extends Intermine +{ + public YeastMine() + { + this.name = "YeastMine"; + this.baseUrl = "http://yeastmine.yeastgenome.org/yeastmine"; + this.domain = "4932"; + this.testQuery = "chrI"; + } + + @Override + public AlignmentI getSequenceRecords(String queries) throws Exception + { + return getAlignmentData(baseUrl, queries, domain, seqStart, seqEnd); + } + + + +} diff --git a/src/jalview/ws/intermine/IntermineFetchClient.java b/src/jalview/ws/intermine/IntermineFetchClient.java deleted file mode 100644 index 321bb85..0000000 --- a/src/jalview/ws/intermine/IntermineFetchClient.java +++ /dev/null @@ -1,86 +0,0 @@ -package jalview.ws.intermine; - -import jalview.ws.HttpClientUtils; - -import java.io.IOException; - -import org.apache.http.client.ClientProtocolException; - - -public class IntermineFetchClient -{ - - - public static enum IntermineDB - { - YeastMine("Yeast Mine", "http://yeastmine.yeastgenome.org/yeastmine"), FlyMine( - "Fly Mine", "http://www.flymine.org/query"), FlyMine_Beta( - "Fly Mine Beta", - "http://beta.flymine.org/beta"), MouseMine("Mouse Mine", - "http://www.mousemine.org/mousemine"), modMine( - "Mod Mine", - "http://intermine.modencode.org/modminetest"), RatMine( - "Rat Mine", "http://ratmine.mcw.edu/ratmine"); - - private final String name; - private final String Url; - - IntermineDB(String name, String Url) - { - this.Url = Url; - this.name = name; - } - - public String getName() - { - return this.name; - } - - public String getURL() - { - return this.Url; - } - } - - public static enum IntermineMethod - { - GET_VERSION("/service/version"), GET_RELEASE("/service/version/release"), GET_FASTA_LIST( - "/service/list/results/fasta"), GET_FASTA_QUERY( - "/query/results/fasta"); - - private final String target; - - IntermineMethod(String target) - { - this.target = target; - } - - public String getTarget() - { - return target; - } - - } - - public static String[] getSupportedDBs() - { - String[] supportedDbs = new String[IntermineDB.values().length]; - int count = 0; - for (IntermineDB db : IntermineDB.values()) - { - supportedDbs[count++] = db.getName(); - } - return supportedDbs; - - } - - - public static String fetchData(String url) - throws ClientProtocolException, IOException - { - - return HttpClientUtils.doHttpUrlGet(url);// client.resource(url).get(String.class); - } - - -} -- 1.7.10.2