Permalink
Browse files

Cleaned up boilerplate in 'Biocaml_vcf' test suite

  • Loading branch information...
1 parent 807e7d1 commit bfe73e71b1109c7ac20cd353e15184b9bf909a93 @superbobry superbobry committed Mar 5, 2013
Showing with 33 additions and 59 deletions.
  1. +0 −15 src/tests/data/vcf_05_alt.vcf
  2. +33 −44 src/tests/test_vcf.ml
@@ -12,22 +12,7 @@
##INFO=<ID=MEINFO,Number=4,Type=String,Description="Mobile element info of the form NAME,START,END,POLARITY">
##INFO=<ID=SVLEN,Number=.,Type=Integer,Description="Difference in length between REF and ALT alleles">
##INFO=<ID=SVTYPE,Number=1,Type=String,Description="Type of structural variant">
-##ALT=<ID=DEL,Description="Deletion">
##ALT=<ID=DEL:ME:ALU,Description="Deletion of ALU element">
-##ALT=<ID=DEL:ME:L1,Description="Deletion of L1 element">
-##ALT=<ID=DUP,Description="Duplication">
-##ALT=<ID=DUP:TANDEM,Description="Tandem Duplication">
-##ALT=<ID=INS,Description="Insertion of novel sequence">
-##ALT=<ID=INS:ME:ALU,Description="Insertion of ALU element">
-##ALT=<ID=INS:ME:L1,Description="Insertion of L1 element">
-##ALT=<ID=INV,Description="Inversion">
-##ALT=<ID=CNV,Description="Copy number variable region">
-##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
-##FORMAT=<ID=GQ,Number=1,Type=Float,Description="Genotype quality">
-##FORMAT=<ID=CN,Number=1,Type=Integer,Description="Copy number genotype for imprecise events">
-##FORMAT=<ID=CNQ,Number=1,Type=Float,Description="Copy number genotype quality for imprecise events">
#CHROM POS ID REF ALT QUAL FILTER INFO
2 321682 . T <DEL> 6 PASS IMPRECISE;SVTYPE=DEL;END=321887;SVLEN=-105;CIPOS=-56,20;CIEND=-10,62
2 14477084 . C <DEL:ME:ALU> 12 PASS IMPRECISE;SVTYPE=DEL;END=14477381;SVLEN=-297;MEINFO=AluYa5,5,307,+;CIPOS=-22,18;CIEND=-12,32
-3 9425916 . C <INS:ME:L1> 23 PASS IMPRECISE;SVTYPE=INS;END=9425916;SVLEN=6027;CIPOS=-16,22;MEINFO=L1HS,1,6025,-
-3 12665100 . A <DUP> 14 PASS IMPRECISE;SVTYPE=DUP;
View
@@ -34,6 +34,19 @@ let make_row ~chrom ~pos ~ids ~ref ~alts ~qual ~filter ~info =
vcfr_info
}
+let test_parse_vcf_generic filename rows =
+ let s = make_stream filename in
+ List.iter rows ~f:(fun row ->
+ match Stream.next s with
+ | Some (Ok actual_row) ->
+ assert_equal ~cmp:compare_rows row actual_row
+ | Some (Error err) ->
+ let msg = Vcf.parse_error_to_string err in
+ assert_bool
+ (sprintf "%s:row *not* parsed, reason: %s" filename msg)
+ false
+ | None -> assert_bool (sprintf "%s:row missing" filename) false)
+
let test_parse_vcf_header () =
let s = make_stream "vcf_01_header_only.vcf" in
match Stream.next s with
@@ -44,27 +57,19 @@ let test_parse_vcf_header () =
assert_bool (Printf.sprintf "test_parse_vcf_header, reason: %s" msg) false
let test_parse_vcf_simple () =
- let s = make_stream "vcf_02_simple.vcf" in
- let row = make_row ~chrom:"20" ~pos:14370 ~ids:["rs6054257"]
+ test_parse_vcf_generic "vcf_02_simple.vcf" [
+ make_row ~chrom:"20" ~pos:14370 ~ids:["rs6054257"]
~ref:"G" ~alts:["A"]
~qual:(Some 29.0) ~filter:[]
~info:[("NS", [`integer 3]);
("DP", [`integer 14]);
("AF", [`float 0.5]);
("DB", [`flag "DB"]);
("H2", [`flag "H2"])]
- in match Stream.next s with
- | Some (Ok actual_row) -> assert_equal ~cmp:compare_rows actual_row row
- | Some (Error err) ->
- let msg = Vcf.parse_error_to_string err in
- assert_bool
- (Printf.sprintf "test_parse_vcf_simple:row *not* parsed, reason: %s" msg)
- false
- | None -> assert_bool "test_parse_vcf_simple:row missing" false
+ ]
let test_parse_vcf_1000g () =
- let s = make_stream "vcf_03_1000g.vcf" in
- let rows = [
+ test_parse_vcf_generic "vcf_03_1000g.vcf" [
make_row ~chrom:"20" ~pos:17330 ~ids:[]
~ref:"T" ~alts:["A"]
~qual:(Some 3.0) ~filter:["q10"]
@@ -91,39 +96,22 @@ let test_parse_vcf_1000g () =
~info:[("NS", [`integer 3]);
("DP", [`integer 9]);
("AA", [`string "G"])]
- ] in List.iter rows ~f:(fun row ->
- match Stream.next s with
- | Some (Ok actual_row) ->
- assert_equal ~cmp:compare_rows row actual_row
- | Some (Error err) ->
- let msg = Vcf.parse_error_to_string err in
- assert_bool
- (Printf.sprintf "test_parse_vcf_1000g:row *not* parsed, reason: %s" msg)
- false
- | None -> assert_bool "test_parse_vcf_1000g:row missing" false)
+ ]
let test_parse_vcf_reserved () =
- let s = make_stream "vcf_04_reserved.vcf" in
- let row = make_row ~chrom:"20" ~pos:14370 ~ids:["rs6054257"]
+ test_parse_vcf_generic "vcf_04_reserved.vcf" [
+ make_row ~chrom:"20" ~pos:14370 ~ids:["rs6054257"]
~ref:"G" ~alts:["A"]
~qual:(Some 29.0) ~filter:[]
~info:[("NS", [`integer 3]);
("DP", [`integer 14]);
("AF", [`float 0.5]);
("DB", [`flag "DB"]);
("H2", [`flag "H2"])]
- in match Stream.next s with
- | Some (Ok actual_row) -> assert_equal ~cmp:compare_rows actual_row row
- | Some (Error err) ->
- let msg = Vcf.parse_error_to_string err in
- assert_bool
- (Printf.sprintf "test_parse_vcf_reserved:row *not* parsed, reason: %s" msg)
- false
- | None -> assert_bool "test_parse_vcf_reserved:row missing" false
+ ]
let test_parse_vcf_alt () =
- let s = make_stream "vcf_05_alt.vcf" in
- let rows = [
+ test_parse_vcf_generic "vcf_05_alt.vcf" [
make_row ~chrom:"2" ~pos:321682 ~ids:[]
~ref:"T" ~alts:["<DEL>"]
~qual:(Some 6.0) ~filter:[]
@@ -133,16 +121,17 @@ let test_parse_vcf_alt () =
("SVLEN", [`integer (-105)]);
("CIPOS", [`integer (-56); `integer 20]);
("CIEND", [`integer (-10); `integer 62])];
- ] in List.iter rows ~f:(fun row ->
- match Stream.next s with
- | Some (Ok actual_row) ->
- assert_equal ~cmp:compare_rows row actual_row
- | Some (Error err) ->
- let msg = Vcf.parse_error_to_string err in
- assert_bool
- (Printf.sprintf "test_parse_vcf_alt:row *not* parsed, reason: %s" msg)
- false
- | None -> assert_bool "test_parse_vcf_alt:row missing" false)
+ make_row ~chrom:"2" ~pos:14477084 ~ids:[]
+ ~ref:"C" ~alts:["<DEL:ME:ALU>"]
+ ~qual:(Some 12.0) ~filter:[]
+ ~info:[("IMPRECISE", [`flag "IMPRECISE"]);
+ ("SVTYPE", [`string "DEL"]);
+ ("END", [`integer 14477381]);
+ ("SVLEN", [`integer (-297)]);
+ ("MEINFO", [`string "AluYa5"; `string "5"; `string "307"; `string "+"]);
+ ("CIPOS", [`integer (-22); `integer 18]);
+ ("CIEND", [`integer (-12); `integer 32])]
+ ]
let tests = "VCF" >::: [
"Parse VCF header" >:: test_parse_vcf_header;

0 comments on commit bfe73e7

Please sign in to comment.