}\r
else\r
{\r
- System.out.println("CLEARED HERE");\r
Sequence ds = new Sequence(snew.getName(),\r
AlignSeq.extractGaps("-. ",\r
snew.getSequence()),\r
*/\r
public void removeGaps()\r
{\r
+ SequenceI[] seqs = getVisibleAndRepresentedSeqs();\r
+ int j, jSize = seqs.length;\r
+\r
SequenceI current;\r
- int iSize = getWidth();\r
+ int width = 0;\r
+ for (int i = 0; i < jSize; i++)\r
+ {\r
+ if (seqs[i].getLength() > width)\r
+ {\r
+ width = seqs[i].getLength();\r
+ }\r
+ }\r
\r
- for (int i = 0; i < iSize; i++)\r
+ int startCol = -1, endCol = -1;\r
+ boolean delete = true;\r
+ for (int i = 0; i < width; i++)\r
{\r
- boolean delete = true;\r
+ delete = true;\r
\r
- for (int j = 0; j < getHeight(); j++)\r
+ for (j = 0; j < jSize; j++)\r
{\r
current = getSequenceAt(j);\r
\r
{\r
if (!jalview.util.Comparison.isGap(current.getCharAt(i)))\r
{\r
+ if(delete)\r
+ endCol = i;\r
+\r
delete = false;\r
+ break;\r
}\r
}\r
+\r
+ }\r
+\r
+ if(delete && startCol==-1)\r
+ {\r
+ startCol = i;\r
}\r
\r
- if (delete)\r
+\r
+ if (!delete && startCol > -1)\r
{\r
- deleteColumns(i, i);\r
- iSize--;\r
- i--;\r
+ deleteColumns(seqs, startCol, endCol);\r
+ width -= (endCol - startCol);\r
+ i -= (endCol - startCol);\r
+ startCol = -1;\r
+ endCol = -1;\r
}\r
}\r
+\r
+ if (delete && startCol > -1)\r
+ {\r
+ deleteColumns(seqs, startCol, endCol);\r
+ }\r
+\r
}\r
\r
/** Removes a range of columns (start to end inclusive).\r
*\r
+ * @param seqs Sequences to remove columns from\r
* @param start Start column in the alignment\r
* @param end End column in the alignment\r
*/\r
- public void deleteColumns(int start, int end)\r
+ public void deleteColumns(SequenceI [] seqs, int start, int end)\r
{\r
- deleteColumns(0, getHeight() - 1, start, end);\r
+ for(int i=0; i<seqs.length; i++)\r
+ seqs[i].deleteChars(start, end);\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param seq1 DOCUMENT ME!\r
- * @param seq2 DOCUMENT ME!\r
- * @param start DOCUMENT ME!\r
- * @param end DOCUMENT ME!\r
- */\r
- public void deleteColumns(int seq1, int seq2, int start, int end)\r
- {\r
- for (int i = 0; i <= (end - start); i++)\r
- {\r
- for (int j = seq1; j <= seq2; j++)\r
- {\r
- getSequenceAt(j).deleteCharAt(start);\r
- }\r
- }\r
- }\r
\r
/**\r
* DOCUMENT ME!\r
*/\r
public void trimLeft(int i)\r
{\r
- int j, jSize = getHeight();\r
+ SequenceI[] seqs = getVisibleAndRepresentedSeqs();\r
+ int j, jSize = seqs.length;\r
for (j = 0; j < jSize; j++)\r
{\r
- SequenceI s = getSequenceAt(j);\r
- int newstart = s.findPosition(i);\r
+ int newstart = seqs[j].findPosition(i);\r
\r
- if(i>s.getLength())\r
+ if(i>seqs[j].getLength())\r
{\r
- sequences.removeElement(s);\r
+ sequences.removeElement(seqs[j]);\r
j--;\r
jSize--;\r
}\r
else\r
{\r
- s.setStart(newstart);\r
- s.setSequence(s.getSequence().substring(i));\r
+ seqs[j].setStart(newstart);\r
+ seqs[j].setSequence(seqs[j].getSequence().substring(i));\r
}\r
}\r
}\r
*/\r
public void trimRight(int i)\r
{\r
- for (int j = 0; j < getHeight(); j++)\r
+ SequenceI[] seqs = getVisibleAndRepresentedSeqs();\r
+ int j, jSize = seqs.length;\r
+ for (j = 0; j < jSize; j++)\r
{\r
- SequenceI s = getSequenceAt(j);\r
- int newend = s.findPosition(i);\r
+ int newend = seqs[j].findPosition(i);\r
\r
- s.setEnd(newend);\r
- if(s.getLength()>i)\r
- s.setSequence(s.getSequence().substring(0, i + 1));\r
+ seqs[j].setEnd(newend);\r
+ if(seqs[j].getLength()>i)\r
+ seqs[j].setSequence(seqs[j].getSequence().substring(0, i + 1));\r
}\r
}\r
\r
return hiddenSequences;\r
}\r
\r
+ SequenceI [] getVisibleAndRepresentedSeqs()\r
+ {\r
+ if(hiddenSequences==null || hiddenSequences.getSize()<1)\r
+ return getSequencesArray();\r
+\r
+ Vector seqs = new Vector();\r
+ SequenceI seq;\r
+ SequenceGroup hidden;\r
+ for (int i = 0; i < sequences.size(); i++)\r
+ {\r
+ seq = (SequenceI) sequences.elementAt(i);\r
+ seqs.addElement(seq);\r
+ hidden = seq.getHiddenSequences();\r
+ if(hidden!=null)\r
+ {\r
+ for(int j=0; j<hidden.getSize(false); j++)\r
+ {\r
+ seqs.addElement(hidden.getSequenceAt(j));\r
+ }\r
+ }\r
+ }\r
+ SequenceI [] result = new SequenceI[seqs.size()];\r
+ for(int i=0; i<seqs.size(); i++)\r
+ result[i] = (SequenceI)seqs.elementAt(i);\r
+\r
+ return result;\r
+\r
+ }\r
+\r
}\r