X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=08754509f72d7a1da743bc20db4f398e6689d48d;hb=d4ede6b61d4abab78200f334d8df07879dfe6741;hp=69b66e01b8e56249d3f0553517a17a007b778dd7;hpb=1ecf6419aba86993b3c223bf5ec0fa79427baf85;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 69b66e0..0875450 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -1,7 +1,5 @@ package jalview.datamodel; -import jalview.jbgui.*; -import jalview.schemes.*; import jalview.analysis.*; import jalview.util.*; import java.util.*; @@ -13,8 +11,8 @@ public class Alignment implements AlignmentI protected Vector sequences; protected Vector groups = new Vector(); - public Hashtable[] cons; - protected String gapCharacter = "."; + protected ArrayList superGroup = new ArrayList(); + protected char gapCharacter = '-'; /** Make an alignment from an array of Sequences. * @@ -23,18 +21,8 @@ public class Alignment implements AlignmentI public Alignment(SequenceI[] seqs) { sequences = new Vector(); - for (int i=0; i < seqs.length; i++) { + for (int i=0; i < seqs.length; i++) sequences.addElement(seqs[i]); - } - - groups.addElement(new SequenceGroup()); - - int i = 0; - - while (i < seqs.length) { - addToGroup((SequenceGroup)groups.elementAt(0),seqs[i]); - i++; - } getWidth(); } @@ -125,7 +113,7 @@ public class Alignment implements AlignmentI if (current.getLength() > i) { /* MC Should move this to a method somewhere */ - if (current.getCharAt(i)!='-' && current.getCharAt(i)!='.' && current.getCharAt(i)!=' ') + if ( !jalview.util.Comparison.isGap(current.getCharAt(i))) delete = false; } @@ -230,35 +218,34 @@ public class Alignment implements AlignmentI 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++) { + 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))) { + if (!del.contains( (SequenceI) sel.elementAt(i)) || + !del.contains( (SequenceI) sel.elementAt(j))) + { - float pid = Comparison.compare((SequenceI)sel.elementAt(j), - (SequenceI)sel.elementAt(i)); + float pid = Comparison.compare( (SequenceI) sel.elementAt(j), + (SequenceI) sel.elementAt(i)); - if (pid >= threshold) { + if (pid >= threshold) + { // Delete the shortest one - if (((SequenceI)sel.elementAt(j)).getSequence().length() > - ((SequenceI)sel.elementAt(i)).getSequence().length()) { + if ( ( (SequenceI) sel.elementAt(j)).getSequence().length() > + ( (SequenceI) sel.elementAt(i)).getSequence().length()) del.addElement(sel.elementAt(i)); - System.out.println("Deleting sequence " + ((SequenceI)sel.elementAt(i)).getName()); - } else { + else del.addElement(sel.elementAt(i)); - System.out.println("Deleting sequence " + ((SequenceI)sel.elementAt(i)).getName()); - } } } } } // Now delete the sequences - for (int i=0; i < del.size(); i++) { - System.out.println("Deleting sequence " + ((SequenceI)del.elementAt(i)).getName()); + for (int i=0; i < del.size(); i++) deleteSequence((SequenceI)del.elementAt(i)); - } return del; } @@ -324,13 +311,33 @@ public class Alignment implements AlignmentI /** */ public SequenceGroup findGroup(SequenceI s) { - for (int i = 0; i < this.groups.size();i++) { + for (int i = 0; i < this.groups.size();i++) + { SequenceGroup sg = (SequenceGroup)groups.elementAt(i); - if (sg.sequences.contains(s)) { + if (sg.sequences.contains(s)) return sg; - } + } 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; } /** */ @@ -351,16 +358,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) { - groups.addElement(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++; + } + + } /** */ @@ -375,21 +411,36 @@ public class Alignment implements AlignmentI int i = 0; while (i < sequences.size()) { SequenceI s = getSequenceAt(i); - if (s.getName().equals(name)) { + if (s.getName().equals(name)) return s; - } + i++; } return null; } /** */ - public int findIndex(SequenceI s) { - int i=0; + public SequenceI findbyDisplayId(String name) { + int i = 0; while (i < sequences.size()) { - if (s == getSequenceAt(i)) { + SequenceI s = getSequenceAt(i); + if (s.getDisplayId().equals(name)) + return s; + + i++; + } + return null; + } + + /** */ + public int findIndex(SequenceI s) + { + int i=0; + while (i < sequences.size()) + { + if (s == getSequenceAt(i)) return i; - } + i++; } return -1; @@ -430,11 +481,18 @@ public class Alignment implements AlignmentI return max; } - public void setGapCharacter(String gc) { + 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); + } } - public String getGapCharacter() { + public char getGapCharacter() { return gapCharacter; }