From: gmungoc Date: Thu, 18 Jun 2015 08:18:14 +0000 (+0100) Subject: JAL-1781 annotation.sequenceRef now sequence id not name, incrementing X-Git-Tag: Release_2_10_0~604 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Ffeatures%2FJAL-1781annotationXmlIds;p=jalview.git JAL-1781 annotation.sequenceRef now sequence id not name, incrementing annotation ids --- diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 4c5ea17..322fd54 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -20,10 +20,6 @@ */ package jalview.datamodel; -import jalview.analysis.Rna; -import jalview.analysis.SecStrConsensus.SimpleBP; -import jalview.analysis.WUSSParseException; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -32,6 +28,10 @@ import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; +import jalview.analysis.Rna; +import jalview.analysis.SecStrConsensus.SimpleBP; +import jalview.analysis.WUSSParseException; + /** * DOCUMENT ME! * @@ -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 @@ -282,6 +286,7 @@ public class AlignmentAnnotation public AlignmentAnnotation(String label, String description, Annotation[] annotations) { + setAnnotationId(); // always editable? editable = true; this.label = label; @@ -458,8 +463,6 @@ public class AlignmentAnnotation _updateRnaSecStr(new AnnotCharSequence()); } } - - annotationId = this.hashCode() + ""; } /** @@ -565,6 +568,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; @@ -664,6 +668,7 @@ public class AlignmentAnnotation */ public AlignmentAnnotation(AlignmentAnnotation annotation) { + setAnnotationId(); this.label = new String(annotation.label); if (annotation.description != null) { @@ -1382,4 +1387,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++; + } } diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index e443512..da9c6a9 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -1511,9 +1511,8 @@ public class Jalview2XML if (aa[i].sequenceRef != null) { - // TODO later annotation sequenceRef should be the XML ID of the - // sequence rather than its display name - an.setSequenceRef(aa[i].sequenceRef.getName()); + // 2.9 JAL-1781 xref on sequence id rather than name + an.setSequenceRef(seqsToIds.get(aa[i].sequenceRef)); } if (aa[i].groupRef != null) { @@ -2872,13 +2871,20 @@ public class Jalview2XML jaa.annotationId = an[i].getId(); } // recover sequence association - if (an[i].getSequenceRef() != null) + String sequenceRef = an[i].getSequenceRef(); + if (sequenceRef != null) { - if (al.findName(an[i].getSequenceRef()) != null) + // from 2.9 sequenceRef is to sequence id (JAL-1781) + SequenceI sequence = seqRefIds.get(sequenceRef); + if (sequence == null) { - jaa.createSequenceMapping(al.findName(an[i].getSequenceRef()), - 1, true); - al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(jaa); + // in pre-2.9 projects sequence ref is to sequence name + sequence = al.findName(sequenceRef); + } + if (sequence != null) + { + jaa.createSequenceMapping(sequence, 1, true); + sequence.addAlignmentAnnotation(jaa); } } // and make a note of any group association