From: jprocter Date: Wed, 23 May 2012 18:36:20 +0000 (+0100) Subject: JAL-961 - annotatable datamodel objects can be queried to obtain annotation with... X-Git-Tag: Jalview_2_9~516 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ef23315db576f5451de0fcb850f645c5db222b20;p=jalview.git JAL-961 - annotatable datamodel objects can be queried to obtain annotation with a particular calculation ID --- diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 708e566..c32a40f 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -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 findAnnotation(String calcId) + { + ArrayList aa=new ArrayList(); + for (AlignmentAnnotation a:getAlignmentAnnotation()) + { + if (a.getCalcId()==calcId || (a.getCalcId()!=null && calcId!=null && a.getCalcId().equals(calcId))) + { + aa.add(a); + } + } + return aa; + } + } diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index a79106a..ec35124 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -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); } diff --git a/src/jalview/datamodel/AnnotatedCollectionI.java b/src/jalview/datamodel/AnnotatedCollectionI.java index d7a0339..085fb70 100644 --- a/src/jalview/datamodel/AnnotatedCollectionI.java +++ b/src/jalview/datamodel/AnnotatedCollectionI.java @@ -1,7 +1,5 @@ package jalview.datamodel; -import java.util.List; - public interface AnnotatedCollectionI { @@ -11,4 +9,6 @@ public interface AnnotatedCollectionI */ AlignmentAnnotation[] getAlignmentAnnotation(); + Iterable findAnnotation(String calcId); + } diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index e7c1a85..9a6d022 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -1216,4 +1216,17 @@ public class SequenceGroup implements AnnotatedCollectionI } return annot.toArray(new AlignmentAnnotation[0]); } + @Override + public Iterable findAnnotation(String calcId) + { + ArrayList aa=new ArrayList(); + for (AlignmentAnnotation a:getAlignmentAnnotation()) + { + if (a.getCalcId()==calcId) + { + aa.add(a); + } + } + return aa; + } } diff --git a/src/jalview/ws/jws2/AAConsClient.java b/src/jalview/ws/jws2/AAConsClient.java index 289d49b..7aaac5b 100644 --- a/src/jalview/ws/jws2/AAConsClient.java +++ b/src/jalview/ws/jws2/AAConsClient.java @@ -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()) { diff --git a/src/jalview/ws/jws2/JabawsAlignCalcWorker.java b/src/jalview/ws/jws2/JabawsAlignCalcWorker.java index a11cc35..029c842 100644 --- a/src/jalview/ws/jws2/JabawsAlignCalcWorker.java +++ b/src/jalview/ws/jws2/JabawsAlignCalcWorker.java @@ -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 *