X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=04977e852fcd85d83afaee169af0423b76b7468f;hb=797df64fa2a0a30773d0f48f5494d4155e5a8be3;hp=08c04f5b779f3b73c27cdba8baf081912a48d199;hpb=961b10e4c895aadb7fc9df82a641c6c53c0d5c70;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 08c04f5..04977e8 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -1,20 +1,19 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) - * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * This file is part of Jalview. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . */ package jalview.datamodel; @@ -25,6 +24,10 @@ import jalview.analysis.*; /** * Data structure to hold and manipulate a multiple sequence alignment */ +/** + * @author JimP + * + */ public class Alignment implements AlignmentI { protected Alignment dataset; @@ -40,6 +43,8 @@ public class Alignment implements AlignmentI public static final int PROTEIN = 0; public static final int NUCLEOTIDE = 1; + + public boolean hasRNAStructure = false; /** DOCUMENT ME!! */ public AlignmentAnnotation[] annotations; @@ -84,7 +89,7 @@ public class Alignment implements AlignmentI * Make a new alignment from an array of SeqCigars * * @param seqs - * SeqCigar[] + * SeqCigar[] */ public Alignment(SeqCigar[] alseqs) { @@ -100,7 +105,7 @@ public class Alignment implements AlignmentI * appropriately. * * @param compactAlignment - * CigarArray + * CigarArray */ public static AlignmentI createAlignment(CigarArray compactAlignment) { @@ -134,13 +139,13 @@ public class Alignment implements AlignmentI * DOCUMENT ME! * * @param i - * DOCUMENT ME! + * DOCUMENT ME! * * @return DOCUMENT ME! */ public SequenceI getSequenceAt(int i) { - if (i < sequences.size()) + if (i>-1 && i < sequences.size()) { return (SequenceI) sequences.elementAt(i); } @@ -234,7 +239,7 @@ public class Alignment implements AlignmentI * DOCUMENT ME! * * @param s - * DOCUMENT ME! + * DOCUMENT ME! */ public void deleteSequence(SequenceI s) { @@ -245,7 +250,7 @@ public class Alignment implements AlignmentI * DOCUMENT ME! * * @param i - * DOCUMENT ME! + * DOCUMENT ME! */ public void deleteSequence(int i) { @@ -276,7 +281,7 @@ public class Alignment implements AlignmentI * DOCUMENT ME! * * @param s - * DOCUMENT ME! + * DOCUMENT ME! * * @return DOCUMENT ME! */ @@ -340,10 +345,71 @@ 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(); } @@ -352,6 +418,7 @@ public class Alignment implements AlignmentI { if (groups.contains(g)) { + removeAnnotationForGroup(g); groups.removeElement(g); } } @@ -376,7 +443,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) { @@ -441,7 +508,10 @@ public class Alignment implements AlignmentI return result; } - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see jalview.datamodel.AlignmentI#findIndex(jalview.datamodel.SequenceI) */ public int findIndex(SequenceI s) @@ -460,14 +530,18 @@ public class Alignment implements AlignmentI return -1; } - /* (non-Javadoc) - * @see jalview.datamodel.AlignmentI#findIndex(jalview.datamodel.SearchResults) + + /* + * (non-Javadoc) + * + * @see + * jalview.datamodel.AlignmentI#findIndex(jalview.datamodel.SearchResults) */ public int findIndex(SearchResults results) { - int i=0; - - while (i