Added automatic sample name replacement
Some checks failed
ydeng/modvcfsamples/pipeline/head There was a failure building this commit

This commit is contained in:
2023-06-28 05:51:52 +00:00
parent 02f52560eb
commit 2d1d69f95f
3 changed files with 121 additions and 25 deletions

View File

@@ -2,6 +2,7 @@ from modvcfsamples.sample import (
keep_specific_call_data,
get_records_from_vcf,
normalize_gt_to_length,
replace_sample_names,
)
import os
@@ -32,7 +33,7 @@ def test_normalize_gt_to_length_not_empty():
records, header = get_records_from_vcf(
os.path.abspath("tests/resources/test_files_shortened_haploid.vcf")
)
modified_records, _ = normalize_gt_to_length(records, header, 4)
modified_records = normalize_gt_to_length(records, 4)
assert len(modified_records) > 0
@@ -40,7 +41,37 @@ def test_normalize_gt_to_length_gt_normalized():
records, header = get_records_from_vcf(
os.path.abspath("tests/resources/test_files_shortened_haploid.vcf")
)
modified_records, _ = normalize_gt_to_length(records, header, 4)
modified_records = normalize_gt_to_length(records, 4)
for modified_record in modified_records:
for call in modified_record.calls:
assert len(call.data["GT"].split("|")) == 4 or "/" in call.data["GT"]
def test_replace_sample_names_record_modified_correctly():
records, header = get_records_from_vcf(
os.path.abspath("tests/resources/test_files_shortened_haploid.vcf")
)
modified_records, modified_headers = replace_sample_names(records, header, "Gambian", "different")
for modified_record in modified_records:
call_name_replaced = False
for call in modified_record.calls:
assert call.sample != "Gambian"
if call.sample == "different":
call_name_replaced = True
assert call_name_replaced
def test_replace_sample_names_header_modified_correctly():
records, header = get_records_from_vcf(
os.path.abspath("tests/resources/test_files_shortened_haploid.vcf")
)
modified_records, modified_headers = replace_sample_names(records, header, "Gambian", "different")
replaced_found = False
original_found = False
for name in modified_headers.samples.names:
if name == "Gambian":
original_found = True
if name == "different":
replaced_found = True
assert replaced_found
assert not original_found