From: Jim Procter Date: Thu, 1 May 2014 14:38:57 +0000 (+0100) Subject: JAL-1492 JAL-1397 make AnnotatedCollectionI context aware so groups can be coloured... X-Git-Tag: Jalview_2_9~190^2~8 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=fb27f86492eb06fc39b0578e1c31de8b4c26491a JAL-1492 JAL-1397 make AnnotatedCollectionI context aware so groups can be coloured based on annotation on their parent alignments. --- diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index ed65dd5..35efe4f 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -371,7 +371,7 @@ public class Alignment implements AlignmentI return; } } - + sg.setContext(this); groups.add(sg); } } @@ -446,6 +446,9 @@ public class Alignment implements AlignmentI { removeAnnotationForGroup(null); } + for (SequenceGroup sg:groups) { + sg.setContext(null); + } groups.clear(); } } @@ -460,6 +463,7 @@ public class Alignment implements AlignmentI { removeAnnotationForGroup(g); groups.remove(g); + g.setContext(null); } } } @@ -1498,4 +1502,14 @@ public int getStartRes() { return 0; } + +/* In the case of AlignmentI - returns the dataset for the alignment, if set + * (non-Javadoc) + * @see jalview.datamodel.AnnotatedCollectionI#getContext() + */ +@Override +public AnnotatedCollectionI getContext() +{ + return dataset; +} } diff --git a/src/jalview/datamodel/AnnotatedCollectionI.java b/src/jalview/datamodel/AnnotatedCollectionI.java index 510437a..0f856ee 100644 --- a/src/jalview/datamodel/AnnotatedCollectionI.java +++ b/src/jalview/datamodel/AnnotatedCollectionI.java @@ -31,4 +31,9 @@ public interface AnnotatedCollectionI extends SequenceCollectionI Iterable findAnnotation(String calcId); + /** + * context for this annotated collection + * @return null or the collection upon which this collection is defined (e.g. alignment, parent group). + */ + AnnotatedCollectionI getContext(); } diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 521bdbe..1df45a2 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -500,10 +500,6 @@ public class SequenceGroup implements AnnotatedCollectionI { return; } - if (cs != null) - { - cs.alignmentChanged(this, null); - } try { Hashtable cnsns[] = AAFrequency.calculate(sequences, startRes, @@ -515,7 +511,6 @@ public class SequenceGroup implements AnnotatedCollectionI if (cs != null) { cs.setConsensus(cnsns); - cs.alignmentChanged(this, null); } if ((conservation != null) @@ -535,10 +530,13 @@ public class SequenceGroup implements AnnotatedCollectionI if (cs.conservationApplied()) { cs.setConservation(c); - cs.alignmentChanged(this, null); } } } + if (cs != null) + { + cs.alignmentChanged(context!=null ? context : this, null); + } } catch (java.lang.OutOfMemoryError err) { // TODO: catch OOM @@ -1248,4 +1246,21 @@ public class SequenceGroup implements AnnotatedCollectionI { sequences.clear(); } + private AnnotatedCollectionI context; + /** + * set the alignment or group context for this group + * @param context + */ + public void setContext(AnnotatedCollectionI context) + { + this.context = context; + } + /* (non-Javadoc) + * @see jalview.datamodel.AnnotatedCollectionI#getContext() + */ + @Override + public AnnotatedCollectionI getContext() + { + return context; + } } diff --git a/src/jalview/schemes/AnnotationColourGradient.java b/src/jalview/schemes/AnnotationColourGradient.java index f619d07..3606db9 100755 --- a/src/jalview/schemes/AnnotationColourGradient.java +++ b/src/jalview/schemes/AnnotationColourGradient.java @@ -19,6 +19,7 @@ package jalview.schemes; import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.GraphLine; import jalview.datamodel.SequenceCollectionI; @@ -138,7 +139,9 @@ public class AnnotationColourGradient extends FollowerColourScheme { seqannot = new IdentityHashMap(); } - for (AlignmentAnnotation alan : alignment.findAnnotation(annotation + // resolve the context containing all the annotation for the sequence + AnnotatedCollectionI alcontext = alignment instanceof AlignmentI ? alignment : alignment.getContext(); + for (AlignmentAnnotation alan : alcontext.findAnnotation(annotation .getCalcId())) { if (alan.sequenceRef != null diff --git a/src/jalview/schemes/TCoffeeColourScheme.java b/src/jalview/schemes/TCoffeeColourScheme.java index 38d1200..1c8e469 100644 --- a/src/jalview/schemes/TCoffeeColourScheme.java +++ b/src/jalview/schemes/TCoffeeColourScheme.java @@ -85,8 +85,9 @@ public class TCoffeeColourScheme extends ResidueColourScheme // Search alignment to get all tcoffee annotation and pick one set of // annotation to use to colour seqs. seqMap = new IdentityHashMap(); + AnnotatedCollectionI alcontext = alignment instanceof AlignmentI ? alignment : alignment.getContext(); int w = 0; - for (AlignmentAnnotation al : alignment + for (AlignmentAnnotation al : alcontext .findAnnotation(TCoffeeScoreFile.TCOFFEE_SCORE)) { if (al.sequenceRef != null && !al.belowAlignment)