<classpathentry kind="lib" path="appletlib/JmolApplet-12.2.4.jar"/>
<classpathentry kind="lib" path="lib/jdas-1.0.4.jar"/>
<classpathentry kind="lib" path="lib/spring-core-3.0.5.RELEASE.jar"/>
- <classpathentry kind="lib" path="lib/spring-web-3.0.5.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/VARNAv3-9.jar" sourcepath="/Users/jimp/Documents/Jalview/VARNA/VARNAv3-9-src.jar"/>
+ <classpathentry kind="lib" path="lib/spring-web-3.0.5.RELEASE.jar" sourcepath="/Users/jimp/.m2/repository/org/springframework/spring-web/3.0.5.RELEASE/spring-web-3.0.5.RELEASE-sources.jar"/>
+ <classpathentry kind="lib" path="lib/json_simple-1.1.jar" sourcepath="/Users/jimp/Downloads/json_simple-1.1-all.zip"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/plugin.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="classes"/>
/dist
/classes
.externalToolBuilders/Jalview Release indices [Builder].launch
+/.DS_Store
+/.com.apple.timemachine.supported
wsdl4j.jar
xercesImpl.jar
xml-apis.jar
-
+json_simple-1.1.jar : Apache 2.0 license : downloaded from https://code.google.com/p/json-simple/downloads/list (will move to 1.1.1 version when jalview is mavenised and osgi-ised)
Additional dependencies
examples/javascript/deployJava.js : http://java.com/js/deployJava.js
import jalview.ws.HttpClientUtils;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.Reader;
+import java.io.StringReader;
+import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.JSONStreamAware;
+import org.json.simple.parser.ContentHandler;
+import org.json.simple.parser.ParseException;
+/**
+ * simple methods for calling the various paradise RNA tools
+ *
+ * @author jimp
+ *
+ * History: v1.0 revised from original due to refactoring of
+ * paradise-ubmc.u-strasbg.fr/webservices/annotate3d to
+ * http://arn-ibmc.in2p3.fr/api/compute/2d?tool=rnaview
+ */
public class Annotate3D
{
+ private static String twoDtoolsURL = "http://arn-ibmc.in2p3.fr/api/compute/2d";
+ private static ContentHandler createContentHandler()
+ {
+ ContentHandler ch = new ContentHandler() {
+
+ @Override
+ public void startJSON() throws ParseException, IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void endJSON() throws ParseException, IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean startObject() throws ParseException, IOException
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean endObject() throws ParseException, IOException
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean startObjectEntry(String key) throws ParseException,
+ IOException
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
- public static Reader getRNAMLForPDBFileAsString(String pdbfile)
+ @Override
+ public boolean endObjectEntry() throws ParseException, IOException
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean startArray() throws ParseException, IOException
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean endArray() throws ParseException, IOException
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean primitive(Object value) throws ParseException,
+ IOException
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ };
+ return ch;
+ }
+ public static Iterator<Reader> getRNAMLForPDBFileAsString(String pdbfile)
throws Exception
{
List<NameValuePair> vals = new ArrayList<NameValuePair>();
+ vals.add(new BasicNameValuePair("tool", "rnaview"));
vals.add(new BasicNameValuePair("data", pdbfile));
- return HttpClientUtils.doHttpUrlPost(
- "http://paradise-ibmc.u-strasbg.fr/webservices/annotate3d",
- vals);
+ vals.add(new BasicNameValuePair("output", "rnaml"));
+ return processJsonResponseFor(HttpClientUtils.doHttpUrlPost(twoDtoolsURL, vals));
+ }
+ public static Iterator<Reader> processJsonResponseFor(Reader respons) throws Exception
+ {
+ org.json.simple.parser.JSONParser jp = new org.json.simple.parser.JSONParser();
+ try {
+ final JSONArray responses = (JSONArray) jp.parse(respons);
+ final Iterator rvals = responses.iterator();
+ return new Iterator<Reader>()
+ {
+ @Override
+ public boolean hasNext()
+ {
+ return rvals.hasNext();
+ }
+ @Override
+ public Reader next()
+ {
+ JSONObject val=(JSONObject) rvals.next();
+
+ Object sval = null;
+ try {
+ sval = val.get("2D");
+ } catch (Exception x) {x.printStackTrace();};
+ if (sval==null)
+ {
+ System.err.println("DEVELOPER WARNING: Annotate3d didn't return a '2D' tag in its response. Consider checking output of server. Response was :"+val.toString());
+
+ sval = "";
+ }
+ return new StringReader((sval instanceof JSONObject) ? ((JSONObject)sval).toString():sval.toString());
+
+ }@Override
+ public void remove()
+ {
+ throw new Error("Remove: Not implemented");
+
+ }@Override
+ protected Object clone() throws CloneNotSupportedException
+ {
+ throw new CloneNotSupportedException("Clone: Not implemented");
+ }@Override
+ public boolean equals(Object obj)
+ {
+ return super.equals(obj);
+ }@Override
+ protected void finalize() throws Throwable
+ {
+ while (rvals.hasNext())
+ {
+ rvals.next();
+ }
+ super.finalize();
+ }
+ };
+ } catch (Exception foo)
+ {
+ throw new Exception("Couldn't parse response from Annotate3d server.",foo);
+ }
+
+
}
- public static Reader getRNAMLForPDBId(String pdbid) throws Exception
+ public static Iterator<Reader> getRNAMLForPDBId(String pdbid) throws Exception
{
List<NameValuePair> vals = new ArrayList<NameValuePair>();
+ vals.add(new BasicNameValuePair("tool", "rnaview"));
vals.add(new BasicNameValuePair("pdbid", pdbid));
- return HttpClientUtils.doHttpUrlPost(
- "http://paradise-ibmc.u-strasbg.fr/webservices/annotate3d",
- vals);
+ vals.add(new BasicNameValuePair("format", "rnaml"));
+ java.net.URL geturl = new URL(twoDtoolsURL+"?tool=rnaview&output=rnaml&pdbid="+pdbid);
+ return processJsonResponseFor(new InputStreamReader(geturl.openStream()));
}
}
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
+import java.util.Iterator;
public class Annotate3D
{
sb.append(cbuff[i]);
}
}
-
- FileParse fp = new InputStreamParser(
- jalview.ext.paradise.Annotate3D.getRNAMLForPDBFileAsString(sb
- .toString()), source.getDataName());
- AlignmentI nal = new FormatAdapter().readFromFile(fp, "RNAML");
- return nal;
+ Iterator<Reader> r = jalview.ext.paradise.Annotate3D
+ .getRNAMLForPDBFileAsString(sb.toString());
+ AlignmentI al=null;
+ while (r.hasNext())
+ {
+ FileParse fp = new InputStreamParser(r.next(), source.getDataName());
+ AlignmentI nal = new FormatAdapter().readFromFile(fp, "RNAML");
+ if (al==null)
+ {
+ al = nal;
+ } else {
+ al.append(nal);
+ }
+ }
+ return al;
} catch (Throwable x)
{
if (x instanceof IOException)
import java.io.BufferedReader;
import java.io.File;
+import java.io.Reader;
+import java.util.Iterator;
import org.junit.Assert;
import org.junit.Test;
@Test
public void testIdVsContent() throws Exception
{
- BufferedReader id = (BufferedReader) Annotate3D
+ Iterator<Reader> ids = Annotate3D
.getRNAMLForPDBId("2GIS");
- assertTrue("Didn't retrieve 2GIS by id.", id != null);
- BufferedReader file = (BufferedReader) Annotate3D
+ assertTrue("Didn't retrieve 2GIS by id.", ids != null);
+ Iterator<Reader> files = Annotate3D
.getRNAMLForPDBFileAsString(FileUtil.readFileToString(new File(
"examples/2GIS.pdb")));
- assertTrue("Didn't retrieve using examples/2GIS.pdb.", file != null);
+ assertTrue("Didn't retrieve using examples/2GIS.pdb.", files != null);
+ int i=0;
+ while (ids.hasNext() && files.hasNext())
+ {
+ BufferedReader file=new BufferedReader(files.next()), id=new BufferedReader(ids.next());
String iline, fline;
do
{
System.out.println(iline);
if (fline != null)
System.out.println(fline);
-
- assertTrue("Results differ for ID and file upload based retrieval",
+ // next assert fails for latest RNAview - because the XMLID entries change between file and ID based RNAML generation.
+ assertTrue("Results differ for ID and file upload based retrieval (chain entry "+(++i)+")",
((iline == fline && iline == null) || (iline != null
&& fline != null && iline.equals(fline))));
} while (iline != null);
+ }
}
/**
StringBuffer sb = new StringBuffer();
// Comment - should add new FileParse constructor like new FileParse(Reader
// ..). for direct reading
- BufferedReader br = new BufferedReader(
- Annotate3D.getRNAMLForPDBFileAsString(FileUtil
- .readFileToString(new File("examples/2GIS.pdb"))));
- String line;
- while ((line = br.readLine()) != null)
+ Iterator<Reader> readers = Annotate3D
+ .getRNAMLForPDBFileAsString(FileUtil.readFileToString(new File(
+ "examples/2GIS.pdb")));
+ int r=0;
+ while (readers.hasNext())
{
- sb.append(line + "\n");
- }
- assertTrue("No data returned by Annotate3D", sb.length() > 0);
- AlignmentI al = new FormatAdapter().readFile(sb.toString(),
- FormatAdapter.PASTE, "RNAML");
+ System.out.println("Testing RNAML input number "+(++r));
+ BufferedReader br = new BufferedReader(readers.next());
+ String line;
+ while ((line = br.readLine()) != null)
+ {
+ sb.append(line + "\n");
+ }
+ assertTrue("No data returned by Annotate3D", sb.length() > 0);
+ AlignmentI al = new FormatAdapter().readFile(sb.toString(),
+ FormatAdapter.PASTE, "RNAML");
- assertTrue("No alignment returned.", al != null);
- assertTrue("No sequences in returned alignment.", al.getHeight() > 0);
- for (SequenceI sq : al.getSequences())
- {
+ assertTrue("No alignment returned.", al != null);
+ assertTrue("No sequences in returned alignment.", al.getHeight() > 0);
+ for (SequenceI sq : al.getSequences())
{
- SequenceI struseq = null;
- String sq_ = new String(sq.getSequence()).toLowerCase();
- for (SequenceI _struseq : pdbf.getSeqsAsArray())
{
- if (new String(_struseq.getSequence()).toLowerCase().equals(sq_))
+ SequenceI struseq = null;
+ String sq_ = new String(sq.getSequence()).toLowerCase();
+ for (SequenceI _struseq : pdbf.getSeqsAsArray())
{
- struseq = _struseq;
- break;
+ if (new String(_struseq.getSequence()).toLowerCase()
+ .equals(sq_))
+ {
+ struseq = _struseq;
+ break;
+ }
+ }
+ if (struseq == null)
+ {
+ Assert.fail("Couldn't find this sequence in original input:\n"
+ + new FastaFile().print(new SequenceI[]
+ { sq }) + "\n\nOriginal input:\n"
+ + new FastaFile().print(pdbf.getSeqsAsArray()) + "\n");
}
- }
- if (struseq == null)
- {
- Assert.fail("Couldn't find this sequence in original input:\n"
- + new FastaFile().print(new SequenceI[]
- { sq }) + "\n\nOriginal input:\n"
- + new FastaFile().print(pdbf.getSeqsAsArray()) + "\n");
}
}
}