| 1 |
package hiseq; |
| 2 |
|
| 3 |
import shared.KillSwitch; |
| 4 |
import shared.Tools; |
| 5 |
import structures.ByteBuilder; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
public class IlluminaHeaderParser1 extends ReadHeaderParser { |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public static void main(String[] args) { |
| 21 |
PARSE_COMMENT=true; |
| 22 |
IlluminaHeaderParser1 ihp=new IlluminaHeaderParser1(); |
| 23 |
ihp.test(args.length>0 ? args[0] : null); |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public IlluminaHeaderParser1 parse(String id_) { |
| 63 |
reset(id_); |
| 64 |
|
| 65 |
try { |
| 66 |
commentSeparator=findCommentSeparator(); |
| 67 |
if(PARSE_COORDINATES){parseCoordinates();} |
| 68 |
if(PARSE_COMMENT){parseComment();} |
| 69 |
} catch (Throwable e) { |
| 70 |
System.err.println("Trouble parsing header "+id_); |
| 71 |
KillSwitch.throwableKill(e); |
| 72 |
} |
| 73 |
return this; |
| 74 |
} |
| 75 |
|
| 76 |
@Override |
| 77 |
public String machine() { |
| 78 |
return null; |
| 79 |
} |
| 80 |
|
| 81 |
@Override |
| 82 |
public String sample() { |
| 83 |
return null; |
| 84 |
} |
| 85 |
|
| 86 |
@Override |
| 87 |
public int run() { |
| 88 |
return -1; |
| 89 |
} |
| 90 |
|
| 91 |
@Override |
| 92 |
public String flowcell() { |
| 93 |
return null; |
| 94 |
} |
| 95 |
|
| 96 |
@Override |
| 97 |
public int lane() {return lane;} |
| 98 |
|
| 99 |
@Override |
| 100 |
public int tile() {return tile;} |
| 101 |
|
| 102 |
@Override |
| 103 |
public int xPos() {return x;} |
| 104 |
|
| 105 |
@Override |
| 106 |
public int yPos() {return y;} |
| 107 |
|
| 108 |
@Override |
| 109 |
public char pairCode() {return pairCode;} |
| 110 |
|
| 111 |
@Override |
| 112 |
public char chastityCode() {return chastityCode;} |
| 113 |
|
| 114 |
@Override |
| 115 |
public int controlBits() {return controlBits;} |
| 116 |
|
| 117 |
@Override |
| 118 |
public String barcode() { |
| 119 |
assert(PARSE_COMMENT); |
| 120 |
return barcode; |
| 121 |
} |
| 122 |
|
| 123 |
@Override |
| 124 |
public String extra() { |
| 125 |
assert(PARSE_COMMENT); |
| 126 |
return extra; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
private void parseCoordinates(){ |
| 135 |
pos=commentSeparator; |
| 136 |
goBackSeveralColons(4); |
| 137 |
lane=parseInt(); |
| 138 |
if(!Tools.isDigit(id.charAt(pos))){ |
| 139 |
while(pos<limit && id.charAt(pos)!=':'){pos++;} |
| 140 |
pos++; |
| 141 |
lane=parseInt(); |
| 142 |
} |
| 143 |
|
| 144 |
tile=parseInt(); |
| 145 |
x=parseInt(); |
| 146 |
y=parseInt(); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
private void parseComment(){ |
| 151 |
pos=commentSeparator+1; |
| 152 |
pairCode=parseChar(); |
| 153 |
chastityCode=parseChar(); |
| 154 |
controlBits=parseInt(); |
| 155 |
int idx=id.indexOf(' ', pos); |
| 156 |
idx=(idx>=0 ? idx : id.indexOf('\t', pos)); |
| 157 |
if(idx<0) { |
| 158 |
barcode=id.substring(pos); |
| 159 |
extra=null; |
| 160 |
}else { |
| 161 |
barcode=id.substring(pos, idx); |
| 162 |
extra=id.substring(idx+1); |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
private void reset(String id_){ |
| 168 |
id=id_; |
| 169 |
limit=(id==null ? -1 : id.length()); |
| 170 |
pos=-1; |
| 171 |
commentSeparator=-1; |
| 172 |
|
| 173 |
lane=-1; |
| 174 |
tile=-1; |
| 175 |
x=-1; |
| 176 |
y=-1; |
| 177 |
|
| 178 |
pairCode='?'; |
| 179 |
barcode=null; |
| 180 |
chastityCode='?'; |
| 181 |
controlBits=-1; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
private int findCommentSeparator(){ |
| 193 |
for(int i=0; i<limit; i++){ |
| 194 |
char c=id.charAt(i); |
| 195 |
if(c==' ' || c== '/'){return i;} |
| 196 |
} |
| 197 |
return limit; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
private void goBackSeveralColons(int target){ |
| 206 |
for(int colons=0; pos>=0; pos--){ |
| 207 |
if(id.charAt(pos)==':'){ |
| 208 |
colons++; |
| 209 |
if(colons==target){break;} |
| 210 |
} |
| 211 |
} |
| 212 |
pos++; |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
private int parseInt(){ |
| 222 |
int current=0; |
| 223 |
assert(Tools.isDigit(id.charAt(pos))) : id; |
| 224 |
while(pos<limit && Tools.isDigit(id.charAt(pos))){ |
| 225 |
current=current*10+(id.charAt(pos)-'0'); |
| 226 |
pos++; |
| 227 |
} |
| 228 |
pos++; |
| 229 |
return current; |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
private char parseChar(){ |
| 239 |
char c=id.charAt(pos); |
| 240 |
assert(c!=':'); |
| 241 |
pos++; |
| 242 |
assert(pos>=limit || id.charAt(pos)==':'); |
| 243 |
pos++; |
| 244 |
assert(pos>=limit || id.charAt(pos)!=':'); |
| 245 |
return c; |
| 246 |
} |
| 247 |
|
| 248 |
public String toString() { |
| 249 |
ByteBuilder bb=new ByteBuilder(); |
| 250 |
bb.append("lane:\t").append(lane).nl(); |
| 251 |
bb.append("tile:\t").append(tile).nl(); |
| 252 |
bb.append("x:\t").append(x).nl(); |
| 253 |
bb.append("y:\t").append(y).nl(); |
| 254 |
bb.append("pairnum:\t").append(pairCode).nl(); |
| 255 |
bb.append("barcode:\t").append(barcode).nl(); |
| 256 |
bb.append("chastity:\t").append(chastityCode).nl(); |
| 257 |
return bb.toString(); |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
public int lane; |
| 266 |
|
| 267 |
public int tile; |
| 268 |
|
| 269 |
public int x; |
| 270 |
|
| 271 |
public int y; |
| 272 |
|
| 273 |
|
| 274 |
public char pairCode; |
| 275 |
|
| 276 |
public char chastityCode; |
| 277 |
|
| 278 |
public int controlBits; |
| 279 |
|
| 280 |
public String barcode; |
| 281 |
|
| 282 |
public String extra; |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
private int limit; |
| 290 |
|
| 291 |
private int pos; |
| 292 |
|
| 293 |
private int commentSeparator; |
| 294 |
|
| 295 |
} |