1 2 3 4 5 6 7 8 9 10 11 12 13 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
package hiseq;
import shared.LineParserS4Reverse;
import structures.ByteBuilder;
/**
* Uses a reverse parser because BGI headers have an unknown prefix.
* As a result, it does not support comments, but this could be preprocessed.
* @author Brian Bushnell
* @date May 6, 2024
*
*/
public class BGIHeaderParser2 extends ReadHeaderParser {
/*--------------------------------------------------------------*/
/*---------------- Main ----------------*/
/*--------------------------------------------------------------*/
public static void main(String[] args) {
BGIHeaderParser2 ihp=new BGIHeaderParser2();
ihp.test(args.length>0 ? args[0] : null);
ihp.parse(args[0]);
System.err.println("toIllumina: "+ihp.toIllumina("ACGTACGT"));
}
/*--------------------------------------------------------------*/
/*---------------- Expected Format ----------------*/
/*--------------------------------------------------------------*/
//v300056266_run28L3C001R0010057888/1
//20A_V100002704L1C001R012000000/1
//E200008112L1C001R00100063962/1
//split: [v300056266, run28, 3, 001, 0010057888, 1]
/*--------------------------------------------------------------*/
/*---------------- Public Methods ----------------*/
/*--------------------------------------------------------------*/
public BGIHeaderParser2 parse(String id_) {
id=id_;
extra=null;
if(PARSE_EXTRA) {//Handles comments, but it's slow
int idx=firstWhitespace(id);
if(idx>=0) {
extra=id.substring(idx+1);
id=id.substring(0, idx);
}
}
lp.set(id);
return this;
}
private static int firstWhitespace(String s) {
for(int i=0; i<s.length(); i++) {
if(Character.isWhitespace(s.charAt(i))){
return i;
}
}
return -1;
}
//@LH00223:28:22GLGMLT3:1:1101:5928:1016 1:N:0:CTGCTTGGTT+CTAACGACAG (NovaseqX)
public String toIllumina(String barcode) {
bb.clear();
bb.append(machine()).colon();
bb.append(run()).colon();
bb.append(flowcell()).colon();
bb.append(lane()).colon();
bb.append(tile()).colon();
bb.append(xPos()).colon();
bb.append(yPos()).space();
bb.append(pairCode()).colon();
bb.append('N').colon();
bb.append(controlBits()).colon();
if(barcode!=null) {bb.append(barcode);}
String ex=extra();
if(ex!=null) {bb.tab().append(ex);}
return bb.toString();
}
@Override
public String sample() {
String s=lp.terms()<=1 ? null : lp.parseString(1);
return s!=null ? s : "SA";
}
@Override
public String machine() {
return "CG";//Complete Genomics
}
@Override
public int run() {
return 0;
}
@Override
public String flowcell() {
String s=lp.terms()<=0 ? null : lp.parseString(0);
// String s=lp.terms()<=1 ? null : lp.parseString(1);
return s!=null ? s : "FC";
}
@Override
public int lane() {return lp.parseInt(2);}
@Override
public int tile() {return lp.parseInt(4, 3, 10);}
@Override
public int xPos() {return lp.parseInt(3);}
@Override
public int yPos() {return lp.parseInt(4, 0, 3);}
@Override
public char pairCode() {return lp.parseChar(5, 0);}
@Override
public char chastityCode() {return 'N';}
@Override
public int controlBits() {return 0;}
@Override
public String barcode() {
return null;
}
@Override
public String extra() {
// return lp.terms()<=6 ? null : lp.parseString(6);
return extra;
}
/*--------------------------------------------------------------*/
/*---------------- Private Fields ----------------*/
/*--------------------------------------------------------------*/
private String extra=null;
private final LineParserS4Reverse lp=new LineParserS4Reverse("_LCR/");
private final ByteBuilder bb=new ByteBuilder(64);
/*--------------------------------------------------------------*/
/*---------------- Static Fields ----------------*/
/*--------------------------------------------------------------*/
public static boolean PARSE_EXTRA=false;
}
|