JAL-961 - annotatable datamodel objects can be queried to obtain annotation with...
[jalview.git] / src / jalview / datamodel / Alignment.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;
+  }
+
 }