JAL-1358 Just the eclipse project/classpath files so that I can stash changes and...
authorDaniel Barton <daluke.barton@gmail.com>
Tue, 27 Aug 2013 12:47:23 +0000 (13:47 +0100)
committerDaniel Barton <daluke.barton@gmail.com>
Tue, 27 Aug 2013 12:47:23 +0000 (13:47 +0100)
.classpath
src/jalview/ws/jws2/RNAalifoldClient.java [new file with mode: 0644]

index f396252..8f6f94c 100644 (file)
@@ -39,7 +39,6 @@
        <classpathentry kind="lib" path="lib/miglayout-4.0-swing.jar"/>
        <classpathentry kind="lib" path="lib/jswingreader-0.3.jar" sourcepath="/jswingreader"/>
        <classpathentry kind="lib" path="lib/commons-codec-1.3.jar"/>
-       <classpathentry kind="lib" path="lib/min-jaba-client-2.0.jar" sourcepath="/clustengine2"/>
        <classpathentry kind="lib" path="lib/Jmol-12.2.4.jar"/>
        <classpathentry kind="lib" path="appletlib/JmolApplet-12.2.4.jar"/>
        <classpathentry kind="lib" path="lib/jdas-1.0.4.jar"/>
@@ -48,5 +47,6 @@
        <classpathentry kind="lib" path="lib/VARNAv3-9-dev.jar"/>
        <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/plugin.jar"/>
        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+       <classpathentry kind="lib" path="lib/rnaalifold-jaba-dan-test3.jar"/>
        <classpathentry kind="output" path="classes"/>
 </classpath>
diff --git a/src/jalview/ws/jws2/RNAalifoldClient.java b/src/jalview/ws/jws2/RNAalifoldClient.java
new file mode 100644 (file)
index 0000000..70ddb7e
--- /dev/null
@@ -0,0 +1,140 @@
+package jalview.ws.jws2;
+
+import jalview.api.AlignCalcWorkerI;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.Annotation;
+import jalview.gui.AlignFrame;
+import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.WsParamSetI;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import compbio.data.msa.jaxws.Align;
+import compbio.data.sequence.Range;
+import compbio.data.sequence.Score;
+import compbio.data.sequence.RNAStructScoreManager;
+import compbio.data.sequence.ScoreManager;
+import compbio.metadata.Argument;
+
+public class RNAalifoldClient extends JabawsAlignCalcWorker implements
+               AlignCalcWorkerI 
+{
+       
+       String methodName;
+       
+       AlignFrame af;
+       
+       public RNAalifoldClient(Jws2Instance sh, AlignFrame alignFrame,
+                       WsParamSetI preset, List<Argument> paramset)
+       {
+               super(sh, alignFrame, preset, paramset);
+
+               
+               af = alignFrame;
+                               
+               methodName = sh.serviceType;
+
+       }
+       
+        @Override
+         public String getServiceActionText()
+         {
+           return "Submitting RNA alignment for Secondary Structure prediction using"
+                       + "RNAalifold Service";
+         }
+       
+       @Override
+       public void updateResultAnnotation(boolean immediate)
+       {
+
+               if (immediate || !calcMan.isWorking(this) && scoremanager != null) 
+               {
+                       
+
+                       
+                       List<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
+//                     ourAnnots = new ArrayList<AlignmentAnnotation>();
+
+                       // So I don't have to do any more casting
+                       List<String> structs = ((RNAStructScoreManager) scoremanager).getStructs();
+                       List<TreeSet<Score>> data = ((RNAStructScoreManager) scoremanager).getData();
+                       
+                       // Deal with the consensus structure and (?)BasePair Probabilities
+                       Annotation[] anns = new Annotation[structs.get(1).length()];
+
+                       // check if the first Score object is populated with base pair probabilities
+                       Score fscore = data.get(0).first();
+                       boolean BPScores = (fscore.getScores().size() > 0 
+                                       && fscore.getRanges() != null);
+
+                       TreeMap<Range, Float> basePairs = null;
+                       if (BPScores) {
+                               // The base pair probabilities are stored in a set in scoremanager... we want a map
+                               basePairs = new TreeMap<Range, Float>();
+                               for (Score score : data.get(0)) {
+                                       // The Score objects contain a set of size one containing the range and
+                                       //  an ArrayList<float> of size one containing the probabilty
+                                       basePairs.put(score.getRanges().first(), new Float(score.getScores().get(0)));
+                               }
+                       }
+
+                       // ignoring the Consensus alignemnt for now, get the Structure and make an AlignmentAnnotation
+                       String struct = structs.get(1);
+                       for (int i = 0; i < struct.length(); i++) {
+
+                               if (BPScores) {
+                                       // Return all the contacts associated with position i
+                                       List<Range> contacts = isContact(basePairs, i+1);
+
+                                       if (contacts.size() == 0) {
+                                               anns[i] = new Annotation(struct.substring(i, i+1), "", struct.charAt(i), 0f);
+                                       }
+                                       else if (contacts.size() == 1) {
+                                               // There is only one contact associated with this base
+                                               float prob = basePairs.get(contacts.get(i));
+                                               anns[i] = new Annotation(struct.substring(i, i+1), "", struct.charAt(i), prob);
+                                       }
+                                       else if (contacts.size() > 1) {
+                                               // For now we will simply deal with alternate contact information by mentioning its
+                                               //  existance in the description
+                                               float prob = basePairs.get(contacts.get(i));
+                                               anns[i] = new Annotation(struct.substring(i, i+1), "This base has alternate contact(s)",
+                                                               struct.charAt(i), prob);
+                                       }
+                               }
+                               else {
+                                       // Same as the first if from the previous block
+                                       anns[i] = new Annotation(struct.substring(i, i+1), "", struct.charAt(i), 0f);
+                               }
+                       }
+                       
+                       AlignmentAnnotation annot = new AlignmentAnnotation("Consensus Structure", "Free Energy", anns);
+                       annot.setScore(data.get(1).first().getScores().get(0));
+
+                       if (ourAnnot.size() > 0) {
+                               updateOurAnnots(ourAnnot);
+                       }
+
+               }
+       }
+       
+       // Check whether, at position i there is a base contact and return all the
+       //  contacts at this position. Should be in order of descending probability.
+       private List<Range> isContact(TreeMap<Range, Float> basePairs, int i) {
+               
+               List<Range> contacts = new ArrayList<Range>();
+               
+               for (Range contact : basePairs.keySet()) {
+                       // finds the contacts associtated with position i ordered by the natural
+                       //  ordering of the Scores TreeSet in ScoreManager which is, descending probability
+                       if (contact.from == i || contact.to == i) contacts.add(contact);
+               }
+               
+               return contacts;
+       }
+}