X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignmentAnnotation.java;h=7990a5cfb6afb30796bdb60f1e1ca6945d1f0611;hb=refs%2Fheads%2Ffeatures%2FJAL-2055alternateFeatureColours;hp=52779f71c52e3c5dd6c50b72ef43ab1899e7f462;hpb=d1f61dfcb459e538da2d2265f2dff9abf3ccf400;p=jalview.git diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 52779f7..7990a5c 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -40,6 +40,8 @@ import java.util.Map.Entry; */ public class AlignmentAnnotation { + private static final String ANNOTATION_ID_PREFIX = "ann"; + /* * Identifers for different types of profile data */ @@ -49,6 +51,8 @@ public class AlignmentAnnotation public static final int CDNA_PROFILE = 2; + private static long counter = 0; + /** * If true, this annotations is calculated every edit, eg consensus, quality * or conservation graphs @@ -160,6 +164,7 @@ public class AlignmentAnnotation } setScore(mxval); } + /** * map of positions in the associated annotation */ @@ -240,6 +245,7 @@ public class AlignmentAnnotation * * @see java.lang.Object#finalize() */ + @Override protected void finalize() throws Throwable { sequenceRef = null; @@ -282,6 +288,7 @@ public class AlignmentAnnotation public AlignmentAnnotation(String label, String description, Annotation[] annotations) { + setAnnotationId(); // always editable? editable = true; this.label = label; @@ -458,8 +465,6 @@ public class AlignmentAnnotation _updateRnaSecStr(new AnnotCharSequence()); } } - - annotationId = this.hashCode() + ""; } /** @@ -565,6 +570,7 @@ public class AlignmentAnnotation public AlignmentAnnotation(String label, String description, Annotation[] annotations, float min, float max, int graphType) { + setAnnotationId(); // graphs are not editable editable = graphType == 0; @@ -650,7 +656,7 @@ public class AlignmentAnnotation { if (annotations[i] != null) { - annotations[i].displayCharacter = "X"; + annotations[i].displayCharacter = ""; } } } @@ -664,6 +670,7 @@ public class AlignmentAnnotation */ public AlignmentAnnotation(AlignmentAnnotation annotation) { + setAnnotationId(); this.label = new String(annotation.label); if (annotation.description != null) { @@ -687,10 +694,10 @@ public class AlignmentAnnotation this.scaleColLabel = annotation.scaleColLabel; this.showAllColLabels = annotation.showAllColLabels; this.calcId = annotation.calcId; - if (annotation.properties!=null) + if (annotation.properties != null) { - properties = new HashMap(); - for (Map.Entry val:annotation.properties.entrySet()) + properties = new HashMap(); + for (Map.Entry val : annotation.properties.entrySet()) { properties.put(val.getKey(), val.getValue()); } @@ -951,6 +958,12 @@ public class AlignmentAnnotation } + /** + * When positional annotation and a sequence reference is present, clears and + * resizes the annotations array to the current alignment width, and adds + * annotation according to aligned positions of the sequenceRef given by + * sequenceMapping. + */ public void adjustForAlignment() { if (sequenceRef == null) @@ -974,18 +987,20 @@ public class AlignmentAnnotation int position; Annotation[] temp = new Annotation[aSize]; Integer index; - - for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++) + if (sequenceMapping != null) { - index = new Integer(a); - if (sequenceMapping.containsKey(index)) + for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++) { - position = sequenceRef.findIndex(a) - 1; + index = new Integer(a); + Annotation annot = sequenceMapping.get(index); + if (annot != null) + { + position = sequenceRef.findIndex(a) - 1; - temp[position] = sequenceMapping.get(index); + temp[position] = annot; + } } } - annotations = temp; } @@ -1022,11 +1037,11 @@ public class AlignmentAnnotation } /** - * Associate this annotion with the aligned residues of a particular sequence. - * sequenceMapping will be updated in the following way: null sequenceI - - * existing mapping will be discarded but annotations left in mapped - * positions. valid sequenceI not equal to current sequenceRef: mapping is - * discarded and rebuilt assuming 1:1 correspondence TODO: overload with + * Associate this annotation with the aligned residues of a particular + * sequence. sequenceMapping will be updated in the following way: null + * sequenceI - existing mapping will be discarded but annotations left in + * mapped positions. valid sequenceI not equal to current sequenceRef: mapping + * is discarded and rebuilt assuming 1:1 correspondence TODO: overload with * parameter to specify correspondence between current and new sequenceRef * * @param sequenceI @@ -1037,7 +1052,8 @@ public class AlignmentAnnotation { if (sequenceRef != null) { - boolean rIsDs=sequenceRef.getDatasetSequence()==null,tIsDs=sequenceI.getDatasetSequence()==null; + boolean rIsDs = sequenceRef.getDatasetSequence() == null, tIsDs = sequenceI + .getDatasetSequence() == null; if (sequenceRef != sequenceI && (rIsDs && !tIsDs && sequenceRef != sequenceI .getDatasetSequence()) @@ -1233,8 +1249,10 @@ public class AlignmentAnnotation { if (sp2sq.getMappedWidth() != sp2sq.getWidth()) { - // TODO: employ getWord/MappedWord to transfer annotation between cDNA and Protein reference frames - throw new Error("liftOver currently not implemented for transfer of annotation between different types of seqeunce"); + // TODO: employ getWord/MappedWord to transfer annotation between cDNA and + // Protein reference frames + throw new Error( + "liftOver currently not implemented for transfer of annotation between different types of seqeunce"); } boolean mapIsTo = (sp2sq != null) ? (sp2sq.getTo() == sq || sp2sq .getTo() == sq.getDatasetSequence()) : false; @@ -1287,7 +1305,8 @@ public class AlignmentAnnotation * @note caller should add the remapped annotation to newref if they have not * already */ - public void remap(SequenceI newref, int[][] mapping, int from, int to, + public void remap(SequenceI newref, HashMap mapping, + int from, int to, int idxoffset) { if (mapping != null) @@ -1295,7 +1314,7 @@ public class AlignmentAnnotation Map old = sequenceMapping; Map remap = new HashMap(); int index = -1; - for (int mp[] : mapping) + for (int mp[] : mapping.values()) { if (index++ < 0) { @@ -1349,9 +1368,9 @@ public class AlignmentAnnotation public void setProperty(String property, String value) { - if (properties==null) + if (properties == null) { - properties = new HashMap(); + properties = new HashMap(); } properties.put(property, value); } @@ -1382,4 +1401,18 @@ public class AlignmentAnnotation return sequenceMapping == null ? null : sequenceMapping.get(position); } + + /** + * Set the id to "ann" followed by a counter that increments so as to be + * unique for the lifetime of the JVM + */ + protected final void setAnnotationId() + { + this.annotationId = ANNOTATION_ID_PREFIX + Long.toString(nextId()); + } + + protected static synchronized long nextId() + { + return counter++; + } }