X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=e513e594a62614f5e352dfd05bca2d3a64ac4a35;hb=e7ed63f1ea56432246a6ed1553f0fe56d26f56ea;hp=f480f0f82a3caf97b0bf1f7c7ca7802ec92d0386;hpb=8af8289df86798d5e283e1d0aa275b8f98e563dc;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index f480f0f..e513e59 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -11,7 +11,12 @@ public class Alignment implements AlignmentI protected Vector sequences; protected Vector groups = new Vector(); - protected char gapCharacter = '-'; + protected ArrayList superGroup = new ArrayList(); + protected char gapCharacter = '-'; + public AlignmentAnnotation [] annotations; + public Conservation conservation; + + public boolean featuresAdded = false; /** Make an alignment from an array of Sequences. * @@ -39,14 +44,11 @@ public class Alignment implements AlignmentI } /** Adds a sequence to the alignment. Recalculates maxLength and size. - * Should put the new sequence in a sequence group!!! * * @param snew */ public void addSequence(SequenceI snew) { sequences.addElement(snew); - - ((SequenceGroup)groups.lastElement()).addSequence(snew); } public void addSequence(SequenceI[] seq) { @@ -56,8 +58,7 @@ public class Alignment implements AlignmentI } /** Adds a sequence to the alignment. Recalculates maxLength and size. - * Should put the new sequence in a sequence group!!! - * + * * @param snew */ public void setSequenceAt(int i,SequenceI snew) { @@ -65,8 +66,6 @@ public class Alignment implements AlignmentI deleteSequence(oldseq); sequences.setElementAt(snew,i); - - ((SequenceGroup)groups.lastElement()).addSequence(snew); } public Vector getGroups() { @@ -318,6 +317,25 @@ public class Alignment implements AlignmentI } return null; + } + + public SequenceGroup [] findAllGroups(SequenceI s) + { + + ArrayList temp = new ArrayList(); + + for (int i = 0; i < this.groups.size();i++) + { + SequenceGroup sg = (SequenceGroup)groups.elementAt(i); + + if (sg.sequences.contains(s)) + temp.add(sg); + } + + SequenceGroup [] ret = new SequenceGroup[temp.size()]; + temp.toArray( ret ); + + return ret; } /** */ @@ -338,17 +356,45 @@ public class Alignment implements AlignmentI } } + public void addSuperGroup(SuperGroup sg) + { + superGroup.add(sg); + } + + public void removeSuperGroup(SuperGroup sg) + { + superGroup.remove(sg); + } + + public SuperGroup getSuperGroup(SequenceGroup sg) + { + for (int i = 0; i < this.superGroup.size(); i++) + { + SuperGroup temp = (SuperGroup) superGroup.get(i); + if (temp.sequenceGroups.contains(sg)) + return temp; + } + return null; + } + /** */ public void addGroup(SequenceGroup sg) { if(!groups.contains(sg)) groups.addElement(sg); } - /** */ - public SequenceGroup addGroup() { - SequenceGroup sg = new SequenceGroup(); - groups.addElement(sg); - return sg; + public void deleteAllGroups() + { + groups.clear(); + superGroup.clear(); + int i=0; + while (i < sequences.size()) { + SequenceI s = getSequenceAt(i); + s.setColor(java.awt.Color.white); + i++; + } + + } /** */ @@ -435,12 +481,12 @@ public class Alignment implements AlignmentI public void setGapCharacter(char gc) { - char old = getGapCharacter(); gapCharacter = gc; for (int i=0; i < sequences.size(); i++) { Sequence seq = (Sequence)sequences.elementAt(i); - seq.sequence = seq.sequence.replace(old, gc); + seq.sequence = seq.sequence.replace('.', gc); + seq.sequence = seq.sequence.replace('-', gc); } } @@ -452,6 +498,61 @@ public class Alignment implements AlignmentI { return AAFrequency.calculate(sequences, 0, getWidth()); } + + public boolean isAligned() + { + int width = getWidth(); + for (int i = 0; i < sequences.size(); i++) + if (getSequenceAt(i).getLength() != width) + return false; + + return true; + } + + public void deleteAnnotation(AlignmentAnnotation aa) + { + int aSize = 1; + if(annotations!=null) + aSize = annotations.length; + + AlignmentAnnotation [] temp = new AlignmentAnnotation [aSize-1]; + + int tIndex = 0; + for (int i = 0; i < aSize; i++) + { + if(annotations[i]==aa) + continue; + + + temp[tIndex] = annotations[i]; + tIndex++; + } + + annotations = temp; + + } + + public void addAnnotation(AlignmentAnnotation aa) + { + int aSize = 1; + if(annotations!=null) + aSize = annotations.length+1; + + AlignmentAnnotation [] temp = new AlignmentAnnotation [aSize]; + int i=0; + if (aSize > 1) + for (i = 0; i < aSize-1; i++) + temp[i] = annotations[i]; + + temp[i] = aa; + + annotations = temp; + } + public AlignmentAnnotation[] getAlignmentAnnotation() + { + return annotations; + } + }