From e92b43b69e418df0a247a7148d6e4312f57b3787 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 18 Jul 2008 15:10:29 +0000 Subject: [PATCH] resolve 1:many mappings for sequence associated annotation to all alignment sequence(s) with same ID --- src/jalview/io/AnnotationFile.java | 41 +++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 016ee8f..13cfc38 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -323,6 +323,7 @@ public class AnnotationFile } SequenceI refSeq = null; + String refSeqId = null; public boolean readAnnotationFile(AlignmentI al, String file, String protocol) @@ -420,7 +421,13 @@ public class AnnotationFile else if (token.equalsIgnoreCase("SEQUENCE_REF")) { - refSeq = al.findName(st.nextToken()); + if (st.hasMoreTokens()) + { + refSeq = al.findName(refSeqId=st.nextToken()); + if (refSeq==null) + { + refSeqId=null; + } try { refSeqIndex = Integer.parseInt(st.nextToken()); @@ -435,7 +442,10 @@ public class AnnotationFile { refSeqIndex = 1; } - + } else { + refSeq = null; + refSeqId = null; + } continue ; } @@ -538,16 +548,27 @@ public class AnnotationFile if (refSeq != null) { annotation.belowAlignment=false; - annotation.createSequenceMapping(refSeq, refSeqIndex, false); - annotation.adjustForAlignment(); - refSeq.addAlignmentAnnotation(annotation); - } - - al.addAnnotation(annotation); - - al.setAnnotationIndex(annotation, + do { + // copy before we do any mapping business. + // TODO: verify that undo/redo with 1:many sequence associated annotations can be undone correctly + AlignmentAnnotation ann = new AlignmentAnnotation(annotation); + annotation.createSequenceMapping(refSeq, refSeqIndex, false); + annotation.adjustForAlignment(); + refSeq.addAlignmentAnnotation(annotation); + al.addAnnotation(annotation); + al.setAnnotationIndex(annotation, + al.getAlignmentAnnotation().length - existingAnnotations - + 1); + // and recover our virgin copy to use again if necessary. + annotation = ann; + + } while (refSeqId!=null && (refSeq=al.findName(refSeq, refSeqId, true))!=null); + } else { + al.addAnnotation(annotation); + al.setAnnotationIndex(annotation, al.getAlignmentAnnotation().length - existingAnnotations - 1); + } } } -- 1.7.10.2