/*
* Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
* Copyright (C) 2014 The Jalview Authors
- *
+ *
* This file is part of Jalview.
- *
+ *
* Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
+ * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see <http://www.gnu.org/licenses/>.
* The Jalview Authors are detailed in the 'AUTHORS' file.
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
/**
* Helpful procedures for working with services via HTTPClient
- *
+ *
* @author jimp
- *
+ *
*/
public class HttpClientUtils
{
/**
* do a minimal HTTP post with URL-Encoded parameters passed in the Query
* string
- *
+ *
* @param postUrl
* @param vals
* @return Reader containing content, if any, or null if no entity returned.
}
}
+ public static String doHttpUrlGet(String getUrl /* , HttpParams params */)
+ throws ClientProtocolException, IOException
+ {
+ HttpClient httpclient = new DefaultHttpClient();
+ HttpGet httpget = new HttpGet(getUrl);
+ // httpget.setParams(params);
+ HttpResponse response = httpclient.execute(httpget);
+ HttpEntity resEntity = response.getEntity();
+
+
+ if (resEntity != null)
+ {
+ BufferedReader r = new BufferedReader(new InputStreamReader(
+ resEntity.getContent()));
+
+ String aux = "";
+ StringBuilder responseBuilder = new StringBuilder();
+ while ((aux = r.readLine()) != null)
+ {
+ responseBuilder.append(aux);
+ }
+ return responseBuilder.toString();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
public static BufferedReader doHttpMpartFilePost(String postUrl,
List<NameValuePair> vals, String fparm, File file, String mtype)
- throws ClientProtocolException, IOException
+ throws ClientProtocolException, IOException
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(postUrl);
package jalview.ws.dbsources;
+import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefSource;
-import jalview.ws.seqfetcher.DbSourceProxy;
+import jalview.io.FormatAdapter;
+import jalview.io.IdentifyFile;
+import jalview.ws.intermine.IntermineFetchClient;
import jalview.ws.seqfetcher.DbSourceProxyImpl;
+import java.util.Iterator;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+
import com.stevesoft.pat.Regex;
-public class Intermine extends DbSourceProxyImpl implements DbSourceProxy
+public class Intermine extends DbSourceProxyImpl // implements DbSourceProxy
{
@Override
@Override
public String getDbVersion()
{
- // TODO Auto-generated method stub
- return null;
+ return "0";
}
@Override
public String getAccessionSeparator()
{
- // TODO Auto-generated method stub
return null;
}
@Override
public Regex getAccessionValidator()
{
- // TODO Auto-generated method stub
return null;
}
- // @Override
- // public Hashtable getDbSourceProperties()
- // {
- // // TODO Auto-generated method stub
- // return null;
- // }
@Override
public String getTestQuery()
{
// TODO Auto-generated method stub
- return null;
+ return "http://www.flymine.org/query/service/jbrowse/7227/features/2L?start=100000&end=100200&reference=true";
}
@Override
public boolean isValidReference(String accession)
{
- // TODO Auto-generated method stub
return false;
}
@Override
- public AlignmentI getSequenceRecords(String queries) throws Exception
+ public AlignmentI getSequenceRecords(String query) throws Exception
{
- // TODO Auto-generated method stub
- return null;
+ startQuery();
+ String jsonString = IntermineFetchClient.fetchData(query);
+
+ Object sequenceString = "";
+ System.out.println("Found json: " + jsonString);
+ org.json.simple.parser.JSONParser jsonParser = new org.json.simple.parser.JSONParser();
+ try
+ {
+ JSONObject jobj = (JSONObject) jsonParser.parse(jsonString);
+ JSONArray responses = (JSONArray) jobj.get("features");
+ for (Iterator<JSONObject> rvals = responses.iterator(); rvals
+ .hasNext();)
+ {
+ JSONObject feature = rvals.next();
+ Object seq = feature.get("seq");
+ System.out.println("Sequence : " + seq.toString());
+ }
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ stopQuery();
+ return parseResult(sequenceString.toString());
}
@Override
- public boolean queryInProgress()
+ protected Alignment parseResult(String result) throws Exception
{
- // TODO Auto-generated method stub
- return false;
+ Alignment sequences = null;
+ String format = new IdentifyFile().Identify(result, "Paste");
+ if (FormatAdapter.isValidFormat(format))
+ {
+ sequences = new FormatAdapter().readFile(result, "Paste",
+ format);
+ }
+ return sequences;
}
- @Override
- public StringBuffer getRawRecords()
- {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public boolean isA(Object dbsourceproperty)
- {
- // TODO Auto-generated method stub
- return false;
- }
+
+
@Override
public int getTier()
{
- // TODO Auto-generated method stub
return 0;
}
--- /dev/null
+package jalview.ws.intermine;
+
+import jalview.ws.HttpClientUtils;
+
+import java.io.IOException;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.apache.http.client.ClientProtocolException;
+
+import com.sun.jersey.api.client.Client;
+
+public class IntermineFetchClient
+{
+
+ private static final Client client = Client.create();
+
+ 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(IntermineDB Database,
+ IntermineMethod method, MultivaluedMap<String, String> params)
+ {
+ String response = "";
+ if (params.isEmpty())
+ {
+
+ response = client.resource(Database.getURL() + method.getTarget())
+ .accept("text/plain")
+ .get(String.class);
+
+ }
+ else
+ {
+ response = client.resource(Database.getURL() + method.getTarget())
+ .queryParams(params)
+ .get(String.class);
+ }
+ return response;
+ }
+
+ public static String fetchData(String url)
+ throws ClientProtocolException, IOException
+ {
+
+ return HttpClientUtils.doHttpUrlGet(url);// client.resource(url).get(String.class);
+ }
+
+
+}