use new file filter
[jalview.git] / src / jalview / io / BLCFile.java
1 /* Jalview - a java multiple alignment editor\r
2  * Copyright (C) 1998  Michele Clamp\r
3  *\r
4  * This program is free software; you can redistribute it and/or\r
5  * modify it under the terms of the GNU General Public License\r
6  * as published by the Free Software Foundation; either version 2\r
7  * of the License, or (at your option) any later version.\r
8  *\r
9  * This program is distributed in the hope that it will be useful,\r
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12  * GNU General Public License for more details.\r
13  *\r
14  * You should have received a copy of the GNU General Public License\r
15  * along with this program; if not, write to the Free Software\r
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
17  */\r
18 package jalview.io;\r
19 \r
20 import jalview.datamodel.*;\r
21 \r
22 import java.io.*;\r
23 import java.util.*;\r
24 import java.net.*;\r
25 import java.awt.Font;\r
26 \r
27 public class BLCFile extends AlignFile {\r
28 \r
29   Vector titles;\r
30 \r
31   public BLCFile()\r
32   {}\r
33 \r
34   public BLCFile(String inStr) {\r
35     super(inStr);\r
36   }\r
37 \r
38   public void initData() {\r
39     super.initData();\r
40     titles = new Vector();\r
41   }\r
42 \r
43   public BLCFile(String inFile, String type) throws IOException {\r
44     super(inFile,type);\r
45   }\r
46 \r
47 \r
48   public void parse()\r
49   {\r
50     boolean idsFound=false;\r
51     Vector ids = new Vector();\r
52     StringBuffer seqstrings [];\r
53     Vector starts = new Vector();\r
54     Vector ends = new Vector();\r
55 \r
56    String line=null;\r
57    try{\r
58      do{\r
59       line = nextLine();\r
60 \r
61       // seek end of ids\r
62       if (line.indexOf("*") > -1)\r
63       {\r
64         idsFound=true;\r
65         break;\r
66       }\r
67 \r
68       if (line.indexOf(">") > -1)\r
69       {\r
70 \r
71         if(line.indexOf(" ")>-1 )\r
72         {\r
73           //>54402046         0             1   137   137: immunog\r
74           ids.addElement(line.substring(1, line.indexOf(" ")));\r
75 \r
76           // remove p Value\r
77           line = line.substring(line.indexOf(" ") + 1);\r
78           line = line.trim();\r
79 \r
80           line = line.substring(line.indexOf(" ") + 1);\r
81           line = line.trim();\r
82           starts.addElement(line.substring(0, line.indexOf(" ")));\r
83           line = line.substring(line.indexOf(" ") + 1);\r
84           line = line.trim();\r
85           ends.addElement(line.substring(0, line.indexOf(" ")));\r
86         }\r
87         else\r
88         {\r
89           ids.addElement( line.substring(line.indexOf(">") + 1, line.indexOf("/")));\r
90           line = line.substring(line.indexOf("/") + 1);\r
91           starts.addElement(line.substring(0, line.indexOf("-")));\r
92           ends.addElement(line.substring(line.indexOf("-")+1));\r
93         }\r
94       }\r
95     }while(!idsFound);\r
96 \r
97     int starCol = line.indexOf("*");\r
98     seqstrings = new StringBuffer[ids.size()];\r
99     for(int i=0; i<ids.size(); i++)\r
100     {\r
101       if(seqstrings[i]==null)\r
102         seqstrings[i] = new StringBuffer();\r
103     }\r
104 \r
105     while ((line = nextLine()).indexOf("*")==-1)\r
106     {\r
107       for(int i=0; i<ids.size(); i++)\r
108         seqstrings[i].append( line.charAt(i+starCol) );\r
109     }\r
110 \r
111     for(int i=0; i<ids.size(); i++)\r
112     {\r
113       Sequence newSeq = new Sequence(ids.elementAt(i).toString(),\r
114                                      seqstrings[i].toString(),\r
115                                      Integer.parseInt(starts.elementAt(i).toString()),\r
116                                      Integer.parseInt(ends.elementAt(i).toString()));\r
117       seqs.addElement(newSeq);\r
118     }\r
119 \r
120    }catch(Exception ex){ex.printStackTrace();}\r
121   }\r
122 \r
123   public String print() {\r
124     return print(getSeqsAsArray());\r
125   }\r
126   public static String print(SequenceI[] s) {\r
127     StringBuffer out = new StringBuffer();\r
128 \r
129     int i=0;\r
130     int max = -1;\r
131     while (i < s.length && s[i] != null) {\r
132       out.append(">" + s[i].getName() + "/" + s[i].getStart() + "-" + s[i].getEnd() + "\n");\r
133       if (s[i].getSequence().length() > max) { max = s[i].getSequence().length();}\r
134       i++;\r
135     }\r
136 \r
137       out.append("* iteration 1\n");\r
138       for (int j = 0; j < max; j++) {\r
139         i=0;\r
140         while (i < s.length && s[i] != null) {\r
141           if(s[i].getSequence().length()>j )\r
142             out.append(s[i].getSequence().substring(j,j+1));\r
143           else\r
144             out.append("-");\r
145           i++;\r
146         }\r
147         out.append("\n");\r
148       }\r
149     out.append("*\n");\r
150     return out.toString();\r
151 \r
152   }\r
153 }\r