From bfa499ca7f69ea6503d59d057f53880ef95ef838 Mon Sep 17 00:00:00 2001 From: Max Zhao Date: Fri, 15 Sep 2023 18:14:29 +0200 Subject: [PATCH 1/5] Adding offending data --- tests/data/annotate/vars/badly_formed_vcf_entry.vcf | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/data/annotate/vars/badly_formed_vcf_entry.vcf diff --git a/tests/data/annotate/vars/badly_formed_vcf_entry.vcf b/tests/data/annotate/vars/badly_formed_vcf_entry.vcf new file mode 100644 index 00000000..9b3d43ba --- /dev/null +++ b/tests/data/annotate/vars/badly_formed_vcf_entry.vcf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cf0554626056c285623cbbd3c3d374a77144e631d793d0adc21f216682c9e46f +size 9744 From 5b43b1da18e2fc791d76f08a2deddba1dbbf7a2c Mon Sep 17 00:00:00 2001 From: Max Zhao Date: Fri, 15 Sep 2023 18:34:35 +0200 Subject: [PATCH 2/5] Adding failing test --- src/annotate/seqvars/mod.rs | 35 +++++++++++++++++++ .../annotate/vars/badly_formed_vcf_entry.vcf | 3 -- .../data/db/create/badly_formed_vcf_entry.ped | 3 ++ .../data/db/create/badly_formed_vcf_entry.vcf | 3 ++ 4 files changed, 41 insertions(+), 3 deletions(-) delete mode 100644 tests/data/annotate/vars/badly_formed_vcf_entry.vcf create mode 100644 tests/data/db/create/badly_formed_vcf_entry.ped create mode 100644 tests/data/db/create/badly_formed_vcf_entry.vcf diff --git a/src/annotate/seqvars/mod.rs b/src/annotate/seqvars/mod.rs index 40a38e0a..2855469e 100644 --- a/src/annotate/seqvars/mod.rs +++ b/src/annotate/seqvars/mod.rs @@ -1672,4 +1672,39 @@ mod test { Ok(()) } + + #[test] + fn test_badly_formed_vcf_entry() -> Result<(), anyhow::Error> { + let temp = TempDir::default(); + let path_out = temp.join("output.tsv.gz"); + + let args_common = crate::common::Args { + verbose: Verbosity::new(0, 1), + }; + let args = Args { + genome_release: None, + path_db: String::from("tests/data/annotate/db"), + path_input_vcf: String::from( + "tests/data/db/create/badly_formed_vcf_entry.vcf", + ), + output: PathOutput { + path_output_vcf: None, + path_output_tsv: Some(path_out.into_os_string().into_string().unwrap()), + }, + max_var_count: None, + path_input_ped: Some(String::from( + "tests/data/db/create/badly_formed_vcf_entry.ped", + )), + }; + + run(&args_common, &args)?; + + // let actual = std::fs::read_to_string(args.output.path_output_vcf.unwrap())?; + // let expected = std::fs::read_to_string( + // "tests/data/db/create/seqvar_freqs/db-rs1263393206/output.vcf", + // )?; + // assert_eq!(&expected, &actual); + + Ok(()) + } } diff --git a/tests/data/annotate/vars/badly_formed_vcf_entry.vcf b/tests/data/annotate/vars/badly_formed_vcf_entry.vcf deleted file mode 100644 index 9b3d43ba..00000000 --- a/tests/data/annotate/vars/badly_formed_vcf_entry.vcf +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:cf0554626056c285623cbbd3c3d374a77144e631d793d0adc21f216682c9e46f -size 9744 diff --git a/tests/data/db/create/badly_formed_vcf_entry.ped b/tests/data/db/create/badly_formed_vcf_entry.ped new file mode 100644 index 00000000..90d1f727 --- /dev/null +++ b/tests/data/db/create/badly_formed_vcf_entry.ped @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b6a175f650923802a94c81637b8cfec56d0f0147a2c7c3a687dd01820a1d7eba +size 80 diff --git a/tests/data/db/create/badly_formed_vcf_entry.vcf b/tests/data/db/create/badly_formed_vcf_entry.vcf new file mode 100644 index 00000000..2198ae89 --- /dev/null +++ b/tests/data/db/create/badly_formed_vcf_entry.vcf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57e5e636202d9adf6a57088044aa182e53385698f69ac7c678081626713bbe54 +size 9738 From 7560c68e868d65cec471790f9380771d7b680277 Mon Sep 17 00:00:00 2001 From: Max Zhao Date: Fri, 15 Sep 2023 23:36:37 +0200 Subject: [PATCH 3/5] Fixing invalid genotype values --- src/annotate/seqvars/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/annotate/seqvars/mod.rs b/src/annotate/seqvars/mod.rs index 2855469e..8cc49daf 100644 --- a/src/annotate/seqvars/mod.rs +++ b/src/annotate/seqvars/mod.rs @@ -714,10 +714,9 @@ impl VarFishSeqvarTsvWriter { if let Some(gt) = sample .get(&GENOTYPE) .map(|value| match value { - Some(sample::Value::String(s)) => Ok(s.to_owned()), - _ => anyhow::bail!("invalid GT value"), + Some(sample::Value::String(s)) => s.to_owned(), + _ => ".".into() }) - .transpose()? { let individual = self .pedigree From 209724fbd053a3b5b7db9f9d9c118fb8d66702ab Mon Sep 17 00:00:00 2001 From: Max Zhao Date: Fri, 15 Sep 2023 23:38:10 +0200 Subject: [PATCH 4/5] Fmt code --- src/annotate/seqvars/mod.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/annotate/seqvars/mod.rs b/src/annotate/seqvars/mod.rs index 8cc49daf..d89f2c14 100644 --- a/src/annotate/seqvars/mod.rs +++ b/src/annotate/seqvars/mod.rs @@ -711,13 +711,10 @@ impl VarFishSeqvarTsvWriter { ..Default::default() }; - if let Some(gt) = sample - .get(&GENOTYPE) - .map(|value| match value { - Some(sample::Value::String(s)) => s.to_owned(), - _ => ".".into() - }) - { + if let Some(gt) = sample.get(&GENOTYPE).map(|value| match value { + Some(sample::Value::String(s)) => s.to_owned(), + _ => ".".into(), + }) { let individual = self .pedigree .as_ref() @@ -1683,9 +1680,7 @@ mod test { let args = Args { genome_release: None, path_db: String::from("tests/data/annotate/db"), - path_input_vcf: String::from( - "tests/data/db/create/badly_formed_vcf_entry.vcf", - ), + path_input_vcf: String::from("tests/data/db/create/badly_formed_vcf_entry.vcf"), output: PathOutput { path_output_vcf: None, path_output_tsv: Some(path_out.into_os_string().into_string().unwrap()), From 54904496e5c2e4351b461d72e0e2c64a02cf2740 Mon Sep 17 00:00:00 2001 From: Max Zhao Date: Fri, 15 Sep 2023 23:42:21 +0200 Subject: [PATCH 5/5] Adding result check to test --- src/annotate/seqvars/mod.rs | 10 ++++------ tests/data/db/create/badly_formed_vcf_entry.tsv | 3 +++ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 tests/data/db/create/badly_formed_vcf_entry.tsv diff --git a/src/annotate/seqvars/mod.rs b/src/annotate/seqvars/mod.rs index d89f2c14..ed1b05d6 100644 --- a/src/annotate/seqvars/mod.rs +++ b/src/annotate/seqvars/mod.rs @@ -1672,7 +1672,7 @@ mod test { #[test] fn test_badly_formed_vcf_entry() -> Result<(), anyhow::Error> { let temp = TempDir::default(); - let path_out = temp.join("output.tsv.gz"); + let path_out = temp.join("output.tsv"); let args_common = crate::common::Args { verbose: Verbosity::new(0, 1), @@ -1693,11 +1693,9 @@ mod test { run(&args_common, &args)?; - // let actual = std::fs::read_to_string(args.output.path_output_vcf.unwrap())?; - // let expected = std::fs::read_to_string( - // "tests/data/db/create/seqvar_freqs/db-rs1263393206/output.vcf", - // )?; - // assert_eq!(&expected, &actual); + let actual = std::fs::read_to_string(args.output.path_output_tsv.unwrap())?; + let expected = std::fs::read_to_string("tests/data/db/create/badly_formed_vcf_entry.tsv")?; + assert_eq!(&expected, &actual); Ok(()) } diff --git a/tests/data/db/create/badly_formed_vcf_entry.tsv b/tests/data/db/create/badly_formed_vcf_entry.tsv new file mode 100644 index 00000000..e3b6f63a --- /dev/null +++ b/tests/data/db/create/badly_formed_vcf_entry.tsv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8d74185c825c1038bef0ba5ebd5dd2d14d10b3fbafedcd1dcaa8e6224c3ff907 +size 1156