Skip to content

Commit 5609138

Browse files
Merge pull request #19 from sanogenetics/hotfix/grch-build-detection
Fix and expand grch build detection
2 parents a2bb642 + e7e018b commit 5609138

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/snps/io/reader.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,10 @@ def _detect_build_from_comments(self, comments):
253253
return 37
254254
elif "hg38" in comments.lower():
255255
return 38
256-
elif "GRCh38" in comments.lower():
256+
elif "grch38" in comments.lower():
257257
return 38
258+
elif "grch37" in comments.lower():
259+
return 37
258260
elif "build 38" in comments.lower():
259261
return 38
260262
elif "b38" in comments.lower():

tests/io/test_writer.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,23 @@ class TestWriter(BaseSNPsTestCase):
4444
def test_save_snps(self):
4545
snps = SNPs("tests/input/generic.csv")
4646
self.assertEqual(os.path.relpath(snps.save_snps()), "output/generic_GRCh37.csv")
47-
self.run_parsing_tests("output/generic_GRCh37.csv", "generic")
47+
self.run_parsing_tests(
48+
"output/generic_GRCh37.csv",
49+
"generic",
50+
build_detected=True, # build will be detected from comments because save_snps() writes the build into comments
51+
)
4852

4953
def test_save_snps_tsv(self):
5054
snps = SNPs("tests/input/generic.csv")
5155
self.assertEqual(
5256
os.path.relpath(snps.save_snps("generic.tsv", sep="\t")),
5357
"output/generic.tsv",
5458
)
55-
self.run_parsing_tests("output/generic.tsv", "generic")
59+
self.run_parsing_tests(
60+
"output/generic.tsv",
61+
"generic",
62+
build_detected=True, # build will be detected from comments because save_snps() writes the build into comments
63+
)
5664

5765
def test_save_snps_vcf(self):
5866
s = SNPs("tests/input/testvcf.vcf")
@@ -104,9 +112,17 @@ def test_save_snps_csv_phased(self):
104112
# save phased data to CSV
105113
self.assertEqual(os.path.relpath(s.save_snps()), "output/vcf_GRCh37.csv")
106114
# read saved CSV
107-
self.run_parsing_tests_vcf("output/vcf_GRCh37.csv", phased=True)
115+
self.run_parsing_tests_vcf(
116+
"output/vcf_GRCh37.csv",
117+
phased=True,
118+
build_detected=True, # build will be detected from comments because save_snps() writes the build into comments
119+
)
108120

109121
def test_save_snps_specify_file(self):
110122
s = SNPs("tests/input/generic.csv")
111123
self.assertEqual(os.path.relpath(s.save_snps("snps.csv")), "output/snps.csv")
112-
self.run_parsing_tests("output/snps.csv", "generic")
124+
self.run_parsing_tests(
125+
"output/snps.csv",
126+
"generic",
127+
build_detected=True, # build will be detected from comments because save_snps() writes the build into comments
128+
)

0 commit comments

Comments
 (0)