X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=8b159a63de117095db79ad5bbb7d6c22e784d88c;hb=1d6bdfa4ce1d88c055a257e542de6b8542144d91;hp=d67592a3a44998e8402dbeb872c8eec9f0919c82;hpb=7570956d4b58f313d402cdd0507737c0628f1544;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index d67592a..8b159a6 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -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 @@ -70,7 +68,7 @@ public class Alignment implements AlignmentI * @param seqs SeqCigar[] */ public Alignment(SeqCigar[] alseqs) { - SequenceI[] seqs = SeqCigar.createAlignmentSequences(alseqs, gapCharacter, new ColumnSelection()); + SequenceI[] seqs = SeqCigar.createAlignmentSequences(alseqs, gapCharacter, new ColumnSelection(), null); initAlignment(seqs); } /** @@ -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(); } @@ -173,124 +171,6 @@ public class Alignment implements AlignmentI return groups; } - /** Takes out columns consisting entirely of gaps (-,.," ") - */ - public void removeGaps() - { - 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); - 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(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! * @@ -298,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)); } /** @@ -314,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); } } @@ -389,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++; - } } /** */ @@ -427,6 +313,28 @@ public class Alignment implements AlignmentI return null; } + public SequenceI [] findSequenceMatch(String name) + { + Vector matches = new Vector(); + int i = 0; + + while (i < sequences.size()) + { + if (getSequenceAt(i).getName().equals(name)) + { + matches.addElement(getSequenceAt(i)); + } + i++; + } + + SequenceI [] result = new SequenceI[matches.size()]; + for(i=0; i max) - { - max = tmp.length(); - } - - i++; - } - - return max; - } /** * DOCUMENT ME! @@ -515,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) + ); } } @@ -531,15 +415,6 @@ public class Alignment implements AlignmentI return gapCharacter; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Vector getAAFrequency() - { - return AAFrequency.calculate(sequences, 0, getWidth()); - } /** * DOCUMENT ME! @@ -575,6 +450,9 @@ public class Alignment implements AlignmentI aSize = annotations.length; } + if(aSize<1) + return; + AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize - 1]; int tIndex = 0; @@ -594,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! * @@ -696,22 +560,26 @@ 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()); - + currentSeq.getStart(), + currentSeq.getEnd()); + seqs[i].sequenceFeatures = currentSeq.getSequenceFeatures(); + seqs[i].setDescription(currentSeq.getDescription()); + getSequenceAt(i).setSequenceFeatures(null); getSequenceAt(i).setDatasetSequence(seqs[i]); } } @@ -729,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 @@ -752,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) @@ -774,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