X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=f3d17b4dcbcafc627801c13d78eb908acec69b11;hb=cd71fb9ef1a21678ad648ba13564b658b53ab834;hp=338294b77bfab6ec444146bed2d39f3242c6e1a3;hpb=55e2e9b22b133db8b9ff0979b0338a33081fc8fd;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 338294b..f3d17b4 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 @@ -60,8 +61,6 @@ public class Alignment implements AlignmentI { sequences.addElement(seqs[i]); } - - getWidth(); } /** @@ -97,22 +96,21 @@ public class Alignment implements AlignmentI */ public void addSequence(SequenceI snew) { - sequences.addElement(snew); - } + if(dataset!=null) + { + Sequence ds = new Sequence(snew.getName(), + AlignSeq.extractGaps("-. ", snew.getSequence()), + snew.getStart(), + snew.getEnd()); - /** - * DOCUMENT ME! - * - * @param seq DOCUMENT ME! - */ - public void addSequence(SequenceI[] seq) - { - for (int i = 0; i < seq.length; i++) - { - addSequence(seq[i]); - } + snew.setDatasetSequence(ds); + getDataset().addSequence(ds); + } + + sequences.addElement(snew); } + /** Adds a sequence to the alignment. Recalculates maxLength and size. * * @param snew @@ -205,13 +203,23 @@ public class Alignment implements AlignmentI */ public void trimLeft(int i) { - for (int j = 0; j < getHeight(); j++) + int j, jSize = getHeight(); + for (j = 0; j < jSize; j++) { SequenceI s = getSequenceAt(j); int newstart = s.findPosition(i); - s.setStart(newstart); - s.setSequence(s.getSequence().substring(i)); + if(i>s.getLength()) + { + sequences.removeElement(s); + j--; + jSize--; + } + else + { + s.setStart(newstart); + s.setSequence(s.getSequence().substring(i)); + } } } @@ -228,7 +236,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)); } } @@ -369,47 +378,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) @@ -426,7 +395,6 @@ public class Alignment implements AlignmentI public void deleteAllGroups() { groups.removeAllElements(); - superGroup.removeAllElements(); int i = 0; @@ -631,6 +599,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! * @@ -639,25 +622,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; + } + }