From: jprocter Date: Wed, 28 Apr 2010 10:15:51 +0000 (+0000) Subject: group/annotation association housekeeping X-Git-Tag: Release_2_5~43 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=520cc5fe77f3f625c9a58cb6b8b83bbca68084b6 group/annotation association housekeeping --- diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index afe7032..dc70c47 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -27,7 +27,7 @@ import jalview.analysis.*; */ /** * @author JimP - * + * */ public class Alignment implements AlignmentI { @@ -88,7 +88,7 @@ public class Alignment implements AlignmentI * Make a new alignment from an array of SeqCigars * * @param seqs - * SeqCigar[] + * SeqCigar[] */ public Alignment(SeqCigar[] alseqs) { @@ -104,7 +104,7 @@ public class Alignment implements AlignmentI * appropriately. * * @param compactAlignment - * CigarArray + * CigarArray */ public static AlignmentI createAlignment(CigarArray compactAlignment) { @@ -138,7 +138,7 @@ public class Alignment implements AlignmentI * DOCUMENT ME! * * @param i - * DOCUMENT ME! + * DOCUMENT ME! * * @return DOCUMENT ME! */ @@ -238,7 +238,7 @@ public class Alignment implements AlignmentI * DOCUMENT ME! * * @param s - * DOCUMENT ME! + * DOCUMENT ME! */ public void deleteSequence(SequenceI s) { @@ -249,7 +249,7 @@ public class Alignment implements AlignmentI * DOCUMENT ME! * * @param i - * DOCUMENT ME! + * DOCUMENT ME! */ public void deleteSequence(int i) { @@ -280,7 +280,7 @@ public class Alignment implements AlignmentI * DOCUMENT ME! * * @param s - * DOCUMENT ME! + * DOCUMENT ME! * * @return DOCUMENT ME! */ @@ -344,10 +344,69 @@ public class Alignment implements AlignmentI } /** - * DOCUMENT ME! + * remove any annotation that references gp + * @param gp (if null, removes all group associated annotation) */ + private void removeAnnotationForGroup(SequenceGroup gp) + { + if (annotations==null || annotations.length==0) + { + return; + } + // remove annotation very quickly + AlignmentAnnotation[] t, todelete = new AlignmentAnnotation[annotations.length], tokeep = new AlignmentAnnotation[annotations.length]; + int i, p, k; + if (gp == null) + { + for (i = 0, p = 0, k = 0; i < annotations.length; i++) + { + if (annotations[i].groupRef != null) + { + todelete[p++] = annotations[i]; + } + else + { + tokeep[k++] = annotations[i]; + } + } + } + else + { + for (i = 0, p = 0, k = 0; i < annotations.length; i++) + { + if (annotations[i].groupRef == gp) + { + todelete[p++] = annotations[i]; + } + else + { + tokeep[k++] = annotations[i]; + } + } + } + if (p > 0) + { + // clear out the group associated annotation. + for (i = 0; i < p; i++) + { + unhookAnnotation(todelete[i]); + todelete[i] = null; + } + t = new AlignmentAnnotation[k]; + for (i = 0; i < k; i++) + { + t[i] = tokeep[i]; + } + annotations = t; + } + } + public void deleteAllGroups() { + if (annotations != null) + { + removeAnnotationForGroup(null); + } groups.removeAllElements(); } @@ -356,14 +415,7 @@ public class Alignment implements AlignmentI { if (groups.contains(g)) { - if (annotations!=null && annotations.length>0) - { - if (g.hasAnnotationRows()) - { // remove any annotation references. - deleteAnnotation(g.getConsensus());// todo - create=false flag so we don't create another object unnecessarily - deleteAnnotation(g.getConservationRow()); - } - } + removeAnnotationForGroup(g); groups.removeElement(g); } } @@ -388,7 +440,7 @@ public class Alignment implements AlignmentI * (non-Javadoc) * * @see jalview.datamodel.AlignmentI#findName(SequenceI, java.lang.String, - * boolean) + * boolean) */ public SequenceI findName(SequenceI startAfter, String token, boolean b) { @@ -479,7 +531,8 @@ public class Alignment implements AlignmentI /* * (non-Javadoc) * - * @see jalview.datamodel.AlignmentI#findIndex(jalview.datamodel.SearchResults) + * @see + * jalview.datamodel.AlignmentI#findIndex(jalview.datamodel.SearchResults) */ public int findIndex(SearchResults results) { @@ -530,7 +583,7 @@ public class Alignment implements AlignmentI * DOCUMENT ME! * * @param gc - * DOCUMENT ME! + * DOCUMENT ME! */ public void setGapCharacter(char gc) { @@ -577,7 +630,8 @@ public class Alignment implements AlignmentI /* * (non-Javadoc) * - * @see jalview.datamodel.AlignmentI#deleteAnnotation(jalview.datamodel.AlignmentAnnotation) + * @seejalview.datamodel.AlignmentI#deleteAnnotation(jalview.datamodel. + * AlignmentAnnotation) */ public boolean deleteAnnotation(AlignmentAnnotation aa) { @@ -612,22 +666,45 @@ public class Alignment implements AlignmentI if (swap) { annotations = temp; - if (aa.sequenceRef != null) - aa.sequenceRef.removeAlignmentAnnotation(aa); + unhookAnnotation(aa); } return swap; } - /* (non-Javadoc) - * @see jalview.datamodel.AlignmentI#addAnnotation(jalview.datamodel.AlignmentAnnotation) + /** + * remove any object references associated with this annotation + * + * @param aa + */ + private void unhookAnnotation(AlignmentAnnotation aa) + { + if (aa.sequenceRef != null) + { + aa.sequenceRef.removeAlignmentAnnotation(aa); + } + if (aa.groupRef != null) + { + // probably need to do more here in the future (post 2.5.0) + aa.groupRef = null; + } + } + + /* + * (non-Javadoc) + * + * @seejalview.datamodel.AlignmentI#addAnnotation(jalview.datamodel. + * AlignmentAnnotation) */ public void addAnnotation(AlignmentAnnotation aa) { addAnnotation(aa, -1); } - - /* (non-Javadoc) - * @see jalview.datamodel.AlignmentI#addAnnotation(jalview.datamodel.AlignmentAnnotation, int) + + /* + * (non-Javadoc) + * + * @seejalview.datamodel.AlignmentI#addAnnotation(jalview.datamodel. + * AlignmentAnnotation, int) */ public void addAnnotation(AlignmentAnnotation aa, int pos) { @@ -639,21 +716,25 @@ public class Alignment implements AlignmentI AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize]; int i = 0; - if (pos==-1 || pos>=aSize) { + if (pos == -1 || pos >= aSize) + { temp[aSize - 1] = aa; - } else { + } + else + { temp[pos] = aa; } if (aSize > 1) { - int p=0; - for (i = 0; i < (aSize-1); i++,p++) + int p = 0; + for (i = 0; i < (aSize - 1); i++, p++) { - if (p==pos) + if (p == pos) { p++; } - if (pmaxLength) + ends[i * 2] = j; + hitres = true; + } + else + { + ends[i * 2 + 1] = j; + if (j - ends[i * 2] > maxLength) { - maxLength = j-ends[i*2]; + maxLength = j - ends[i * 2]; } } } @@ -860,50 +948,56 @@ public class Alignment implements AlignmentI maxLength++; // now edit the flanking gaps to justify to either left or right - int cLength,extent,diff; + int cLength, extent, diff; for (int i = 0; i < sequences.size(); i++) { current = getSequenceAt(i); - - cLength = 1+ends[i*2+1]-ends[i*2]; - diff = maxLength-cLength; // number of gaps to indent + + cLength = 1 + ends[i * 2 + 1] - ends[i * 2]; + diff = maxLength - cLength; // number of gaps to indent extent = current.getLength(); if (right) { // right justify - if (extent>ends[i*2+1]) + if (extent > ends[i * 2 + 1]) { - current.deleteChars(ends[i*2+1]+1, extent); + current.deleteChars(ends[i * 2 + 1] + 1, extent); modified = true; } - if (ends[i*2]>diff) + if (ends[i * 2] > diff) { - current.deleteChars(0, ends[i*2]-diff); + current.deleteChars(0, ends[i * 2] - diff); modified = true; - } else { - if (ends[i*2]0) + if (ends[i * 2] > 0) { - current.deleteChars(0, ends[i*2]); + current.deleteChars(0, ends[i * 2]); modified = true; - ends[i*2+1]-=ends[i*2]; - extent-=ends[i*2]; + ends[i * 2 + 1] -= ends[i * 2]; + extent -= ends[i * 2]; } - if (extent>maxLength) + if (extent > maxLength) { - current.deleteChars(maxLength+1, extent); + current.deleteChars(maxLength + 1, extent); modified = true; - } else { - if (extent