X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=5f0bf6884fc9fabbb7acdec470c31a9e0c50bf10;hb=23d3cb8d0e4c227224587135f41132d436dc1178;hp=78aa0157bce1cd05116da3335415de48165853a7;hpb=e0a4b92352ee3e31a8dea075a51ec080ae3945f2;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 78aa015..5f0bf68 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -24,7 +24,6 @@ import jalview.util.*; import java.util.*; - /** Data structure to hold and manipulate a multiple sequence alignment */ public class Alignment implements AlignmentI @@ -32,7 +31,6 @@ public class Alignment implements AlignmentI protected Alignment dataset; protected Vector sequences; protected Vector groups = new Vector(); - protected Vector superGroup = new Vector(); protected char gapCharacter = '-'; protected int type = NUCLEOTIDE; public static final int PROTEIN = 0; @@ -41,6 +39,9 @@ public class Alignment implements AlignmentI /** DOCUMENT ME!! */ public AlignmentAnnotation[] annotations; + HiddenSequences hiddenSequences = new HiddenSequences(this); + + /** Make an alignment from an array of Sequences. * * @param sequences @@ -59,19 +60,7 @@ public class Alignment implements AlignmentI for (i = 0; i < seqs.length; i++) { sequences.addElement(seqs[i]); - - if(seqs[i].getDatasetSequence()!=null - && seqs[i].getDatasetSequence().getAnnotation()!=null) - { - - for(int a=0; a= threshold) - { - // Delete the shortest one - if (((SequenceI) sel.elementAt(j)).getSequence().length() > ((SequenceI) sel - .elementAt( - i)).getSequence().length()) - { - del.addElement(sel.elementAt(i)); - } - else - { - del.addElement(sel.elementAt(i)); - } - } - } - } - } - - // Now delete the sequences - for (int i = 0; i < del.size(); i++) - { - deleteSequence((SequenceI) del.elementAt(i)); - } - - return del; - } - - /** */ - public SequenceGroup findGroup(int i) - { - return findGroup(getSequenceAt(i)); - } /** */ public SequenceGroup findGroup(SequenceI s) @@ -343,7 +285,7 @@ public class Alignment implements AlignmentI { SequenceGroup sg = (SequenceGroup) groups.elementAt(i); - if (sg.sequences.contains(s)) + if (sg.getSequences(false).contains(s)) { return sg; } @@ -367,14 +309,14 @@ public class Alignment implements AlignmentI for (int i = 0; i < gSize; i++) { SequenceGroup sg = (SequenceGroup) groups.elementAt(i); - if(sg==null || sg.sequences==null) + if(sg==null || sg.getSequences(false)==null) { this.deleteGroup(sg); gSize--; continue; } - if (sg.sequences.contains(s)) + if (sg.getSequences(false).contains(s)) { temp.addElement(sg); } @@ -390,47 +332,7 @@ public class Alignment implements AlignmentI return ret; } - /** - * DOCUMENT ME! - * - * @param sg DOCUMENT ME! - */ - public void addSuperGroup(SuperGroup sg) - { - superGroup.addElement(sg); - } - - /** - * DOCUMENT ME! - * - * @param sg DOCUMENT ME! - */ - public void removeSuperGroup(SuperGroup sg) - { - superGroup.removeElement(sg); - } - - /** - * DOCUMENT ME! - * - * @param sg DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public SuperGroup getSuperGroup(SequenceGroup sg) - { - for (int i = 0; i < this.superGroup.size(); i++) - { - SuperGroup temp = (SuperGroup) superGroup.elementAt(i); - if (temp.sequenceGroups.contains(sg)) - { - return temp; - } - } - - return null; - } /** */ public void addGroup(SequenceGroup sg) @@ -447,7 +349,6 @@ public class Alignment implements AlignmentI public void deleteAllGroups() { groups.removeAllElements(); - superGroup.removeAllElements(); int i = 0; @@ -574,9 +475,9 @@ public class Alignment implements AlignmentI for (int i = 0; i < sequences.size(); i++) { Sequence seq = (Sequence) sequences.elementAt(i); - seq.sequence = seq.sequence.replace('.', gc); - seq.sequence = seq.sequence.replace('-', gc); - seq.sequence = seq.sequence.replace(' ', gc); + seq.setSequence( seq.getSequence().replace('.', gc) ); + seq.setSequence( seq.getSequence().replace('-', gc) ); + seq.setSequence( seq.getSequence().replace(' ', gc) ); } } @@ -652,70 +553,6 @@ public class Alignment implements AlignmentI annotations = temp; } - /** - * - * @param aa AlignmentAnnotation - * @param seqRef The sequence to associate this annotation with - * @return The adjusted AlignmentAnnotation, with dataset sequence and annotation added - */ - public AlignmentAnnotation addAnnotation(AlignmentAnnotation aa, SequenceI seqRef) - { - if(seqRef!=null) - { - //We can only add Annotations to the dataset sequences - if(seqRef.getDatasetSequence()==null) - { - setDataset(null); - } - - AlignmentAnnotation [] old = seqRef.getDatasetSequence().getAnnotation(); - - //First check if this is a new annotation or not. If it is new, - //we must add the annotation to the dataset - boolean newAnnotation = true; - if(seqRef.getDatasetSequence().getAnnotation()!=null) - { - for(int a=0; a 0) - copy = new AlignmentAnnotation( - aa.label, aa.description, aa.annotations, aa.graphMin, - aa.graphMax, aa.graph - ); - else - copy = new AlignmentAnnotation( - aa.label, aa.description, aa.annotations - ); - - copy.datasetAnnotation = aa; - - addAnnotation(copy); - - copy.sequenceRef = seqRef; - - return copy; - } - else - { - addAnnotation(aa); - return aa; - } - } public void adjustSequenceAnnotations() { @@ -848,19 +685,48 @@ public class Alignment implements AlignmentI public boolean padGaps() { boolean modified=false; - int Width = getWidth(); + + //Remove excess gaps from the end of alignment + int maxLength = -1; + SequenceI current; + for (int i = 0; i < sequences.size(); i++) + { + current = getSequenceAt(i); + for (int j = current.getLength(); j > maxLength; j--) + { + if (j > maxLength && !jalview.util.Comparison.isGap( + current.getCharAt(j))) + { + maxLength = j; + break; + } + } + } + + maxLength++; + for (int i = 0; i < sequences.size(); i++) { current = getSequenceAt(i); - if (current.getLength() < Width) + if (current.getLength() < maxLength) { - current.insertCharAt(Width - 1, gapCharacter); + current.insertCharAt(maxLength - 1, gapCharacter); modified=true; } + else if(current.getLength() > maxLength) + { + current.deleteChars(maxLength, current.getLength()); + } } return modified; } + + public HiddenSequences getHiddenSequences() + { + return hiddenSequences; + } + }