/*
* 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
* @param seqs SeqCigar[]
*/
public Alignment(SeqCigar[] alseqs) {
-
- SequenceI[] seqs = new SequenceI[alseqs.length];
- for (int i=0; i<alseqs.length; i++) {
- seqs[i] = alseqs[i].getSeq(this.gapCharacter);
- }
+ SequenceI[] seqs = SeqCigar.createAlignmentSequences(alseqs, gapCharacter, new ColumnSelection(), null);
initAlignment(seqs);
}
/**
* JBPNote - must also check that compactAlignment resolves to a set of SeqCigars - or construct them appropriately.
* @param compactAlignment CigarArray
*/
- public Alignment(CigarArray compactAlignment) {
+ public static AlignmentI createAlignment(CigarArray compactAlignment) {
throw new Error("Alignment(CigarArray) not yet implemented");
// this(compactAlignment.refCigars);
}
{
if(snew.getDatasetSequence()!=null)
{
- System.out.println(snew.getName());
getDataset().addSequence(snew.getDatasetSequence());
}
else
getDataset().addSequence(ds);
}
}
-
sequences.addElement(snew);
+
+ hiddenSequences.adjustHeightSequenceAdded();
}
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; i<seqs.length; i++)
- seqs[i].deleteChars(start, end);
- }
-
-
- /**
- * DOCUMENT ME!
- *
- * @param i DOCUMENT ME!
- */
- public void trimLeft(int i)
- {
- SequenceI[] seqs = getVisibleAndRepresentedSeqs();
- int j, jSize = seqs.length;
- for (j = 0; j < jSize; j++)
- {
- int newstart = seqs[j].findPosition(i);
-
- if(i>seqs[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!
*
*/
public void deleteSequence(SequenceI s)
{
- for (int i = 0; i < getHeight(); i++)
- {
- if (getSequenceAt(i) == s)
- {
- deleteSequence(i);
- }
- }
+ deleteSequence(findIndex(s));
}
/**
*/
public void deleteSequence(int i)
{
+ if(i>-1 && i<getHeight())
+ {
sequences.removeElementAt(i);
+ hiddenSequences.adjustHeightSequenceDeleted(i);
+ }
}
{
if (!groups.contains(sg))
{
- groups.addElement(sg);
+ if(hiddenSequences.getSize()>0)
+ {
+ //We're not going to make groups of
+ //Hidden sequences
+ int i, iSize = sg.getSize(false);
+ for (i = 0; i < iSize; i++)
+ {
+ if (!sequences.contains(sg.getSequenceAt(i)))
+ {
+ sg.deleteSequence(sg.getSequenceAt(i), false);
+ iSize--;
+ i--;
+ }
+ }
+
+ if (sg.getSize(true) < 1)
+ return;
+ }
+
+ groups.addElement(sg);
}
}
public void deleteAllGroups()
{
groups.removeAllElements();
-
- int i = 0;
-
- while (i < sequences.size())
- {
- SequenceI s = getSequenceAt(i);
- s.setColor(java.awt.Color.white);
- i++;
- }
}
/** */
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<result.length; i++)
+ result[i] = (SequenceI)matches.elementAt(i);
+
+ return result;
+
+ }
+
/** */
public int findIndex(SequenceI s)
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!
return gapCharacter;
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Vector getAAFrequency()
- {
- return AAFrequency.calculate(sequences, 0, getWidth());
- }
/**
* DOCUMENT ME!
aSize = annotations.length;
}
+ if(aSize<1)
+ return;
+
AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize - 1];
int tIndex = 0;
// 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.getSequence()
),
- 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]);
}
}
return dataset;
}
- public boolean padGaps() {
+ public boolean padGaps()
+ {
boolean modified=false;
//Remove excess gaps from the end of alignment
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)
for (int i=0; i<sequences.size(); i++) {
alseqs[i] = new SeqCigar((SequenceI) sequences.elementAt(i));
}
- return new CigarArray(alseqs);
+ CigarArray cal = new CigarArray(alseqs);
+ cal.addOperation(CigarArray.M, getWidth());
+ return cal;
}
}