| 1 |
package hiseq; |
| 2 |
|
| 3 |
import shared.Tools; |
| 4 |
import stream.Read; |
| 5 |
import structures.ByteBuilder; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
public abstract class ReadHeaderParser { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public final void test(String s) { |
| 48 |
if(s==null) {s="LH00223:28:22GLGMLT3:1:1101:5928:1016 1:N:0:CTGCTTGGTT+CTAACGACAG";} |
| 49 |
parse(s); |
| 50 |
System.err.println("ihp="+this); |
| 51 |
System.err.println("id="+id()); |
| 52 |
|
| 53 |
|
| 54 |
System.err.println("whitespaceIndex="+whitespaceIndex()); |
| 55 |
|
| 56 |
|
| 57 |
System.err.println("machine="+machine()); |
| 58 |
System.err.println("run="+run()); |
| 59 |
System.err.println("flowcell="+flowcell()); |
| 60 |
System.err.println("lane="+lane()); |
| 61 |
System.err.println("tile="+tile()); |
| 62 |
System.err.println("xPos="+xPos()); |
| 63 |
System.err.println("yPos="+yPos()); |
| 64 |
System.err.println("surface="+surface()); |
| 65 |
System.err.println("swath="+swath()); |
| 66 |
System.err.println("pairCode="+pairCode()); |
| 67 |
System.err.println("pairnum="+pairnum()); |
| 68 |
System.err.println("chastityCode="+chastityCode()); |
| 69 |
System.err.println("chastityFail="+chastityFail()); |
| 70 |
System.err.println("controlBits="+controlBits()); |
| 71 |
System.err.println("barcode="+barcode()); |
| 72 |
System.err.println("extra="+extra()); |
| 73 |
System.err.println("index3="+index3()); |
| 74 |
System.err.println("commentSeparator='"+commentSeparator()+"' ("+(int)commentSeparator()+")"); |
| 75 |
System.err.println("pairnum="+pairnum()); |
| 76 |
System.err.println("barcodeDelimiter='"+barcodeDelimiter()+"' ("+(int)barcodeDelimiter()+")"); |
| 77 |
System.err.println("barcodeLength1="+barcodeLength1()); |
| 78 |
System.err.println("barcodeLength2="+barcodeLength2()); |
| 79 |
System.err.println("barcodeLength="+barcodeLength()); |
| 80 |
System.err.println("barcodeLetters="+barcodeLetters()); |
| 81 |
System.err.println("numBarcodes="+numBarcodes()); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public abstract ReadHeaderParser parse(String id); |
| 89 |
public abstract String machine(); |
| 90 |
public abstract int run(); |
| 91 |
public abstract String flowcell(); |
| 92 |
public abstract int lane(); |
| 93 |
public abstract int tile(); |
| 94 |
public abstract int xPos(); |
| 95 |
public abstract int yPos(); |
| 96 |
public abstract char pairCode(); |
| 97 |
public abstract char chastityCode(); |
| 98 |
public abstract int controlBits(); |
| 99 |
public abstract String barcode(); |
| 100 |
public abstract String extra(); |
| 101 |
public abstract String sample(); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public final ReadHeaderParser parse(Read r){ |
| 108 |
return parse(r.id); |
| 109 |
} |
| 110 |
|
| 111 |
public final String id() {return id;} |
| 112 |
|
| 113 |
public char commentSeparator() { |
| 114 |
for(int i=0; i<id.length(); i++){ |
| 115 |
char c=id.charAt(i); |
| 116 |
if(c==' ' || c== '/'){return c;} |
| 117 |
} |
| 118 |
return 0; |
| 119 |
} |
| 120 |
|
| 121 |
public int surface() { |
| 122 |
return surface(tile()); |
| 123 |
} |
| 124 |
|
| 125 |
public int swath() { |
| 126 |
return swath(tile()); |
| 127 |
} |
| 128 |
|
| 129 |
public int pairnum() { |
| 130 |
return pairCode()-(int)'1'; |
| 131 |
} |
| 132 |
|
| 133 |
public boolean chastityFail() { |
| 134 |
int c=chastityCode(); |
| 135 |
assert(c=='N' || c=='Y') : c; |
| 136 |
return c=='Y'; |
| 137 |
} |
| 138 |
|
| 139 |
public char barcodeDelimiter() { |
| 140 |
return barcodeDelimiter(barcode()); |
| 141 |
} |
| 142 |
|
| 143 |
public int barcodeLength1() { |
| 144 |
return barcodeLength1(barcode()); |
| 145 |
} |
| 146 |
|
| 147 |
public int barcodeLength2() { |
| 148 |
return barcodeLength2(barcode()); |
| 149 |
} |
| 150 |
|
| 151 |
public int barcodeLength() { |
| 152 |
String bc=barcode(); |
| 153 |
return bc==null ? 0 : bc.length(); |
| 154 |
} |
| 155 |
|
| 156 |
public int barcodeLetters() { |
| 157 |
return barcodeLetters(barcode()); |
| 158 |
} |
| 159 |
|
| 160 |
public int numBarcodes() { |
| 161 |
return numBarcodes(barcode()); |
| 162 |
} |
| 163 |
|
| 164 |
public String index3() {return null;} |
| 165 |
public int whitespaceIndex() {return -1;} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
public static char commentSeparator(String id) { |
| 172 |
for(int i=0; i<id.length(); i++){ |
| 173 |
char c=id.charAt(i); |
| 174 |
if(c==' ' || c== '/'){return c;} |
| 175 |
} |
| 176 |
return 0; |
| 177 |
} |
| 178 |
|
| 179 |
public static final int surface(int tile) { |
| 180 |
return tile/1000; |
| 181 |
} |
| 182 |
|
| 183 |
public static final int swath(int tile) { |
| 184 |
return (tile%1000)/100; |
| 185 |
} |
| 186 |
|
| 187 |
public static final char barcodeDelimiter(String bc) { |
| 188 |
if(bc==null) {return 0;} |
| 189 |
for(int i=0; i<bc.length(); i++){ |
| 190 |
char c=bc.charAt(i); |
| 191 |
if(!Character.isLetter(c)){return c;} |
| 192 |
} |
| 193 |
return 0; |
| 194 |
} |
| 195 |
|
| 196 |
public static int barcodeLength1(String bc) { |
| 197 |
if(bc==null) {return 0;} |
| 198 |
for(int i=0; i<bc.length(); i++){ |
| 199 |
char c=bc.charAt(i); |
| 200 |
if(!Tools.isLetter(c)){return i;} |
| 201 |
} |
| 202 |
return bc.length(); |
| 203 |
} |
| 204 |
|
| 205 |
public static int barcodeLength2(String bc) { |
| 206 |
if(bc==null) {return 0;} |
| 207 |
for(int i=bc.length()-1; i>=0; i--){ |
| 208 |
char c=bc.charAt(i); |
| 209 |
if(!Tools.isLetter(c)){return bc.length()-1-i;} |
| 210 |
} |
| 211 |
return 0; |
| 212 |
} |
| 213 |
|
| 214 |
public static int barcodeLetters(String bc) { |
| 215 |
if(bc==null) {return 0;} |
| 216 |
int letters=0; |
| 217 |
for(int i=0; i<bc.length(); i++){ |
| 218 |
char c=bc.charAt(i); |
| 219 |
letters+=(Tools.isLetter(c) ? 1 : 0); |
| 220 |
} |
| 221 |
return letters; |
| 222 |
} |
| 223 |
|
| 224 |
public static int numBarcodes(String bc) { |
| 225 |
return (barcodeLength1(bc)>0 ? 1 : 0)+(barcodeLength2(bc)>0 ? 1 : 0); |
| 226 |
} |
| 227 |
|
| 228 |
public String toString() { |
| 229 |
ByteBuilder bb=new ByteBuilder(); |
| 230 |
bb.append("lane:\t").append(lane()).nl(); |
| 231 |
bb.append("tile:\t").append(tile()).nl(); |
| 232 |
bb.append("x:\t").append(xPos()).nl(); |
| 233 |
bb.append("y:\t").append(yPos()).nl(); |
| 234 |
bb.append("pairnum:\t").append(pairCode()).nl(); |
| 235 |
bb.append("barcode:\t").append(barcode()).nl(); |
| 236 |
bb.append("chastity:\t").append(chastityCode()).nl(); |
| 237 |
return bb.toString(); |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
String id; |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
public static boolean PARSE_COORDINATES=true; |
| 257 |
|
| 258 |
public static boolean PARSE_COMMENT=false; |
| 259 |
|
| 260 |
} |