X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=b0b04cae8739551cd24ee5b045d62d5391d81b01;hb=cb8ec179c020265666678572815ab056a024da22;hp=ac8f47a4f68e76ff1d75f43080272b03c00386ea;hpb=bb99b11825ccc8f9d7dd7b4b0dfcc2f64ebe0b75;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index ac8f47a..b0b04ca 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -24,23 +24,24 @@ 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 boolean isNucleotide = true; - + 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. * @@ -48,27 +49,28 @@ public class Alignment implements AlignmentI */ public Alignment(SequenceI[] seqs) { - int i=0, iSize = seqs.length, j, jSize; - while(isNucleotide && is.getLength()) + { + sequences.removeElement(s); + j--; + jSize--; + } + else + { + s.setStart(newstart); + s.setSequence(s.getSequence().substring(i)); + } } } @@ -238,7 +250,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)); } } @@ -379,47 +392,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) @@ -464,11 +437,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++; @@ -477,25 +448,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) @@ -663,6 +615,85 @@ public class Alignment implements AlignmentI } /** + * + * @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() + { + if(annotations!=null) + { + for (int a = 0; a < annotations.length; a++) + { + if (annotations[a].sequenceRef != null) + { + annotations[a].adjustForAlignment(); + } + } + } + } + + /** * DOCUMENT ME! * * @param aa DOCUMENT ME! @@ -670,24 +701,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; + } + }