| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 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.Enumeration; |
| 28 |
|
import java.util.Hashtable; |
| 29 |
|
import java.util.Vector; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
@author |
| 36 |
|
|
| 37 |
|
|
| |
|
| 0% |
Uncovered Elements: 171 (171) |
Complexity: 48 |
Complexity Density: 0.47 |
|
| 38 |
|
public class SimpleBlastFile extends AlignFile |
| 39 |
|
{ |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
StringBuffer headerLines, footerLines; |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
Vector seqids; |
| 49 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 50 |
0 |
public SimpleBlastFile()... |
| 51 |
|
{ |
| 52 |
|
} |
| 53 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 54 |
0 |
public SimpleBlastFile(String inFile, DataSourceType sourceType)... |
| 55 |
|
throws IOException |
| 56 |
|
{ |
| 57 |
0 |
super(inFile, sourceType); |
| 58 |
|
} |
| 59 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 60 |
0 |
public SimpleBlastFile(FileParse source) throws IOException... |
| 61 |
|
{ |
| 62 |
0 |
super(source); |
| 63 |
|
} |
| 64 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 65 |
0 |
@Override... |
| 66 |
|
public void initData() |
| 67 |
|
{ |
| 68 |
0 |
super.initData(); |
| 69 |
0 |
headerLines = new StringBuffer(); |
| 70 |
0 |
footerLines = new StringBuffer(); |
| 71 |
0 |
seqids = new Vector(); |
| 72 |
|
} |
| 73 |
|
|
| |
|
| 0% |
Uncovered Elements: 158 (158) |
Complexity: 43 |
Complexity Density: 0.45 |
|
| 74 |
0 |
@Override... |
| 75 |
|
public void parse() throws IOException |
| 76 |
|
{ |
| 77 |
0 |
String line; |
| 78 |
0 |
char gapc = ' '; |
| 79 |
0 |
Hashtable seqhash = new Hashtable(); |
| 80 |
0 |
boolean inAlignments = false; |
| 81 |
0 |
int padding = -1, numcol = -1, aligcol = -1, lastcol = -1; |
| 82 |
0 |
long qlen = 0, rstart, rend; |
| 83 |
0 |
boolean padseq = false; |
| 84 |
0 |
while ((line = nextLine()) != null) |
| 85 |
|
{ |
| 86 |
0 |
if (line.indexOf("ALIGNMENTS") == 0) |
| 87 |
|
{ |
| 88 |
0 |
inAlignments = true; |
| 89 |
|
} |
| 90 |
|
else |
| 91 |
|
{ |
| 92 |
0 |
if (inAlignments) |
| 93 |
|
{ |
| 94 |
0 |
if (line.trim().length() == 0) |
| 95 |
|
{ |
| 96 |
0 |
continue; |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
0 |
if (line.indexOf("Query") == 0) |
| 102 |
|
{ |
| 103 |
0 |
padding = -1; |
| 104 |
|
|
| 105 |
0 |
numcol = -1; |
| 106 |
0 |
aligcol = -1; |
| 107 |
0 |
lastcol = -1; |
| 108 |
|
|
| 109 |
0 |
for (int p = 5, mLen = line.length(); p < mLen; p++) |
| 110 |
|
{ |
| 111 |
0 |
char c = line.charAt(p); |
| 112 |
0 |
if (c >= '0' && c <= '9') |
| 113 |
|
{ |
| 114 |
0 |
if (numcol == -1) |
| 115 |
|
{ |
| 116 |
0 |
numcol = p; |
| 117 |
|
} |
| 118 |
0 |
else if (aligcol != -1 && lastcol == -1) |
| 119 |
|
{ |
| 120 |
0 |
lastcol = p; |
| 121 |
|
} |
| 122 |
|
} |
| 123 |
|
else |
| 124 |
|
{ |
| 125 |
0 |
if (c >= 'A' && c <= 'z') |
| 126 |
|
{ |
| 127 |
0 |
if (aligcol == -1) |
| 128 |
|
{ |
| 129 |
0 |
aligcol = p; |
| 130 |
0 |
padding = -1; |
| 131 |
|
} |
| 132 |
|
} |
| 133 |
|
else |
| 134 |
|
{ |
| 135 |
0 |
if (padding == -1) |
| 136 |
|
{ |
| 137 |
0 |
padding = p; |
| 138 |
|
} |
| 139 |
|
} |
| 140 |
|
} |
| 141 |
|
} |
| 142 |
0 |
if (padding == -1) |
| 143 |
|
{ |
| 144 |
0 |
padding = aligcol; |
| 145 |
|
} |
| 146 |
|
} |
| 147 |
0 |
if (line.indexOf("Database:") > -1 |
| 148 |
|
|| (aligcol == -1 || numcol == -1 || lastcol == -1) |
| 149 |
|
|| line.length() < lastcol) |
| 150 |
|
{ |
| 151 |
0 |
inAlignments = false; |
| 152 |
|
} |
| 153 |
|
else |
| 154 |
|
{ |
| 155 |
|
|
| 156 |
0 |
String sqid = line.substring(0, numcol).trim(); |
| 157 |
0 |
String stindx = line.substring(numcol, aligcol).trim(); |
| 158 |
0 |
String aligseg = line.substring(aligcol, padding); |
| 159 |
0 |
String endindx = line.substring(lastcol).trim(); |
| 160 |
|
|
| 161 |
0 |
rstart = 1; |
| 162 |
0 |
rend = 0; |
| 163 |
0 |
try |
| 164 |
|
{ |
| 165 |
0 |
rstart = Long.parseLong(stindx); |
| 166 |
|
} catch (Exception e) |
| 167 |
|
{ |
| 168 |
0 |
jalview.bin.Console.errPrintln( |
| 169 |
|
"Couldn't parse '" + stindx + "' as start of row"); |
| 170 |
|
|
| 171 |
|
|
| 172 |
|
} |
| 173 |
0 |
try |
| 174 |
|
{ |
| 175 |
0 |
rend = Long.parseLong(endindx); |
| 176 |
|
} catch (Exception e) |
| 177 |
|
{ |
| 178 |
0 |
jalview.bin.Console.errPrintln( |
| 179 |
|
"Couldn't parse '" + endindx + "' as end of row"); |
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
|
} |
| 184 |
0 |
Vector seqentries = (Vector) seqhash.get(sqid); |
| 185 |
0 |
if (seqentries == null) |
| 186 |
|
{ |
| 187 |
0 |
seqentries = new Vector(); |
| 188 |
0 |
seqhash.put(sqid, seqentries); |
| 189 |
0 |
seqids.addElement(sqid); |
| 190 |
|
} |
| 191 |
|
|
| 192 |
0 |
Object[] seqentry = null; |
| 193 |
0 |
Enumeration sqent = seqentries.elements(); |
| 194 |
0 |
while (seqentry == null && sqent.hasMoreElements()) |
| 195 |
|
{ |
| 196 |
0 |
seqentry = (Object[]) sqent.nextElement(); |
| 197 |
0 |
if (((long[]) seqentry[1])[1] + 1 != rstart) |
| 198 |
|
{ |
| 199 |
0 |
seqentry = null; |
| 200 |
|
} |
| 201 |
|
} |
| 202 |
0 |
padseq = false; |
| 203 |
0 |
if (seqentry == null) |
| 204 |
|
{ |
| 205 |
0 |
padseq = true; |
| 206 |
0 |
seqentry = new Object[] { new StringBuffer(), |
| 207 |
|
new long[] |
| 208 |
|
{ rstart, rend } }; |
| 209 |
0 |
seqentries.addElement(seqentry); |
| 210 |
0 |
seqhash.put(sqid, seqentry); |
| 211 |
|
|
| 212 |
|
} |
| 213 |
0 |
if (sqid.equals("Query")) |
| 214 |
|
{ |
| 215 |
|
|
| 216 |
0 |
qlen = ((StringBuffer) seqentry[0]).length(); |
| 217 |
|
} |
| 218 |
0 |
StringBuffer sqs = ((StringBuffer) seqentry[0]); |
| 219 |
0 |
if (padseq) |
| 220 |
|
{ |
| 221 |
0 |
for (long c = sqs.length(); c < qlen; c++) |
| 222 |
|
{ |
| 223 |
0 |
sqs.append(gapc); |
| 224 |
|
} |
| 225 |
|
} |
| 226 |
0 |
sqs.append(aligseg); |
| 227 |
0 |
if (rend > 0) |
| 228 |
|
{ |
| 229 |
0 |
((long[]) seqentry[1])[1] = rend; |
| 230 |
|
} |
| 231 |
|
} |
| 232 |
|
|
| 233 |
|
} |
| 234 |
|
|
| 235 |
|
|
| 236 |
0 |
if (!inAlignments) |
| 237 |
|
{ |
| 238 |
0 |
String ln = line.trim(); |
| 239 |
|
|
| 240 |
0 |
if (ln.length() > 0) |
| 241 |
|
{ |
| 242 |
0 |
StringBuffer addto = (seqhash.size() > 0) ? footerLines |
| 243 |
|
: headerLines; |
| 244 |
0 |
addto.append(line); |
| 245 |
0 |
addto.append("\n"); |
| 246 |
|
} |
| 247 |
|
} |
| 248 |
|
} |
| 249 |
|
} |
| 250 |
0 |
if (seqhash.size() > 0) |
| 251 |
|
{ |
| 252 |
|
|
| 253 |
0 |
Enumeration seqid = seqids.elements(); |
| 254 |
0 |
while (seqid.hasMoreElements()) |
| 255 |
|
{ |
| 256 |
0 |
String idstring = (String) seqid.nextElement(); |
| 257 |
0 |
Object[] seqentry = (Object[]) seqhash.get(idstring); |
| 258 |
0 |
try |
| 259 |
|
{ |
| 260 |
0 |
Sequence newseq = new Sequence(idstring, |
| 261 |
|
|
| 262 |
|
((StringBuffer) seqentry[0]).toString(), |
| 263 |
|
(int) ((long[]) seqentry[1])[0], |
| 264 |
|
(int) ((long[]) seqentry[1])[1]); |
| 265 |
0 |
if (newseq.getEnd() == 0) |
| 266 |
|
{ |
| 267 |
|
|
| 268 |
0 |
newseq.setEnd(newseq.findPosition(newseq.getLength())); |
| 269 |
|
} |
| 270 |
0 |
seqs.addElement(newseq); |
| 271 |
|
} catch (Exception e) |
| 272 |
|
{ |
| 273 |
0 |
if (warningMessage == null) |
| 274 |
|
{ |
| 275 |
0 |
warningMessage = ""; |
| 276 |
|
} |
| 277 |
0 |
warningMessage += "Couldn't add Sequence - ID is '" + idstring |
| 278 |
|
+ "' : Exception was " + e.toString() + "\n"; |
| 279 |
|
} |
| 280 |
|
} |
| 281 |
|
|
| 282 |
0 |
if (headerLines.length() > 1) |
| 283 |
|
{ |
| 284 |
0 |
setAlignmentProperty("HEADER", headerLines.toString()); |
| 285 |
|
} |
| 286 |
0 |
if (footerLines.length() > 1) |
| 287 |
|
{ |
| 288 |
0 |
setAlignmentProperty("FOOTER", footerLines.toString()); |
| 289 |
|
} |
| 290 |
|
} |
| 291 |
|
} |
| 292 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 293 |
0 |
@Override... |
| 294 |
|
public String print(SequenceI[] sqs, boolean jvsuffix) |
| 295 |
|
{ |
| 296 |
0 |
return new String("Not Implemented."); |
| 297 |
|
} |
| 298 |
|
} |