Skip to content

Commit

Permalink
Changed tests to use larger example files, which are required for tes…
Browse files Browse the repository at this point in the history
…ting many functions
  • Loading branch information
aewebb80 committed Aug 8, 2017
1 parent 54703bc commit c9f18f4
Show file tree
Hide file tree
Showing 35 changed files with 12,530 additions and 343 deletions.
65 changes: 40 additions & 25 deletions andrew/andrew_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
import vcf_sampler

# Used to compare two files, returns bool
def compare_to_expected(test_output, expected_output):
def file_comp(test_output, expected_output):
return filecmp.cmp(test_output, expected_output)

# Run tests for the functions within the vcftools module
class vcftools_module_tests (unittest.TestCase):
# Check vcftools input argument assignment function
def test_vcf_argument_parser (self):
# Assign the input argument from the function
input_arg = vcftools.assign_vcftools_input_arg('example/locus8.vcf.gz')
input_arg = vcftools.assign_vcftools_input_arg('example/input/merged_chr1_10000.vcf.gz')
# Confirm the correct argument has been assigned
self.assertEqual(input_arg, ['--gzvcf', 'example/locus8.vcf.gz'])
self.assertEqual(input_arg, ['--gzvcf', 'example/input/merged_chr1_10000.vcf.gz'])

# Check vcftools log output creation
def test_produce_vcftools_log (self):
# Create the log output using the function
vcftools.produce_vcftools_log('Log Test:\n1\n2\n3\n', 'out', 'logTest')
# Confirm the correct log output has been created
self.assertTrue(compare_to_expected('out.logTest.log', 'example/locus8.logTest.log'))
self.assertTrue(file_comp('out.logTest.log', 'example/out.logTest.log'))
# Remove log output file
self.addCleanup(os.remove, 'out.logTest.log')

Expand All @@ -49,10 +49,15 @@ class vcf_calc_tests (unittest.TestCase):
# Check that Fst window function is operating correctly
def test_Fst_window (self):
# Run the function with the following arguments
vcf_calc.run(['example/locus8.vcf.gz', '--calc-statistic', 'windowed-weir-fst', '--pop-file', 'example/Paniscus.txt', '--pop-file', 'example/Troglodytes.txt', '--out', 'out'])
vcf_calc.run(['example/input/merged_chr1_10000.vcf.gz',
'--calc-statistic', 'windowed-weir-fst',
'--pop-file', 'example/input/Paniscus.txt',
'--pop-file', 'example/input/Troglodytes.txt',
'--out', 'out'])

# Confirm that the output is what is expected
self.assertTrue(compare_to_expected('out.windowed.weir.fst', 'example/locus8.windowed.weir.fst'))
self.assertTrue(file_comp('out.windowed.weir.fst',
'example/merged_chr1_10000.windowed.weir.fst'))

# Remove the ouput and log files created by the function
self.addCleanup(os.remove, 'out.windowed.weir.fst')
Expand All @@ -61,10 +66,13 @@ def test_Fst_window (self):
# Check that the Tajima's D function is operating correctly
def test_tajimasD (self):
# Run the function with the following arguments
vcf_calc.run(['example/locus8.vcf.gz', '--calc-statistic', 'TajimaD', '--out', 'out'])
vcf_calc.run(['example/input/merged_chr1_10000.vcf.gz',
'--calc-statistic', 'TajimaD',
'--out', 'out'])

# Confirm that the output is what is expected
self.assertTrue(compare_to_expected('out.Tajima.D', 'example/locus8.Tajima.D'))
self.assertTrue(file_comp('out.Tajima.D',
'example/merged_chr1_10000.Tajima.D'))

# Remove the ouput and log files created by the function
self.addCleanup(os.remove, 'out.Tajima.D')
Expand All @@ -73,10 +81,13 @@ def test_tajimasD (self):
# Check that the window nucleotide diversity function is operating correctly
def test_window_pi (self):
# Run the function with the following arguments
vcf_calc.run(['example/locus8.vcf.gz', '--calc-statistic', 'pi', '--out', 'out'])
vcf_calc.run(['example/input/merged_chr1_10000.vcf.gz',
'--calc-statistic', 'pi',
'--out', 'out'])

# Confirm that the output is what is expected
self.assertTrue(compare_to_expected('out.windowed.pi', 'example/locus8.windowed.pi'))
self.assertTrue(file_comp('out.windowed.pi',
'example/merged_chr1_10000.windowed.pi'))

# Remove the ouput and log files created by the function
self.addCleanup(os.remove, 'out.windowed.pi')
Expand All @@ -85,10 +96,12 @@ def test_window_pi (self):
# Check that the allele frequency function is operating correctly
def test_freq (self):
# Run the function with the following arguments
vcf_calc.run(['example/locus8.vcf.gz', '--calc-statistic', 'freq', '--out', 'out'])
vcf_calc.run(['example/input/merged_chr1_10000.vcf.gz',
'--calc-statistic', 'freq',
'--out', 'out'])

# Confirm that the output is what is expected
self.assertTrue(compare_to_expected('out.frq', 'example/locus8.frq'))
self.assertTrue(file_comp('out.frq', 'example/merged_chr1_10000.frq'))

# Remove the ouput and log files created by the function
self.addCleanup(os.remove, 'out.frq')
Expand All @@ -97,10 +110,12 @@ def test_freq (self):
# Check that the heterozygosity function is operating correctly
def test_het (self):
# Run the function with the following arguments
vcf_calc.run(['example/locus8.vcf.gz', '--calc-statistic', 'het', '--out', 'out'])
vcf_calc.run(['example/input/merged_chr1_10000.vcf.gz',
'--calc-statistic', 'het',
'--out', 'out'])

# Confirm that the output is what is expected
self.assertTrue(compare_to_expected('out.het', 'example/locus8.het'))
self.assertTrue(file_comp('out.het', 'example/merged_chr1_10000.het'))

# Remove the ouput and log files created by the function
self.addCleanup(os.remove, 'out.het')
Expand Down Expand Up @@ -163,21 +178,21 @@ def test_column_assignment (self):
vcf_sampler.assign_position_columns(['NULL', 'NULL', 'NULL', 'NULL'])
self.assertEqual(str(cm.exception), 'Cannot find CHROM and BIN_START columns in file specified by --statistic-file.')

# Need file that is big enough to test (but not too large)
'''
# Check that the heterozygosity function is operating correctly
# Check that the entire sampler function (using random sampler) is operating correctly
def test_sampler (self):
# Run the function with the following arguments
vcf_sampler.run(['example/locus8.vcf.gz', '--calc-statistic', 'het', '--out', 'out'])
vcf_sampler.run(['example/input/merged_chr1_10000.vcf.gz',
'--statistic-file', 'example/merged_chr1_10000.windowed.weir.fst',
'--sample-size', '20',
'--random-seed', '1000'])

# Confirm that the output is what is expected
self.assertTrue(compare_to_expected('out.het', 'example/locus8.het'))
# Remove the ouput and log files created by the function
self.addCleanup(os.remove, 'out.het')
self.addCleanup(os.remove, 'out.het.log')
'''

self.assertTrue(file_comp('sampled_data.tsv', 'example/sampled_data.tsv'))
self.assertTrue(file_comp('out.vcf.gz', 'example/sampled_data.vcf.gz'))

# Remove the ouput files created by the function
self.addCleanup(os.remove, 'sampled_data.tsv')
self.addCleanup(os.remove, 'out.vcf.gz')

if __name__ == "__main__":
unittest.main()
File renamed without changes.
File renamed without changes.
Binary file added andrew/example/input/merged_chr1_1000.vcf.gz
Binary file not shown.
Binary file added andrew/example/input/merged_chr1_1000.vcf.gz.tbi
Binary file not shown.
Binary file added andrew/example/input/merged_chr1_10000.vcf.gz
Binary file not shown.
Binary file added andrew/example/input/merged_chr1_10000.vcf.gz.tbi
Binary file not shown.
File renamed without changes.
3 changes: 0 additions & 3 deletions andrew/example/locus8.Tajima.D

This file was deleted.

14 changes: 0 additions & 14 deletions andrew/example/locus8.Tajima.D.log

This file was deleted.

118 changes: 0 additions & 118 deletions andrew/example/locus8.frq

This file was deleted.

18 changes: 0 additions & 18 deletions andrew/example/locus8.het

This file was deleted.

14 changes: 0 additions & 14 deletions andrew/example/locus8.het.log

This file was deleted.

Binary file removed andrew/example/locus8.vcf.gz
Binary file not shown.
Binary file removed andrew/example/locus8.vcf.gz.tbi
Binary file not shown.

0 comments on commit c9f18f4

Please sign in to comment.