X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=8b159a63de117095db79ad5bbb7d6c22e784d88c;hb=201b18da026bf92f9cd611e549a9def463583c67;hp=e4bc25e0910a0cab4b8057c01da79f5662729d88;hpb=749ca2a0e792c697a23f68d2cc8d719b306b7f88;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index e4bc25e..8b159a6 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -20,8 +20,6 @@ package jalview.datamodel; import jalview.analysis.*; -import jalview.util.*; - import java.util.*; /** Data structure to hold and manipulate a multiple sequence alignment @@ -131,14 +129,13 @@ public class Alignment implements AlignmentI { if(snew.getDatasetSequence()!=null) { - System.out.println(snew.getName()); getDataset().addSequence(snew.getDatasetSequence()); } else { Sequence ds = new Sequence(snew.getName(), AlignSeq.extractGaps("-. ", - snew.getSequence()), + snew.getSequenceAsString()), snew.getStart(), snew.getEnd()); @@ -146,8 +143,9 @@ public class Alignment implements AlignmentI getDataset().addSequence(ds); } } - sequences.addElement(snew); + + hiddenSequences.adjustHeightSequenceAdded(); } @@ -172,136 +170,6 @@ public class Alignment implements AlignmentI { return groups; } - /** Takes out columns consisting entirely of gaps (-,.," ") - */ - public void removeGaps() { - removeGaps((ShiftList)null); - } - /** - * remove gaps in alignment - recording any frame shifts in shiftrecord - * intended to be passed to ColumnSelection.compensateForEdits(shiftrecord) - * @param shiftrecord - */ - public void removeGaps(ShiftList shiftrecord) { - SequenceI[] seqs = getVisibleAndRepresentedSeqs(); - int j, jSize = seqs.length; - - int width = 0; - for (int i = 0; i < jSize; i++) - { - if (seqs[i].getLength() > width) - { - width = seqs[i].getLength(); - } - } - - int startCol = -1, endCol = -1; - boolean delete = true; - for (int i = 0; i < width; i++) - { - delete = true; - - for (j = 0; j < jSize; j++) - { - if (seqs[j].getLength() > i) - { - if (!jalview.util.Comparison.isGap(seqs[j].getCharAt(i))) - { - if(delete) - endCol = i; - - delete = false; - break; - } - } - } - - if(delete && startCol==-1) - { - startCol = i; - } - - - if (!delete && startCol > -1) - { - deleteColumns(seqs, startCol, endCol); - if (shiftrecord!=null) { - shiftrecord.addShift(startCol, 1+endCol-startCol); - } - width -= (endCol - startCol); - i -= (endCol - startCol); - startCol = -1; - endCol = -1; - } - } - - if (delete && startCol > -1) - { - deleteColumns(seqs, startCol, endCol); - if (shiftrecord!=null) { - shiftrecord.addShift(startCol, 1+endCol-startCol); - } - } - } - - /** 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(SequenceI [] seqs, int start, int end) - { - for(int i=0; iseqs[j].getLength()) - { - sequences.removeElement(seqs[j]); - j--; - jSize--; - } - else - { - seqs[j].setStart(newstart); - seqs[j].setSequence(seqs[j].getSequence().substring(i)); - } - } - } - - /** - * DOCUMENT ME! - * - * @param i DOCUMENT ME! - */ - public void trimRight(int i) - { - SequenceI[] seqs = getVisibleAndRepresentedSeqs(); - int j, jSize = seqs.length; - for (j = 0; j < jSize; j++) - { - int newend = seqs[j].findPosition(i); - - seqs[j].setEnd(newend); - if(seqs[j].getLength()>i) - seqs[j].setSequence(seqs[j].getSequence().substring(0, i + 1)); - } - } /** * DOCUMENT ME! @@ -310,13 +178,7 @@ public class Alignment implements AlignmentI */ public void deleteSequence(SequenceI s) { - for (int i = 0; i < getHeight(); i++) - { - if (getSequenceAt(i) == s) - { - deleteSequence(i); - } - } + deleteSequence(findIndex(s)); } /** @@ -326,7 +188,11 @@ public class Alignment implements AlignmentI */ public void deleteSequence(int i) { + if(i>-1 && i0) + { + int i, iSize = sg.getSize(); + for (i = 0; i < iSize; i++) + { + if (!sequences.contains(sg.getSequenceAt(i))) + { + sg.deleteSequence(sg.getSequenceAt(i), false); + iSize--; + i--; + } + } + + if (sg.getSize() < 1) + return; + } + + groups.addElement(sg); } } @@ -401,15 +284,6 @@ public class Alignment implements AlignmentI public void deleteAllGroups() { groups.removeAllElements(); - - int i = 0; - - while (i < sequences.size()) - { - SequenceI s = getSequenceAt(i); - s.setColor(java.awt.Color.white); - i++; - } } /** */ @@ -510,32 +384,6 @@ public class Alignment implements AlignmentI return maxLength; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getMaxIdLength() - { - int max = 0; - int i = 0; - - while (i < sequences.size()) - { - SequenceI seq = getSequenceAt(i); - String tmp = seq.getName() + "/" + seq.getStart() + "-" + - seq.getEnd(); - - if (tmp.length() > max) - { - max = tmp.length(); - } - - i++; - } - - return max; - } /** * DOCUMENT ME! @@ -549,9 +397,11 @@ public class Alignment implements AlignmentI for (int i = 0; i < sequences.size(); i++) { Sequence seq = (Sequence) sequences.elementAt(i); - seq.setSequence( seq.getSequence().replace('.', gc) ); - seq.setSequence( seq.getSequence().replace('-', gc) ); - seq.setSequence( seq.getSequence().replace(' ', gc) ); + seq.setSequence(seq.getSequenceAsString() + .replace('.', gc) + .replace('-', gc) + .replace(' ', gc) + ); } } @@ -600,6 +450,9 @@ public class Alignment implements AlignmentI aSize = annotations.length; } + if(aSize<1) + return; + AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize - 1]; int tIndex = 0; @@ -619,20 +472,6 @@ public class Alignment implements AlignmentI } - public void adjustSequenceAnnotations() - { - if(annotations!=null) - { - for (int a = 0; a < annotations.length; a++) - { - if (annotations[a].sequenceRef != null) - { - annotations[a].adjustForAlignment(); - } - } - } - } - /** * DOCUMENT ME! * @@ -721,22 +560,25 @@ public class Alignment implements AlignmentI // Can only be done once, if dataset is not null // This will not be performed Sequence[] seqs = new Sequence[getHeight()]; + SequenceI currentSeq; for (int i = 0; i < getHeight(); i++) { - if(getSequenceAt(i).getDatasetSequence()!=null) + currentSeq = getSequenceAt(i); + if(currentSeq.getDatasetSequence()!=null) { - seqs[i] = (Sequence)getSequenceAt(i).getDatasetSequence(); + seqs[i] = (Sequence)currentSeq.getDatasetSequence(); } else { - seqs[i] = new Sequence(getSequenceAt(i).getName(), + seqs[i] = new Sequence(currentSeq.getName(), AlignSeq.extractGaps( jalview.util.Comparison.GapChars, - getSequenceAt(i).getSequence() + currentSeq.getSequenceAsString() ), - getSequenceAt(i).getStart(), - getSequenceAt(i).getEnd()); - seqs[i].sequenceFeatures = getSequenceAt(i).getSequenceFeatures(); + currentSeq.getStart(), + currentSeq.getEnd()); + seqs[i].sequenceFeatures = currentSeq.getSequenceFeatures(); + seqs[i].setDescription(currentSeq.getDescription()); getSequenceAt(i).setSequenceFeatures(null); getSequenceAt(i).setDatasetSequence(seqs[i]); } @@ -755,7 +597,8 @@ public class Alignment implements AlignmentI return dataset; } - public boolean padGaps() { + public boolean padGaps() + { boolean modified=false; //Remove excess gaps from the end of alignment @@ -778,14 +621,17 @@ public class Alignment implements AlignmentI maxLength++; + int cLength; for (int i = 0; i < sequences.size(); i++) { current = getSequenceAt(i); + cLength = current.getLength(); - if (current.getLength() < maxLength) + if (cLength < maxLength) { - current.insertCharAt(maxLength - 1, gapCharacter); + current.insertCharAt(cLength, + maxLength-cLength, gapCharacter); modified=true; } else if(current.getLength() > maxLength) @@ -800,34 +646,6 @@ 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