Clover icon

Coverage Report

  1. Project Clover database Mon Nov 18 2024 09:38:20 GMT
  2. Package jalview.io

File BLCFile.java

 

Coverage histogram

../../img/srcFileCovDistChart8.png
13% of files have more coverage

Code metrics

44
81
6
1
283
175
34
0.42
13.5
6
5.67

Classes

Class Line # Actions
BLCFile 35 81 34
0.755725275.6%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.io;
22   
23    import jalview.datamodel.Sequence;
24    import jalview.datamodel.SequenceI;
25   
26    import java.io.IOException;
27    import java.util.Vector;
28   
29    /**
30    * DOCUMENT ME!
31    *
32    * @author $author$
33    * @version $Revision$
34    */
 
35    public class BLCFile extends AlignFile
36    {
37    Vector titles;
38   
39    /**
40    * Creates a new BLCFile object.
41    */
 
42  1 toggle public BLCFile()
43    {
44    }
45   
46    /**
47    * Creates a new BLCFile object.
48    *
49    * @param inFile
50    * DOCUMENT ME!
51    * @param sourceType
52    * DOCUMENT ME!
53    *
54    * @throws IOException
55    * DOCUMENT ME!
56    */
 
57  0 toggle public BLCFile(String inFile, DataSourceType sourceType)
58    throws IOException
59    {
60  0 super(inFile, sourceType);
61    }
62   
 
63  1 toggle public BLCFile(FileParse source) throws IOException
64    {
65  1 super(source);
66    }
67   
68    /**
69    * DOCUMENT ME!
70    */
 
71  2 toggle @Override
72    public void initData()
73    {
74  2 super.initData();
75  2 titles = new Vector();
76    }
77   
78    /**
79    * Control the number of block iterations to skip before returning. set to 0
80    * to read first block file entry only set to -1 to read last block file entry
81    * only set to greater than zero to skip at most that many entries before
82    * parsing
83    */
84    int iterationSkips = 0;
85   
86    /**
87    * The iteration number for the alignment actually parsed from the blc file
88    */
89    int iterationCount = 0;
90   
91    /**
92    * DOCUMENT ME!
93    */
 
94  1 toggle @Override
95    public void parse() throws IOException
96    {
97  1 StringBuffer headerLines = new StringBuffer();
98  1 int numHeaderLines = 0; // number of lines appended.
99  1 StringBuffer[] seqstrings = null;
100  1 if (suffix != null)
101    {
102  0 try
103    {
104  0 iterationSkips = Integer.parseInt(suffix);
105    } catch (NumberFormatException e)
106    {
107  0 iterationSkips = 0; // first
108    }
109    }
110   
111  1 String line = null;
112   
113  1 do
114    {
115  1 boolean idsFound = false;
116  1 boolean newids = false;
117    // search for ID header.
118  1 do
119    {
120  16 line = nextLine();
121  16 if (line == null)
122    {
123  0 break;
124    }
125    // seek end of ids
126  16 if (line.indexOf("*") > -1)
127    {
128  1 idsFound = true;
129   
130  1 break;
131    }
132   
133  15 int abracket = line.indexOf(">");
134   
135  15 if (abracket > -1)
136    {
137   
138  15 if (iterationCount > 0 && !newids)
139    {
140    // we have a new set of IDs to record.
141  0 newids = true;
142  0 seqs.removeAllElements();
143    }
144   
145  15 line = line.substring(abracket + 1);
146   
147  15 Sequence seq = parseId(line);
148  15 seqs.addElement(seq);
149    }
150    else
151    {
152    // header lines - keep them for the alignment comments.
153  0 headerLines.append(line);
154  0 headerLines.append(newline);
155  0 numHeaderLines++;
156    }
157  15 } while (!idsFound);
158  1 if (line == null)
159    {
160  0 break; // end of file.
161    }
162  1 int starCol = line.indexOf("*");
163  1 seqstrings = new StringBuffer[seqs.size()];
164   
165  16 for (int i = 0; i < seqs.size(); i++)
166    {
167  15 if (seqstrings[i] == null)
168    {
169  15 seqstrings[i] = new StringBuffer();
170    }
171    }
172   
173  1 try
174    {
175  1 line = nextLine();
176  158 while (line != null && line.indexOf("*") == -1)
177    {
178  2512 for (int i = 0; i < seqs.size(); i++)
179    {
180  2355 if (line.length() > (i + starCol))
181    {
182  2355 seqstrings[i].append(line.charAt(i + starCol));
183    }
184    }
185  157 line = nextLine();
186    }
187    } catch (IOException e)
188    {
189  0 if (iterationCount == 0)
190    {
191  0 throw (e); // otherwise we've just run out of iterations.
192    }
193    else
194    {
195  0 iterationSkips = 0;
196    }
197    }
198  1 iterationCount++;
199  1 } while (--iterationSkips != -1);
200   
201  16 for (int i = 0; i < seqs.size(); i++)
202    {
203  15 Sequence newSeq = (Sequence) seqs.elementAt(i);
204   
205  15 newSeq.setSequence(seqstrings[i].toString());
206    }
207  1 if (seqs.size() > 0)
208    {
209  1 if (headerLines.length() > 1 + numHeaderLines)
210    {
211    // just whitespace or not.
212  0 setAlignmentProperty("Comments", headerLines.toString());
213    }
214  1 setAlignmentProperty("iteration", "" + iterationCount);
215    }
216    }
217   
218    /**
219    * DOCUMENT ME!
220    *
221    * @param s
222    * DOCUMENT ME!
223    *
224    * @return DOCUMENT ME!
225    */
 
226  1 toggle @Override
227    public String print(SequenceI[] s, boolean jvsuffix)
228    {
229  1 StringBuffer out = new StringBuffer();
230    /**
231    * A general parser for ids. Will look for dbrefs in Uniprot format
232    * source|id And also Jalview /start-end
233    *
234    * @String id Id to be parsed
235    */
236  1 int i = 0;
237  1 int max = -1;
238   
239  16 while ((i < s.length) && (s[i] != null))
240    {
241  15 out.append(">" + printId(s[i], jvsuffix));
242  15 if (s[i].getDescription() != null)
243    {
244  15 out.append(" " + s[i].getDescription());
245    }
246   
247  15 out.append(newline);
248   
249  15 max = Math.max(max, s[i].getLength());
250   
251  15 i++;
252    }
253   
254  1 out.append("* iteration 1");
255  1 out.append(newline);
256   
257  158 for (int j = 0; j < max; j++)
258    {
259  157 i = 0;
260   
261  2512 while ((i < s.length) && (s[i] != null))
262    {
263  2355 if (s[i].getSequence().length > j)
264    {
265  2355 out.append(s[i].getSequenceAsString(j, j + 1));
266    }
267    else
268    {
269  0 out.append("-");
270    }
271   
272  2355 i++;
273    }
274   
275  157 out.append(newline);
276    }
277   
278  1 out.append("*");
279  1 out.append(newline);
280   
281  1 return out.toString();
282    }
283    }