X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=5f0bf6884fc9fabbb7acdec470c31a9e0c50bf10;hb=23d3cb8d0e4c227224587135f41132d436dc1178;hp=61735eeb1d763b0b8c78d8a32efe9b6f8deebca9;hpb=8c6e707d6d9b1b8ad6385eb7eeef0bc78cb46f6e;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 61735ee..5f0bf68 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -24,21 +24,23 @@ import jalview.util.*; import java.util.*; - /** Data structure to hold and manipulate a multiple sequence alignment */ 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; + public static final int NUCLEOTIDE = 1; /** DOCUMENT ME!! */ public AlignmentAnnotation[] annotations; - /** DOCUMENT ME!! */ - public boolean featuresAdded = false; + HiddenSequences hiddenSequences = new HiddenSequences(this); + /** Make an alignment from an array of Sequences. * @@ -46,14 +48,19 @@ public class Alignment implements AlignmentI */ public Alignment(SequenceI[] seqs) { + int i=0; + + if( jalview.util.Comparison.isNucleotide(seqs)) + type = NUCLEOTIDE; + else + type = PROTEIN; + sequences = new Vector(); - for (int i = 0; i < seqs.length; i++) + for (i = 0; i < seqs.length; i++) { sequences.addElement(seqs[i]); } - - getWidth(); } /** @@ -66,6 +73,16 @@ public class Alignment implements AlignmentI return sequences; } + public SequenceI [] getSequencesArray() + { + SequenceI [] reply = new SequenceI[sequences.size()]; + for(int i=0; is.getLength()) + { + sequences.removeElement(s); + j--; + jSize--; + } + else + { + s.setStart(newstart); + s.setSequence(s.getSequence().substring(i)); + } } } @@ -220,7 +246,8 @@ public class Alignment implements AlignmentI int newend = s.findPosition(i); s.setEnd(newend); - s.setSequence(s.getSequence().substring(0, i + 1)); + if(s.getLength()>i) + s.setSequence(s.getSequence().substring(0, i + 1)); } } @@ -250,62 +277,6 @@ public class Alignment implements AlignmentI sequences.removeElementAt(i); } - /** - * DOCUMENT ME! - * - * @param threshold DOCUMENT ME! - * @param sel DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Vector removeRedundancy(float threshold, Vector sel) - { - Vector del = new Vector(); - - for (int i = 1; i < sel.size(); i++) - { - for (int j = 0; j < i; j++) - { - // Only do the comparison if either have not been deleted - if (!del.contains((SequenceI) sel.elementAt(i)) || - !del.contains((SequenceI) sel.elementAt(j))) - { - // use PID instead of Comparison (which is really not pleasant) - float pid = Comparison.PID((SequenceI) sel.elementAt(j), - (SequenceI) sel.elementAt(i)); - - if (pid >= 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) @@ -314,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; } @@ -338,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); } @@ -361,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) @@ -418,7 +349,6 @@ public class Alignment implements AlignmentI public void deleteAllGroups() { groups.removeAllElements(); - superGroup.removeAllElements(); int i = 0; @@ -446,11 +376,9 @@ public class Alignment implements AlignmentI while (i < sequences.size()) { - SequenceI s = getSequenceAt(i); - - if (s.getName().equals(name)) + if (getSequenceAt(i).getName().equals(name)) { - return s; + return getSequenceAt(i); } i++; @@ -459,25 +387,6 @@ public class Alignment implements AlignmentI return null; } - /** */ - public SequenceI findbyDisplayId(String name) - { - int i = 0; - - while (i < sequences.size()) - { - SequenceI s = getSequenceAt(i); - - if (s.getDisplayId().equals(name)) - { - return s; - } - - i++; - } - - return null; - } /** */ public int findIndex(SequenceI s) @@ -566,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) ); } } @@ -644,6 +553,21 @@ public class Alignment implements AlignmentI annotations = temp; } + + public void adjustSequenceAnnotations() + { + if(annotations!=null) + { + for (int a = 0; a < annotations.length; a++) + { + if (annotations[a].sequenceRef != null) + { + annotations[a].adjustForAlignment(); + } + } + } + } + /** * DOCUMENT ME! * @@ -652,24 +576,48 @@ public class Alignment implements AlignmentI public void addAnnotation(AlignmentAnnotation aa) { int aSize = 1; - if (annotations != null) { aSize = annotations.length + 1; } AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize]; + + temp[aSize-1] = aa; + int i = 0; if (aSize > 1) { - for (i = 0; i < (aSize - 1); i++) + for (i = 0; i < (aSize-1); i++) { temp[i] = annotations[i]; } } - temp[i] = aa; + annotations = temp; + } + + public void setAnnotationIndex(AlignmentAnnotation aa, int index) + { + if(aa==null || annotations==null || annotations.length-1 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() < maxLength) + { + current.insertCharAt(maxLength - 1, gapCharacter); + modified=true; + } + else if(current.getLength() > maxLength) + { + current.deleteChars(maxLength, current.getLength()); + } + } + return modified; + } + + public HiddenSequences getHiddenSequences() + { + return hiddenSequences; + } + }