protected Alignment dataset;\r
protected Vector sequences;\r
protected Vector groups = new Vector();\r
- protected Vector superGroup = new Vector();\r
protected char gapCharacter = '-';\r
protected int type = NUCLEOTIDE;\r
public static final int PROTEIN = 0;\r
for (i = 0; i < seqs.length; i++)\r
{\r
sequences.addElement(seqs[i]);\r
-\r
- if(seqs[i].getDatasetSequence()!=null\r
- && seqs[i].getDatasetSequence().getAnnotation()!=null)\r
- {\r
-\r
- for(int a=0; a<seqs[i].getDatasetSequence().getAnnotation().length; a++)\r
- {\r
- this.addAnnotation(seqs[i].getDatasetSequence().getAnnotation()[a], seqs[i]);\r
- }\r
- }\r
}\r
-\r
- getWidth();\r
}\r
\r
/**\r
return sequences;\r
}\r
\r
+ public SequenceI [] getSequencesArray()\r
+ {\r
+ SequenceI [] reply = new SequenceI[sequences.size()];\r
+ for(int i=0; i<sequences.size(); i++)\r
+ {\r
+ reply[i] = (SequenceI)sequences.elementAt(i);\r
+ }\r
+ return reply;\r
+ }\r
+\r
/**\r
* DOCUMENT ME!\r
*\r
*/\r
public void addSequence(SequenceI snew)\r
{\r
- sequences.addElement(snew);\r
- }\r
+ if(dataset!=null)\r
+ {\r
+ Sequence ds = new Sequence(snew.getName(),\r
+ AlignSeq.extractGaps("-. ", snew.getSequence()),\r
+ snew.getStart(),\r
+ snew.getEnd());\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param seq DOCUMENT ME!\r
- */\r
- public void addSequence(SequenceI[] seq)\r
- {\r
- for (int i = 0; i < seq.length; i++)\r
- {\r
- addSequence(seq[i]);\r
- }\r
+ snew.setDatasetSequence(ds);\r
+ getDataset().addSequence(ds);\r
+ }\r
+\r
+ sequences.addElement(snew);\r
}\r
\r
+\r
/** Adds a sequence to the alignment. Recalculates maxLength and size.\r
*\r
* @param snew\r
\r
if (current.getLength() > i)\r
{\r
- /* MC Should move this to a method somewhere */\r
if (!jalview.util.Comparison.isGap(current.getCharAt(i)))\r
{\r
delete = false;\r
sequences.removeElementAt(i);\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param threshold DOCUMENT ME!\r
- * @param sel DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public Vector removeRedundancy(float threshold, Vector sel)\r
- {\r
- Vector del = new Vector();\r
-\r
- for (int i = 1; i < sel.size(); i++)\r
- {\r
- for (int j = 0; j < i; j++)\r
- {\r
- // Only do the comparison if either have not been deleted\r
- if (!del.contains((SequenceI) sel.elementAt(i)) ||\r
- !del.contains((SequenceI) sel.elementAt(j)))\r
- {\r
- // use PID instead of Comparison (which is really not pleasant)\r
- float pid = Comparison.PID((SequenceI) sel.elementAt(j),\r
- (SequenceI) sel.elementAt(i));\r
-\r
- if (pid >= threshold)\r
- {\r
- // Delete the shortest one\r
- if (((SequenceI) sel.elementAt(j)).getSequence().length() > ((SequenceI) sel\r
- .elementAt(\r
- i)).getSequence().length())\r
- {\r
- del.addElement(sel.elementAt(i));\r
- }\r
- else\r
- {\r
- del.addElement(sel.elementAt(i));\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- // Now delete the sequences\r
- for (int i = 0; i < del.size(); i++)\r
- {\r
- deleteSequence((SequenceI) del.elementAt(i));\r
- }\r
-\r
- return del;\r
- }\r
-\r
- /** */\r
- public SequenceGroup findGroup(int i)\r
- {\r
- return findGroup(getSequenceAt(i));\r
- }\r
\r
/** */\r
public SequenceGroup findGroup(SequenceI s)\r
{\r
SequenceGroup sg = (SequenceGroup) groups.elementAt(i);\r
\r
- if (sg.sequences.contains(s))\r
+ if (sg.getSequences(false).contains(s))\r
{\r
return sg;\r
}\r
for (int i = 0; i < gSize; i++)\r
{\r
SequenceGroup sg = (SequenceGroup) groups.elementAt(i);\r
- if(sg==null || sg.sequences==null)\r
+ if(sg==null || sg.getSequences(false)==null)\r
{\r
this.deleteGroup(sg);\r
gSize--;\r
continue;\r
}\r
\r
- if (sg.sequences.contains(s))\r
+ if (sg.getSequences(false).contains(s))\r
{\r
temp.addElement(sg);\r
}\r
public void deleteAllGroups()\r
{\r
groups.removeAllElements();\r
- superGroup.removeAllElements();\r
\r
int i = 0;\r
\r
for (int i = 0; i < sequences.size(); i++)\r
{\r
Sequence seq = (Sequence) sequences.elementAt(i);\r
- seq.sequence = seq.sequence.replace('.', gc);\r
- seq.sequence = seq.sequence.replace('-', gc);\r
- seq.sequence = seq.sequence.replace(' ', gc);\r
+ seq.setSequence( seq.getSequence().replace('.', gc) );\r
+ seq.setSequence( seq.getSequence().replace('-', gc) );\r
+ seq.setSequence( seq.getSequence().replace(' ', gc) );\r
}\r
}\r
\r
annotations = temp;\r
}\r
\r
- /**\r
- *\r
- * @param aa AlignmentAnnotation\r
- * @param seqRef The sequence to associate this annotation with\r
- * @return The adjusted AlignmentAnnotation, with dataset sequence and annotation added\r
- */\r
- public AlignmentAnnotation addAnnotation(AlignmentAnnotation aa, SequenceI seqRef)\r
- {\r
- if(seqRef!=null)\r
- {\r
- //We can only add Annotations to the dataset sequences\r
- if(seqRef.getDatasetSequence()==null)\r
- {\r
- setDataset(null);\r
- }\r
-\r
- AlignmentAnnotation [] old = seqRef.getDatasetSequence().getAnnotation();\r
-\r
- //First check if this is a new annotation or not. If it is new,\r
- //we must add the annotation to the dataset\r
- boolean newAnnotation = true;\r
- if(seqRef.getDatasetSequence().getAnnotation()!=null)\r
- {\r
- for(int a=0; a<old.length; a++)\r
- {\r
- if(old[a] == aa)\r
- {\r
-\r
- newAnnotation = false;\r
- break;\r
- }\r
- }\r
- }\r
-\r
- if(newAnnotation)\r
- {\r
- seqRef.getDatasetSequence().addAlignmentAnnotation(aa);\r
- }\r
-\r
- AlignmentAnnotation copy = null;\r
- if (aa.graph > 0)\r
- copy = new AlignmentAnnotation(\r
- aa.label, aa.description, aa.annotations, aa.graphMin,\r
- aa.graphMax, aa.graph\r
- );\r
- else\r
- copy = new AlignmentAnnotation(\r
- aa.label, aa.description, aa.annotations\r
- );\r
-\r
- copy.datasetAnnotation = aa;\r
-\r
- addAnnotation(copy);\r
-\r
- copy.sequenceRef = seqRef;\r
-\r
- return copy;\r
- }\r
- else\r
- {\r
- addAnnotation(aa);\r
- return aa;\r
- }\r
- }\r
\r
public void adjustSequenceAnnotations()\r
{\r
\r
public boolean padGaps() {\r
boolean modified=false;\r
- int Width = getWidth();\r
+\r
+ //Remove excess gaps from the end of alignment\r
+ int maxLength = -1;\r
+\r
SequenceI current;\r
+ for (int i = 0; i < sequences.size(); i++)\r
+ {\r
+ current = getSequenceAt(i);\r
+ for (int j = current.getLength(); j > maxLength; j--)\r
+ {\r
+ if (j > maxLength && !jalview.util.Comparison.isGap(\r
+ current.getCharAt(j)))\r
+ {\r
+ maxLength = j;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ maxLength++;\r
+\r
for (int i = 0; i < sequences.size();\r
i++)\r
{\r
current = getSequenceAt(i);\r
\r
- if (current.getLength() < Width)\r
+ if (current.getLength() < maxLength)\r
{\r
- current.insertCharAt(Width - 1, gapCharacter);\r
+ current.insertCharAt(maxLength - 1, gapCharacter);\r
modified=true;\r
}\r
+ else if(current.getLength() > maxLength)\r
+ {\r
+ current.deleteChars(maxLength, current.getLength());\r
+ }\r
}\r
return modified;\r
}\r