JAL-961 - annotatable datamodel objects can be queried to obtain annotation with...
authorjprocter <jprocter@compbio.dundee.ac.uk>
Wed, 23 May 2012 18:36:20 +0000 (19:36 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Wed, 23 May 2012 18:36:20 +0000 (19:36 +0100)
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/AlignmentI.java
src/jalview/datamodel/AnnotatedCollectionI.java
src/jalview/datamodel/SequenceGroup.java
src/jalview/ws/jws2/AAConsClient.java
src/jalview/ws/jws2/JabawsAlignCalcWorker.java

index 708e566..c32a40f 100755 (executable)
@@ -1292,4 +1292,47 @@ public class Alignment implements AlignmentI
     }
   }
 
+  @Override
+  public AlignmentAnnotation findOrCreateAnnotation(String name, boolean autoCalc,
+          SequenceI seqRef, SequenceGroup groupRef)
+  {
+    for (AlignmentAnnotation annot : 
+            getAlignmentAnnotation())
+    {
+      if (annot.autoCalculated == autoCalc
+              && annot.getCalcId().equals(name)
+              && annot.sequenceRef == seqRef && annot.groupRef == groupRef)
+      {
+        return annot;
+      }
+    }
+    AlignmentAnnotation annot = new AlignmentAnnotation(name, name,
+            new Annotation[1], 0f, 0f, AlignmentAnnotation.BAR_GRAPH);
+    annot.hasText = false;
+    annot.setCalcId(new String(name));
+    annot.autoCalculated = autoCalc;
+    if (seqRef != null)
+    {
+      annot.setSequenceRef(seqRef);
+    }
+    annot.groupRef = groupRef;
+    addAnnotation(annot);
+
+    return annot;
+  }
+
+  @Override
+  public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
+  {
+    ArrayList<AlignmentAnnotation> aa=new ArrayList<AlignmentAnnotation>();
+    for (AlignmentAnnotation a:getAlignmentAnnotation())
+    {
+      if (a.getCalcId()==calcId || (a.getCalcId()!=null && calcId!=null && a.getCalcId().equals(calcId)))
+      {
+        aa.add(a);
+      }
+    }
+    return aa;
+  }
+
 }
index a79106a..ec35124 100755 (executable)
@@ -431,4 +431,16 @@ public interface AlignmentI extends AnnotatedCollectionI
    * @param i
    */
   public void addAnnotation(AlignmentAnnotation consensus, int i);
+
+  /**
+   * search for or create a specific annotation row on the alignment
+   *  
+   * @param method - CalcId for the annotation (must match)
+   * @param autoCalc - value of autocalc flag for the annotation
+   * @param seqRef - null or specific sequence reference
+   * @param groupRef - null or specific group reference 
+   * @return existing annotation matching the given attributes 
+   */
+  public AlignmentAnnotation findOrCreateAnnotation(String name, boolean autoCalc,
+          SequenceI seqRef, SequenceGroup groupRef);
 }
index d7a0339..085fb70 100644 (file)
@@ -1,7 +1,5 @@
 package jalview.datamodel;
 
-import java.util.List;
-
 public interface AnnotatedCollectionI
 {
 
@@ -11,4 +9,6 @@ public interface AnnotatedCollectionI
    */
   AlignmentAnnotation[] getAlignmentAnnotation();
 
+  Iterable<AlignmentAnnotation> findAnnotation(String calcId);
+
 }
index e7c1a85..9a6d022 100755 (executable)
@@ -1216,4 +1216,17 @@ public class SequenceGroup implements AnnotatedCollectionI
     }
     return annot.toArray(new AlignmentAnnotation[0]);
   }
+  @Override
+  public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
+  {
+    ArrayList<AlignmentAnnotation> aa=new ArrayList<AlignmentAnnotation>();
+    for (AlignmentAnnotation a:getAlignmentAnnotation())
+    {
+      if (a.getCalcId()==calcId)
+      {
+        aa.add(a);
+      }
+    }
+    return aa;
+  }
 }
index 289d49b..7aaac5b 100644 (file)
@@ -72,7 +72,7 @@ public class AAConsClient extends JabawsAlignCalcWorker
           else
           {
             // simple annotation row
-            annotation = findOrCreate(scr.getMethod(), true, null, null);
+            annotation = alignViewport.getAlignment().findOrCreateAnnotation(scr.getMethod(), true, null, null);
             Annotation[] elm = new Annotation[alWidth];
             if (alWidth == scr.getScores().size())
             {
index a11cc35..029c842 100644 (file)
@@ -364,34 +364,6 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
     return seqs;
   }
 
-  protected AlignmentAnnotation findOrCreate(String name, boolean autoCalc,
-          SequenceI seqRef, SequenceGroup groupRef)
-  {
-    for (AlignmentAnnotation annot : alignViewport.getAlignment()
-            .getAlignmentAnnotation())
-    {
-      if (annot.autoCalculated == autoCalc
-              && annot.getCalcId().equals(name)
-              && annot.sequenceRef == seqRef && annot.groupRef == groupRef)
-      {
-        return annot;
-      }
-    }
-    AlignmentAnnotation annot = new AlignmentAnnotation(name, name,
-            new Annotation[1], 0f, 0f, AlignmentAnnotation.BAR_GRAPH);
-    annot.hasText = false;
-    annot.setCalcId(new String(name));
-    annot.autoCalculated = autoCalc;
-    if (seqRef != null)
-    {
-      annot.setSequenceRef(seqRef);
-    }
-    annot.groupRef = groupRef;
-    alignViewport.getAlignment().addAnnotation(annot);
-
-    return annot;
-  }
-
   /**
    * notify manager that we have started, and wait for a free calculation slot
    *