-/* Jalview - a java multiple alignment editor\r
- * Copyright (C) 1998 Michele Clamp\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- */\r
+/*\r
+* Jalview - A Sequence Alignment Editor and Viewer\r
+* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+*\r
+* This program is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU General Public License\r
+* as published by the Free Software Foundation; either version 2\r
+* of the License, or (at your option) any later version.\r
+*\r
+* This program is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with this program; if not, write to the Free Software\r
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+*/\r
package jalview.io;\r
\r
import jalview.datamodel.*;\r
\r
import java.io.*;\r
-import java.util.*;\r
-import java.net.*;\r
-import java.awt.Font;\r
-\r
-public class BLCFile extends AlignFile {\r
-\r
- Vector titles;\r
-\r
- public BLCFile()\r
- {}\r
-\r
- public BLCFile(String inStr) {\r
- super(inStr);\r
- }\r
\r
- public void initData() {\r
- super.initData();\r
- titles = new Vector();\r
- }\r
-\r
- public BLCFile(String inFile, String type) throws IOException {\r
- super(inFile,type);\r
- }\r
-\r
-\r
- public void parse()\r
- {\r
- boolean idsFound=false;\r
- Vector ids = new Vector();\r
- StringBuffer seqstrings [];\r
- Vector starts = new Vector();\r
- Vector ends = new Vector();\r
-\r
- String line=null;\r
- try{\r
- do{\r
- line = nextLine();\r
+import java.util.*;\r
\r
- // seek end of ids\r
- if (line.indexOf("*") > -1)\r
- {\r
- idsFound=true;\r
- break;\r
- }\r
\r
- if (line.indexOf(">") > -1)\r
- {\r
+/**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
+public class BLCFile extends AlignFile\r
+{\r
+ Vector titles;\r
+\r
+ /**\r
+ * Creates a new BLCFile object.\r
+ */\r
+ public BLCFile()\r
+ {\r
+ }\r
\r
- if(line.indexOf(" ")>-1 )\r
- {\r
- //>54402046 0 1 137 137: immunog\r
- ids.addElement(line.substring(1, line.indexOf(" ")));\r
-\r
- // remove p Value\r
- line = line.substring(line.indexOf(" ") + 1);\r
- line = line.trim();\r
-\r
- line = line.substring(line.indexOf(" ") + 1);\r
- line = line.trim();\r
- starts.addElement(line.substring(0, line.indexOf(" ")));\r
- line = line.substring(line.indexOf(" ") + 1);\r
- line = line.trim();\r
- ends.addElement(line.substring(0, line.indexOf(" ")));\r
- }\r
- else\r
- {\r
- ids.addElement( line.substring(line.indexOf(">") + 1, line.indexOf("/")));\r
- line = line.substring(line.indexOf("/") + 1);\r
- starts.addElement(line.substring(0, line.indexOf("-")));\r
- ends.addElement(line.substring(line.indexOf("-")+1));\r
- }\r
- }\r
- }while(!idsFound);\r
+ /**\r
+ * Creates a new BLCFile object.\r
+ *\r
+ * @param inStr DOCUMENT ME!\r
+ */\r
+ public BLCFile(String inStr)\r
+ {\r
+ super(inStr);\r
+ }\r
\r
- int starCol = line.indexOf("*");\r
- seqstrings = new StringBuffer[ids.size()];\r
- for(int i=0; i<ids.size(); i++)\r
+ /**\r
+ * Creates a new BLCFile object.\r
+ *\r
+ * @param inFile DOCUMENT ME!\r
+ * @param type DOCUMENT ME!\r
+ *\r
+ * @throws IOException DOCUMENT ME!\r
+ */\r
+ public BLCFile(String inFile, String type) throws IOException\r
{\r
- if(seqstrings[i]==null)\r
- seqstrings[i] = new StringBuffer();\r
+ super(inFile, type);\r
}\r
\r
- while ((line = nextLine()).indexOf("*")==-1)\r
+ /**\r
+ * DOCUMENT ME!\r
+ */\r
+ public void initData()\r
{\r
- for(int i=0; i<ids.size(); i++)\r
- seqstrings[i].append( line.charAt(i+starCol) );\r
+ super.initData();\r
+ titles = new Vector();\r
}\r
\r
- for(int i=0; i<ids.size(); i++)\r
+ /**\r
+ * DOCUMENT ME!\r
+ */\r
+ public void parse() throws IOException\r
{\r
- Sequence newSeq = new Sequence(ids.elementAt(i).toString(),\r
- seqstrings[i].toString(),\r
- Integer.parseInt(starts.elementAt(i).toString()),\r
- Integer.parseInt(ends.elementAt(i).toString()));\r
- seqs.addElement(newSeq);\r
+ boolean idsFound = false;\r
+ Vector ids = new Vector();\r
+ StringBuffer[] seqstrings;\r
+ Vector starts = new Vector();\r
+ Vector ends = new Vector();\r
+\r
+ String line = null;\r
+\r
+ do\r
+ {\r
+ line = nextLine();\r
+\r
+ // seek end of ids\r
+ if (line.indexOf("*") > -1)\r
+ {\r
+ idsFound = true;\r
+\r
+ break;\r
+ }\r
+\r
+ int abracket = line.indexOf(">");\r
+\r
+ if (abracket > -1)\r
+ {\r
+ if (line.indexOf(" ") > -1) //\r
+ {\r
+ line = line.substring(abracket + 1,\r
+ line.indexOf(" ", abracket + 1));\r
+ }\r
+ else\r
+ line = line.substring(abracket+1);\r
+\r
+\r
+ Sequence seq = parseId(line);\r
+ ids.addElement(seq.getName());\r
+ starts.addElement(seq.getStart() + "");\r
+ ends.addElement(seq.getEnd() + "");\r
+ }\r
+ }\r
+ while (!idsFound);\r
+\r
+ int starCol = line.indexOf("*");\r
+ seqstrings = new StringBuffer[ids.size()];\r
+\r
+ for (int i = 0; i < ids.size(); i++)\r
+ {\r
+ if (seqstrings[i] == null)\r
+ {\r
+ seqstrings[i] = new StringBuffer();\r
+ }\r
+ }\r
+\r
+ while ((line = nextLine()).indexOf("*") == -1)\r
+ {\r
+ for (int i = 0; i < ids.size(); i++)\r
+ {\r
+ if (line.length() > (i + starCol))\r
+ {\r
+ seqstrings[i].append(line.charAt(i + starCol));\r
+ }\r
+ }\r
+ }\r
+\r
+ for (int i = 0; i < ids.size(); i++)\r
+ {\r
+ Sequence newSeq = new Sequence(ids.elementAt(i).toString(),\r
+ seqstrings[i].toString(),\r
+ Integer.parseInt(starts.elementAt(i).\r
+ toString()),\r
+ Integer.parseInt(ends.elementAt(i).toString()));\r
+\r
+ if (!isValidProteinSequence(newSeq.getSequence()))\r
+ {\r
+ throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS\r
+ +" : "+ newSeq.getName()\r
+ +" : "+invalidCharacter);\r
+\r
+ }\r
+\r
+ seqs.addElement(newSeq);\r
+ }\r
+\r
}\r
\r
- }catch(Exception ex){ex.printStackTrace();}\r
- }\r
-\r
- public String print() {\r
- return print(getSeqsAsArray());\r
- }\r
- public static String print(SequenceI[] s) {\r
- StringBuffer out = new StringBuffer();\r
-\r
- int i=0;\r
- int max = -1;\r
- while (i < s.length && s[i] != null) {\r
- out.append(">" + s[i].getName() + "/" + s[i].getStart() + "-" + s[i].getEnd() + "\n");\r
- if (s[i].getSequence().length() > max) { max = s[i].getSequence().length();}\r
- i++;\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public String print()\r
+ {\r
+ return print(getSeqsAsArray());\r
}\r
\r
- out.append("* iteration 1\n");\r
- for (int j = 0; j < max; j++) {\r
- i=0;\r
- while (i < s.length && s[i] != null) {\r
- if(s[i].getSequence().length()>j )\r
- out.append(s[i].getSequence().substring(j,j+1));\r
- else\r
- out.append("-");\r
- i++;\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param s DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public String print(SequenceI[] s)\r
+ {\r
+ StringBuffer out = new StringBuffer();\r
+ /**\r
+ * A general parser for ids. Will look for dbrefs in\r
+ * Uniprot format source|id\r
+ * And also Jalview /start-end\r
+ *\r
+ * @String id Id to be parsed\r
+ */\r
+ int i = 0;\r
+ int max = -1;\r
+\r
+ while ((i < s.length) && (s[i] != null))\r
+ {\r
+ out.append(">" + printId(s[i]) +"\n");\r
+\r
+ if (s[i].getSequence().length() > max)\r
+ {\r
+ max = s[i].getSequence().length();\r
+ }\r
+\r
+ i++;\r
}\r
- out.append("\n");\r
- }\r
- out.append("*\n");\r
- return out.toString();\r
\r
- }\r
+ out.append("* iteration 1\n");\r
+\r
+ for (int j = 0; j < max; j++)\r
+ {\r
+ i = 0;\r
+\r
+ while ((i < s.length) && (s[i] != null))\r
+ {\r
+ if (s[i].getSequence().length() > j)\r
+ {\r
+ out.append(s[i].getSequence().substring(j, j + 1));\r
+ }\r
+ else\r
+ {\r
+ out.append("-");\r
+ }\r
+\r
+ i++;\r
+ }\r
+\r
+ out.append("\n");\r
+ }\r
+\r
+ out.append("*\n");\r
+\r
+ return out.toString();\r
+ }\r
}\r