11package au .edu .qimr .qannotate .modes ;
22
3- import static org .junit .Assert .assertEquals ;
4- import static org .junit .Assert .assertTrue ;
5- import static org .junit .Assert .fail ;
6-
73import java .io .BufferedWriter ;
84import java .io .File ;
95import java .io .FileWriter ;
2117
2218import au .edu .qimr .qannotate .Main ;
2319
20+ import static org .junit .Assert .*;
21+
2422public class IndelConfidenceModeTest {
2523 public static String dbMask = "repeat.mask" ;
2624 public static String input = "input.vcf" ;
@@ -37,71 +35,79 @@ public void clear(){
3735 }
3836
3937 @ Test
40- public void InfoTest (){
38+ public void infoTest (){
4139
4240 IndelConfidenceMode mode = new IndelConfidenceMode ();
4341
4442 String str = "chr1 11303744 . C CA 37.73 PASS SOMATIC;HOM=5,AGCCTGTCTCaAAAAAAAAAA;NIOC=0.087;SVTYPE=INS;END=11303745 GT:AD:DP:GQ:PL:ACINDEL .:.:.:.:.:0,39,36,0[0,0],0,4,4 0/1:30,10:40:75:75,0,541:7,80,66,8[4,4],1,7,8" ;
4543// String str = "chr1 11303744 . C CA 37.73 HOM5 SOMATIC;HOMTXT=AGCCTGTCTCaAAAAAAAAAA;NIOC=0.087;SVTYPE=INS;END=11303745 GT:AD:DP:GQ:PL:ACINDEL .:.:.:.:.:0,39,36,0[0,0],0,4,4 0/1:30,10:40:75:75,0,541:7,80,66,8[4,4],1,7,8";
4644
4745 VcfRecord vcf = new VcfRecord (str .split ("\\ t" ));
48- assertTrue ( mode .getConfidence (vcf ) == MafConfidence . HIGH );
46+ assertSame ( MafConfidence . HIGH , mode .getConfidence (vcf ));
4947
5048 //HOMCNTXT is no longer checked
5149 vcf .setInfo ("SOMATIC;HOMCNTXT=9,AGCCTGTCTCaAAAAAAAAAA;SVTYPE=INS;END=11303745" );
52- assertTrue ( mode .getConfidence (vcf ) == MafConfidence . HIGH );
53- vcf .setInfo ("SOMATIC;HOM=9,AGCCTGTCTCaAAAAAAAAAA;SVTYPE=INS;END=11303745" );
54- assertTrue ( mode .getConfidence (vcf ) == MafConfidence . LOW );
50+ assertSame ( MafConfidence . HIGH , mode .getConfidence (vcf ));
51+ vcf .setInfo ("SOMATIC;HOM=9,AGCCTGTCTCaAAAAAAAAAA;SVTYPE=INS;END=11303745" );
52+ assertSame ( MafConfidence . LOW , mode .getConfidence (vcf ));
5553
5654
5755 //no homopolymers (repeat)
5856 vcf = new VcfRecord (str .split ("\\ t" ));
5957 vcf .setInfo ("SOMATIC;NIOC=0.087;SVTYPE=INS;END=11303745" );
60- assertTrue ( mode .getConfidence (vcf ) == MafConfidence . HIGH );
58+ assertSame ( MafConfidence . HIGH , mode .getConfidence (vcf ));
6159
6260 //somatic SSOI
6361 vcf .setInfo ("SOMATIC;NIOC=0.087;SSOI=0.1;SVTYPE=INS;END=11303745" );
64- assertTrue ( mode .getConfidence (vcf ) == MafConfidence . HIGH );
62+ assertSame ( MafConfidence . HIGH , mode .getConfidence (vcf ));
6563
6664 //germline SSOI high
6765 vcf .setInfo ("NIOC=0.087;SSOI=0.2;SVTYPE=INS;END=11303745" );
68- assertTrue ( mode .getConfidence (vcf ) == MafConfidence . HIGH );
66+ assertSame ( MafConfidence . HIGH , mode .getConfidence (vcf ));
6967
7068 //germline SSOI low
7169 vcf .setInfo ("NIOC=0.087;SSOI=0.1;SVTYPE=INS;END=11303745" );
72- assertTrue ( mode .getConfidence (vcf ) == MafConfidence . LOW );
70+ assertSame ( MafConfidence . LOW , mode .getConfidence (vcf ));
7371
7472 //9 base repeat
7573 //vcf.setFilter(IndelUtils.FILTER_HOM + "9");
7674 vcf .setInfo ("SOMATIC;HOM=9,AGCCTGTCTCaAAAAAAAAAA;NIOC=0.087;SVTYPE=INS;END=11303745" );
77- assertTrue ( mode .getConfidence (vcf ) == MafConfidence . LOW );
75+ assertSame ( MafConfidence . LOW , mode .getConfidence (vcf ));
7876
7977 //no repeat but too many nearby indel
8078 vcf .setInfo ("SOMATIC;HOM=5,AGCCTGTCTCaAAAAAAAAAA;NIOC=0.187;SVTYPE=INS;END=11303745" );
81- assertTrue ( mode .getConfidence (vcf ) == MafConfidence . LOW );
79+ assertSame ( MafConfidence . LOW , mode .getConfidence (vcf ));
8280
8381
8482 //vcf.setFilter(IndelUtils.FILTER_HOM + "3" );
8583 vcf .setInfo ("SOMATIC;HOM=3,AGCCTGTCTCaAAAAAAAAAA;NIOC=0.087;SVTYPE=INS;END=11303745" );
86- assertTrue ( mode .getConfidence (vcf ) == MafConfidence . HIGH );
84+ assertSame ( MafConfidence . HIGH , mode .getConfidence (vcf ));
8785
8886 vcf .setFilter (IndelUtils .FILTER_MIN );
89- assertTrue ( mode .getConfidence (vcf ) == MafConfidence . LOW );
87+ assertSame ( MafConfidence . LOW , mode .getConfidence (vcf ));
9088
9189 }
9290
9391
9492 @ Test
95- public void confidenceRealLifeIndel () throws Exception {
93+ public void confidenceRealLifeIndel () {
9694 //chr2 29432822 . C CGCGAATT . HCOVT AC=2;AF=1.00;AN=2;DP=1174;FS=0.000;MLEAC=2;MLEAF=1.00;MQ=59.98;QD=7.19;SOR=11.114;HOM=0,GGATTTTATCgcgaattTCCAAGCTGA;CONF=ZERO GT:GD:AD:DP:GQ:PL .:.:.:.:.:. 1/1:CGCGAATT/CGCGAATT:0,258:258:99:8481,606,0
9795 VcfRecord vcf1 = new VcfRecord (new String []{"chr2" ,"29432822" ,"." ,"C" ,"CGCGAATT" ,"." ,"HCOVT" ,"AC=2;AF=1.00;AN=2;DP=1174;FS=0.000;MLEAC=2;MLEAF=1.00;MQ=59.98;QD=7.19;SOR=11.114;HOM=0,GGATTTTATCgcgaattTCCAAGCTGA" ,"GT:GD:AD:DP:GQ:PL" ," .:.:.:.:.:." ,"1/1:CGCGAATT/CGCGAATT:0,258:258:99:8481,606,0" });
9896
99- IndelConfidenceMode cm =new IndelConfidenceMode ();
100- assertTrue ( cm .getConfidence (vcf1 ) == MafConfidence . ZERO );
97+ IndelConfidenceMode cm = new IndelConfidenceMode ();
98+ assertSame ( MafConfidence . ZERO , cm .getConfidence (vcf1 ));
10199 }
100+ @ Test
101+ public void confidenceRealLifeIndel2 () {
102+ //chr2 29432822 . C CGCGAATT . HCOVT AC=2;AF=1.00;AN=2;DP=1174;FS=0.000;MLEAC=2;MLEAF=1.00;MQ=59.98;QD=7.19;SOR=11.114;HOM=0,GGATTTTATCgcgaattTCCAAGCTGA;CONF=ZERO GT:GD:AD:DP:GQ:PL .:.:.:.:.:. 1/1:CGCGAATT/CGCGAATT:0,258:258:99:8481,606,0
103+ VcfRecord vcf1 = new VcfRecord (new String []{"chr2" ,"29432822" ,"." ,"C" ,"CGCGAATT" ,"." ,"HCOVT" ,"AC=2;AF=1.00;AN=2;DP=1174;FS=0.000;MLEAC=2;MLEAF=1.00;MQ=59.98;QD=7.19;SOR=11.114;HOM=0,GGATTTTATCgcgaattTCCAAGCTGA" ,"GT:GD:AD:DP:GQ:PL" ," .:.:.:.:.:." ,"1/1:CGCGAATT/CGCGAATT:0,258:258:99:8481,606,0" });
104+
105+ IndelConfidenceMode cm = new IndelConfidenceMode ();
106+ assertSame (MafConfidence .ZERO , cm .getConfidence (vcf1 ));
107+ }
102108
103109 @ Test
104- public void MaskTest () throws Exception {
110+ public void maskTest () {
105111
106112 try {
107113 createMask ();
@@ -118,44 +124,87 @@ public void MaskTest() throws Exception{
118124 i ++;
119125 if (i == 1 )
120126 //chr1 53741 . CTT C
121- assertTrue ( re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ). equals ( MafConfidence .HIGH .name ()));
127+ assertEquals ( re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ), MafConfidence .HIGH .name ());
122128 else if (i == 2 )
123129 //chr1 53742 . C CA
124- assertTrue ( re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ). equals ( MafConfidence .HIGH .name ()));
130+ assertEquals ( re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ), MafConfidence .HIGH .name ());
125131 else if (i == 3 )
126132 //chr1 53742 . CTT C
127- assertTrue ( re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ). equals ( MafConfidence .ZERO .name ()));
133+ assertEquals ( re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ), MafConfidence .ZERO .name ());
128134 else if (i == 4 )
129135 //chr1 53743 . C CA
130136 //the insertion happened bwt 53743 and 53744, so it is before repeat region
131- assertTrue ( re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ). equals ( MafConfidence .HIGH .name ()));
137+ assertEquals ( re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ), MafConfidence .HIGH .name ());
132138 else if (i == 5 )
133139 //chr1 53744 . CTT C
134- assertTrue ( re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ). equals ( MafConfidence .ZERO .name ()));
140+ assertEquals ( re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ), MafConfidence .ZERO .name ());
135141 }
136142 assertEquals (5 , i );
137143 }
138144
139- }catch (Exception e ){
145+ } catch (Exception e ){
140146 System .out .println (e .getMessage ());
141-
142- fail ( "My method throw expection" );
147+ fail ( "My method threw an exception" );
143148 }
144149
145150 }
151+
152+ @ Test
153+ public void homopolymerOptionTest () {
154+ try {
155+ createMask ();
156+ createHomVcf ();
157+
158+ String [] args ={"--mode" ,"IndelConfidence" , "-i" , new File (input ).getAbsolutePath (), "-o" , new File (output ).getAbsolutePath (),
159+ "-d" , new File (dbMask ).getAbsolutePath (), "--log" , new File (log ).getAbsolutePath ()};
160+ Main .main (args );
161+
162+ try (VcfFileReader reader = new VcfFileReader (new File (output ))) {
163+ int i = 0 ;
164+ for ( VcfRecord re : reader ) {
165+ if (++i == 1 ) {
166+ assertEquals (MafConfidence .LOW .name (), re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ));
167+ } else if (i == 2 ) {
168+ assertEquals (MafConfidence .HIGH .name (), re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ));
169+ }
170+ }
171+ assertEquals (2 , i );
172+ }
173+
174+ args = new String []{"--mode" , "IndelConfidence" , "-i" , new File (input ).getAbsolutePath (), "-o" , new File (output ).getAbsolutePath (),
175+ "-d" , new File (dbMask ).getAbsolutePath (), "--log" , new File (log ).getAbsolutePath (), "--homCutoff" , "8" };
176+ Main .main (args );
177+
178+ try (VcfFileReader reader = new VcfFileReader (new File (output ))) {
179+ int i = 0 ;
180+ for ( VcfRecord re : reader ) {
181+ if (++i == 1 ) {
182+ assertEquals (MafConfidence .HIGH .name (), re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ));
183+ } else if (i == 2 ) {
184+ assertEquals (MafConfidence .HIGH .name (), re .getInfoRecord ().getField (VcfHeaderUtils .INFO_CONFIDENCE ));
185+ }
186+ }
187+ assertEquals (2 , i );
188+ }
189+
190+ } catch (Exception e ){
191+ System .out .println (e .getMessage ());
192+ fail ( "My method threw an exception" );
193+ }
194+ }
146195
147196 public static void createMask () throws IOException {
148- final List <String > data = new ArrayList <String >();
197+ final List <String > data = new ArrayList <>();
149198 data .add ("genoName genoStart genoEnd repClass repFamily" );
150199 data .add ("1 53744 53780 Low_complexity Low_complexity" );
151200 data .add ("chr1 54712 54820 Simple_repeat Simple_repeat" );
152- try (BufferedWriter out = new BufferedWriter (new FileWriter (dbMask )); ) {
201+ try (BufferedWriter out = new BufferedWriter (new FileWriter (dbMask ))) {
153202 for (final String line : data ) out .write (line +"\n " );
154203 }
155204 }
156205
157206 public static void createVcf () throws IOException {
158- final List <String > data = new ArrayList <String >();
207+ final List <String > data = new ArrayList <>();
159208 data .add ("##fileformat=VCFv4.0" );
160209 data .add (VcfHeaderUtils .STANDARD_UUID_LINE + "=abcd_12345678_xzy_999666333" );
161210 data .add ("#CHROM\t POS\t ID\t REF\t ALT\t QUAL\t FILTER\t INFO" );
@@ -166,9 +215,21 @@ public static void createVcf() throws IOException{
166215 data .add ("chr1 53743 . C CA 37.73 PASS SOMATIC;HOMCNTXT=5,AGCCTGTCTCaAAAAAAAAAA;NIOC=0.087" );
167216 data .add ("chr1 53744 . CTT C 37.73 PASS SOMATIC;HOMCNTXT=5,AGCCTGTCTCaAAAAAAAAAA;NIOC=0.087" );
168217
169- try (BufferedWriter out = new BufferedWriter (new FileWriter (input )); ) {
218+ try (BufferedWriter out = new BufferedWriter (new FileWriter (input ))) {
170219 for (final String line : data ) out .write (line +"\n " );
171220 }
172221
173222 }
223+ public static void createHomVcf () throws IOException {
224+ final List <String > data = new ArrayList <>();
225+ data .add ("##fileformat=VCFv4.0" );
226+ data .add (VcfHeaderUtils .STANDARD_UUID_LINE + "=abcd_12345678_xzy_999666333" );
227+ data .add ("#CHROM\t POS\t ID\t REF\t ALT\t QUAL\t FILTER\t INFO\t FORMAT\t 29ab944c-f37f-4531-95ac-57c52c53be6f\t 78ab1438-d237-4cff-a76a-835320a5fb0f" );
228+ data .add ("chr1\t 897580\t rs397863599\t AT\t A\t 404.73\t PASS\t BaseQRankSum=1.304;ClippingRankSum=0.000;DP=50;ExcessHet=3.0103;FS=2.463;MQ=60.00;MQRankSum=0.000;QD=8.26;ReadPosRankSum=-0.193;SOR=0.751;NIOC=0;SSOI=0.286;SVTYPE=DEL;END=897581;IN=1;VLD;DB;VAF=0.696;HOM=8,GACTCACTGA_TTTTTTTCTA\t GT:AD:DP:G;D:GQ:PL:ACINDEL\t 0/1:29,20:49:AT/A:99:442,0,732:14,50,49,14[7,7],18[18],0,0,1\t 0/1:10,51:61:AT/A:99:1367,0,121:43,61,61,48[21,27],48[43],0,0,1" );
229+ data .add ("chr1\t 1303675\t rs60404130\t C\t CCCT\t 1037.73\t PASS\t BaseQRankSum=1.750;ClippingRankSum=0.000;DP=44;ExcessHet=3.0103;FS=13.869;MQ=59.81;MQRankSum=0.000;QD=30.90;ReadPosRankSum=2.125;SOR=1.634;NIOC=0.030;SSOI=0.758;SVTYPE=INS;END=1303676;IN=1;VLD;DB;VAF=0.86;HOM=5,CCTGTTGCCCcctCCTCTTTCTC\t GT:AD:DP:GD:GQ:PL:ACINDEL\t 1/1:3,24:27:CCCT/CCCT:72:1075,72,0:23,33,33,25[6,19],28[25],0,1,2\t 1/1:5,17:22:CCCT/CCCT:23:537,23,0:18,34,33,18[10,8],21[21],1,1,4" );
230+ try (BufferedWriter out = new BufferedWriter (new FileWriter (input ))) {
231+ for (final String line : data ) out .write (line +"\n " );
232+ }
233+
234+ }
174235}
0 commit comments