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()
@Override
public String getDbName()
{
- return "Intermine";
+ return "INTERMINE_" + this.name;
}
@Override
public String getDbVersion()
{
- return "0";
+ return baseUrl;
}
+
@Override
public String getAccessionSeparator()
{
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
}
@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<JSONObject> 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<JSONObject> 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()
{
+++ /dev/null
-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);
- }
-
-
-}