X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=c0c4ae0eb5c22f1f5dd42c7398ad37a84a9a3000;hb=6a52231af31721231478e6ff3a553bbe23ee863f;hp=c62d707d314303d8ac1c577f202e326c1fcc10fe;hpb=601989c95175f5ad883e73c4aa07a76713510d1f;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index c62d707..c0c4ae0 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -73,6 +73,16 @@ public class Alignment implements AlignmentI return sequences; } + public SequenceI [] getSequencesArray() + { + SequenceI [] reply = new SequenceI[sequences.size()]; + for(int i=0; i width) + { + width = seqs[i].getLength(); + } + } - for (int i = 0; i < iSize; i++) + int startCol = -1, endCol = -1; + boolean delete = true; + for (int i = 0; i < width; i++) { - boolean delete = true; + delete = true; - for (int j = 0; j < getHeight(); j++) + for (j = 0; j < jSize; j++) { current = getSequenceAt(j); if (current.getLength() > i) { - /* MC Should move this to a method somewhere */ if (!jalview.util.Comparison.isGap(current.getCharAt(i))) { + if(delete) + endCol = i; + delete = false; + break; } } + } - if (delete) + if(delete && startCol==-1) { - deleteColumns(i, i); - iSize--; - i--; + startCol = i; + } + + + if (!delete && startCol > -1) + { + deleteColumns(seqs, startCol, endCol); + width -= (endCol - startCol); + i -= (endCol - startCol); + startCol = -1; + endCol = -1; } } + + if (delete && startCol > -1) + { + deleteColumns(seqs, startCol, endCol); + } + } /** Removes a range of columns (start to end inclusive). * + * @param seqs Sequences to remove columns from * @param start Start column in the alignment * @param end End column in the alignment */ - public void deleteColumns(int start, int end) + public void deleteColumns(SequenceI [] seqs, int start, int end) { - deleteColumns(0, getHeight() - 1, start, end); + for(int i=0; is.getLength()) + if(i>seqs[j].getLength()) { - sequences.removeElement(s); + sequences.removeElement(seqs[j]); j--; jSize--; } else { - s.setStart(newstart); - s.setSequence(s.getSequence().substring(i)); + seqs[j].setStart(newstart); + seqs[j].setSequence(seqs[j].getSequence().substring(i)); } } } @@ -231,14 +263,15 @@ public class Alignment implements AlignmentI */ public void trimRight(int i) { - for (int j = 0; j < getHeight(); j++) + SequenceI[] seqs = getVisibleAndRepresentedSeqs(); + int j, jSize = seqs.length; + for (j = 0; j < jSize; j++) { - SequenceI s = getSequenceAt(j); - int newend = s.findPosition(i); + int newend = seqs[j].findPosition(i); - s.setEnd(newend); - if(s.getLength()>i) - s.setSequence(s.getSequence().substring(0, i + 1)); + seqs[j].setEnd(newend); + if(seqs[j].getLength()>i) + seqs[j].setSequence(seqs[j].getSequence().substring(0, i + 1)); } } @@ -268,62 +301,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) @@ -332,7 +309,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; } @@ -356,14 +333,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); } @@ -522,9 +499,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) ); } } @@ -705,16 +682,22 @@ public class Alignment implements AlignmentI Sequence[] seqs = new Sequence[getHeight()]; for (int i = 0; i < getHeight(); i++) { - - seqs[i] = new Sequence(getSequenceAt(i).getName(), - AlignSeq.extractGaps( - jalview.util.Comparison.GapChars, - getSequenceAt(i).getSequence() - ), - getSequenceAt(i).getStart(), - getSequenceAt(i).getEnd()); - - getSequenceAt(i).setDatasetSequence(seqs[i]); + if(getSequenceAt(i).getDatasetSequence()!=null) + { + seqs[i] = (Sequence)getSequenceAt(i).getDatasetSequence(); + } + else + { + seqs[i] = new Sequence(getSequenceAt(i).getName(), + AlignSeq.extractGaps( + jalview.util.Comparison.GapChars, + getSequenceAt(i).getSequence() + ), + getSequenceAt(i).getStart(), + getSequenceAt(i).getEnd()); + + getSequenceAt(i).setDatasetSequence(seqs[i]); + } } dataset = new Alignment(seqs); @@ -776,4 +759,33 @@ public class Alignment implements AlignmentI return hiddenSequences; } + SequenceI [] getVisibleAndRepresentedSeqs() + { + if(hiddenSequences==null || hiddenSequences.getSize()<1) + return getSequencesArray(); + + Vector seqs = new Vector(); + SequenceI seq; + SequenceGroup hidden; + for (int i = 0; i < sequences.size(); i++) + { + seq = (SequenceI) sequences.elementAt(i); + seqs.addElement(seq); + hidden = seq.getHiddenSequences(); + if(hidden!=null) + { + for(int j=0; j