Debian Codegraph @

current/hiseq/BGIHeaderParser2.java

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