Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions trtools/mergeSTR/tests/test_mergeSTR.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import argparse
import os
import shutil
import argparse
import subprocess

import cyvcf2
import numpy as np
import pytest
import numpy as np

from ..mergeSTR import *
from trtools.testsupport.utils import assert_same_vcf
Expand Down Expand Up @@ -372,6 +374,39 @@ def test_popstr_output(args, mrgvcfdir):
assert main(args) == 0
assert_same_vcf(args.out + '.vcf', mrgvcfdir + "/popstr_merged.vcf")

def test_mergeSTR_recursion(args, mrgvcfdir, tmpdir):
# Test that mergeSTR will accept its own output as input
# Create a merged VCF and then merge it again with a different file

if shutil.which("bgzip") is not None and shutil.which("tabix") is not None:
# First, merge two files of 10 and 19 samples, respectively
fname1 = os.path.join(mrgvcfdir, "CEU_test_subset10.vcf.gz")
fname2 = os.path.join(mrgvcfdir, "CEU_test_subset19.vcf.gz")
args.vcftype = "hipstr"
merged = str(tmpdir / "test-CEU-subset1")
args.out = merged
args.vcfs = fname1 + "," + fname2
args.vcfs_list = None
assert main(args)==0
subprocess.run(["bgzip", merged + ".vcf"])
subprocess.run(["tabix", "-p", "vcf", merged + ".vcf.gz"])
else:
merged = str(mrgvcfdir / "test-CEU-subset1")

# Now, merge the output of mergeSTR with another file of 150 samples
fname1 = merged + ".vcf.gz"
fname2 = os.path.join(mrgvcfdir, "CEU_test_subset150.vcf.gz")
args.vcftype = "hipstr"
merged = str(tmpdir / "test-CEU-subset2")
args.out = merged
args.vcfs = fname1 + "," + fname2
args.vcfs_list = None
assert main(args)==0

# The subsetted files were created by subsetting CEU_test.vcf.gz, so they should end up the same
# { zcat CEU_test.vcf.gz | head -n-3 && zcat CEU_test.vcf.gz | cut -f -9,10-19; } | bgzip > CEU_test_subset10.vcf.gz
assert_same_vcf(args.out + '.vcf', mrgvcfdir + "/CEU_test.vcf")


# TODO questions and issues to confirm, test or address:
# confirm conflicting samples cause this to fail unless --update-sample-from-file is given
Expand Down
3,420 changes: 3,420 additions & 0 deletions trtools/testsupport/sample_vcfs/mergeSTR_vcfs/CEU_test.vcf

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.