From 9eed9ae2d73cdb16a3f072a9a66b6bda936fb94e Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sun, 19 Feb 2017 12:01:02 -0800 Subject: [PATCH 01/32] some bulk loading/cleaning tests --- tests/test-data/valid-read-testing.fq | 32 ++++++++++++++++++++++++ tests/test_read_parsers.py | 35 ++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/test-data/valid-read-testing.fq diff --git a/tests/test-data/valid-read-testing.fq b/tests/test-data/valid-read-testing.fq new file mode 100644 index 0000000000..e28921cddf --- /dev/null +++ b/tests/test-data/valid-read-testing.fq @@ -0,0 +1,32 @@ +@895:1:1:1246:14654 1:N:0:NNNNN +CAGGCGCCCACCACCGTGCCCTCCAACCTGATGGT ++ +][aaX__aa[`ZUZ[NONNFNNNNNO_____^RQ_ +@895:1:1:1248:9583 1:N:0:NNNNN +ACTGGGCGTAGACGGTGTCCTCATCGGCACCAGC ++ +\UJUWSSV[JQQWNP]]SZ]ZWU^]ZX][^TXR` +@895:1:1:1252:19493 1:N:0:NNNNN +CCGGCGTGGTTGGTGAGGTCACTGAGCTTCATGTC ++ +OOOKONNNNN__`R]O[TGTRSY[IUZ]]]__X__ +@895:1:1:1255:18861 1:N:0:NNNNN +ACGACGAGAAGCTGATCTACCGCGCCGAGCGCATC ++ +bb_^^bb_XTbbbbbb_bab]KTITZQTZ]ZYT^^ +@lowercase_to_uppercase +caggcgcccaccaccgtgccctccaacctgatggt ++ +][aaX__aa[`ZUZ[NONNFNNNNNO_____^RQ_ +@n_in_read +ACTGGGCGTAGNCGGTGTCCTCATCGGCACCAGC ++ +\UJUWSSV[JQQWNP]]SZ]ZWU^]ZX][^TXR` +@895:1:1:1252:19493 1:N:0:NNNNN +CCGGCGTGGTTZZYAGGTCACTGAGCTTCATGTC ++ +OOOKONNNNN__`R]O[TGTRSY[IUZ]]]__X__ +@895:1:1:1255:18861 1:N:0:NNNNN +ACGACGAGAAGCTGATCTACCGCGCCGAGCGCATC ++ +bb_^^bb_XTbbbbbb_bab]KTITZQTZ]ZYT^^ diff --git a/tests/test_read_parsers.py b/tests/test_read_parsers.py index 22cdf32ad7..8e01235131 100644 --- a/tests/test_read_parsers.py +++ b/tests/test_read_parsers.py @@ -38,7 +38,7 @@ from __future__ import print_function from __future__ import absolute_import from khmer import Read -from khmer import ReadParser +from khmer import ReadParser, Counttable, Nodegraph from screed import Record from . import khmer_tst_utils as utils import pytest @@ -483,5 +483,38 @@ def test_clean_seq(): clean = read.sequence.upper().replace("N", "A") assert clean == read.cleaned_seq + +def test_read_cleaning_consume_seqfile(): + infile = utils.get_test_data('valid-read-testing.fq') + + x = Counttable(15, int(1e6), 4) + x.consume_seqfile(infile) + + # the relevant read will automatically get uppercased => abundance of 2 + kmer = "caggcgcccaccacc".upper() + assert x.get(kmer) == 2 + + # the 2nd read with this k-mer in it has an N in it. + kmer = "CCTCATCGGCACCAG" + assert x.get(kmer) == 1 # this should be 2 in the future + + # the 2nd read with this k-mer in it has a Z in it + kmer = "ACTGAGCTTCATGTC" + assert x.get(kmer) == 1 # this should be 2 in the future + + +def test_read_cleaning_abundance_distribution(): + infile = utils.get_test_data('valid-read-testing.fq') + + x = Counttable(15, int(1e6), 4) + y = Nodegraph(15, int(1e6), 4) + + x.consume_seqfile(infile) + + dist = x.abundance_distribution(infile, y) + assert dist[1] == 41 + assert dist[2] == 42 + + # vim: set filetype=python tabstop=4 softtabstop=4 shiftwidth=4 expandtab: # vim: set textwidth=79: From c0c5d2cb77639a7dc163618ffdb910f36afe670d Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sun, 19 Feb 2017 12:11:51 -0800 Subject: [PATCH 02/32] nail down existing ACTGN behavior --- tests/test_read_parsers.py | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_read_parsers.py b/tests/test_read_parsers.py index 8e01235131..8d2c01022f 100644 --- a/tests/test_read_parsers.py +++ b/tests/test_read_parsers.py @@ -503,6 +503,47 @@ def test_read_cleaning_consume_seqfile(): assert x.get(kmer) == 1 # this should be 2 in the future +def test_read_cleaning_consume_read_by_read(): + infile = utils.get_test_data('valid-read-testing.fq') + + x = Counttable(15, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.sequence) # consume raw sequence + + # the relevant read will be entirely ignored + # (b/c ReadParser does not uppercase) + kmer = "caggcgcccaccacc".upper() + assert x.get(kmer) == 1 + + # the 2nd read with this k-mer in it has an N in it; 'consume' will ignore. + kmer = "CCTCATCGGCACCAG" + assert x.get(kmer) == 2 + + # the 2nd read with this k-mer in it has a Z in it; 'consume' will ignore. + kmer = "ACTGAGCTTCATGTC" + assert x.get(kmer) == 2 + + +def test_read_cleaning_consume_read_by_read_cleaned_seq(): + infile = utils.get_test_data('valid-read-testing.fq') + + x = Counttable(15, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.cleaned_seq) # consume cleaned_seq + + # the relevant read will be cleaned & loaded + kmer = "caggcgcccaccacc".upper() + assert x.get(kmer) == 2 + + # this k-mer will be correctly loaded + kmer = "CCTCATCGGCACCAG" + assert x.get(kmer) == 2 + + # this k-mer will be correctly loaded + kmer = "ACTGAGCTTCATGTC" + assert x.get(kmer) == 2 + + def test_read_cleaning_abundance_distribution(): infile = utils.get_test_data('valid-read-testing.fq') From e77f1e16b70a142a8099bfb92c895abbdb9a5cab Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sun, 19 Feb 2017 13:56:35 -0800 Subject: [PATCH 03/32] add tests for various trim functions w/bad DNA input --- tests/test_read_parsers.py | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/test_read_parsers.py b/tests/test_read_parsers.py index 8d2c01022f..6fe0137cbe 100644 --- a/tests/test_read_parsers.py +++ b/tests/test_read_parsers.py @@ -557,5 +557,64 @@ def test_read_cleaning_abundance_distribution(): assert dist[2] == 42 +def test_read_cleaning_trim_functions_lowercase(): + infile = utils.get_test_data('valid-read-testing.fq') + + # read this in using "approved good" behavior w/cleaned_seq + x = Counttable(8, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.cleaned_seq) # consume cleaned_seq + + s = "caggcgcccaccaccgtgccctccaacctgatggt" + _, where = x.trim_on_abundance(s, 1) + assert where == 35 # in future, should be '0' + + _, where = x.trim_below_abundance(s, 2) + assert where == 35 # in future, should be '0' + + posns = x.find_spectral_error_positions(s, 1) + assert posns == [] # in future, should do same + + +def test_read_cleaning_trim_functions_N(): + infile = utils.get_test_data('valid-read-testing.fq') + + # read this in using "approved good" behavior w/cleaned_seq + x = Counttable(8, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.cleaned_seq) # consume cleaned_seq + + s = "ACTGGGCGTAGNCGGTGTCCTCATCGGCACCAGC" + _, where = x.trim_on_abundance(s, 1) + assert where == 0 # in future, should be ?? + + _, where = x.trim_below_abundance(s, 2) + assert where == 0 # in future, should be ?? + + with pytest.raises(ValueError): + posns = x.find_spectral_error_positions(s, 1) + # assert posns == [] # in future, should return [] + + +def test_read_cleaning_trim_functions_bad_dna(): + infile = utils.get_test_data('valid-read-testing.fq') + + # read this in using "approved good" behavior w/cleaned_seq + x = Counttable(8, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.cleaned_seq) # consume cleaned_seq + + s = "CCGGCGTGGTTZZYAGGTCACTGAGCTTCATGTC" + _, where = x.trim_on_abundance(s, 1) + assert where == 0 # in future, should be ?? + + _, where = x.trim_below_abundance(s, 2) + assert where == 0 # in future, should be ?? + + with pytest.raises(ValueError): + posns = x.find_spectral_error_positions(s, 1) + # assert posns == [] # in future, should return [] + + # vim: set filetype=python tabstop=4 softtabstop=4 shiftwidth=4 expandtab: # vim: set textwidth=79: From 33a77029cd414e14d39389ccc11168426399ac86 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sun, 19 Feb 2017 14:07:54 -0800 Subject: [PATCH 04/32] fixed --- tests/test_read_parsers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_read_parsers.py b/tests/test_read_parsers.py index 6fe0137cbe..e51cec5ced 100644 --- a/tests/test_read_parsers.py +++ b/tests/test_read_parsers.py @@ -570,7 +570,7 @@ def test_read_cleaning_trim_functions_lowercase(): assert where == 35 # in future, should be '0' _, where = x.trim_below_abundance(s, 2) - assert where == 35 # in future, should be '0' + assert where == 35 # in future, should be ?? @CTB posns = x.find_spectral_error_positions(s, 1) assert posns == [] # in future, should do same @@ -613,7 +613,7 @@ def test_read_cleaning_trim_functions_bad_dna(): with pytest.raises(ValueError): posns = x.find_spectral_error_positions(s, 1) - # assert posns == [] # in future, should return [] + # assert posns == [] # in future, should return [11] # vim: set filetype=python tabstop=4 softtabstop=4 shiftwidth=4 expandtab: From adfe3b989037d1819c3774fd972cea7d58476694 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sun, 19 Feb 2017 18:34:55 -0800 Subject: [PATCH 05/32] tset current output_partitions behavior in subset.cc --- tests/test-data/valid-read-testing.fq | 2 +- tests/test_read_parsers.py | 38 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/test-data/valid-read-testing.fq b/tests/test-data/valid-read-testing.fq index e28921cddf..e52c058709 100644 --- a/tests/test-data/valid-read-testing.fq +++ b/tests/test-data/valid-read-testing.fq @@ -22,7 +22,7 @@ caggcgcccaccaccgtgccctccaacctgatggt ACTGGGCGTAGNCGGTGTCCTCATCGGCACCAGC + \UJUWSSV[JQQWNP]]SZ]ZWU^]ZX][^TXR` -@895:1:1:1252:19493 1:N:0:NNNNN +@zy_in_read CCGGCGTGGTTZZYAGGTCACTGAGCTTCATGTC + OOOKONNNNN__`R]O[TGTRSY[IUZ]]]__X__ diff --git a/tests/test_read_parsers.py b/tests/test_read_parsers.py index e51cec5ced..c1a4b42019 100644 --- a/tests/test_read_parsers.py +++ b/tests/test_read_parsers.py @@ -616,5 +616,43 @@ def test_read_cleaning_trim_functions_bad_dna(): # assert posns == [] # in future, should return [11] +def test_read_cleaning_output_partitions(): + infile = utils.get_test_data('valid-read-testing.fq') + savepath = utils.get_temp_filename('foo') + + # read this in using "approved good" behavior w/cleaned_seq + x = Nodegraph(8, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.cleaned_seq) # consume cleaned_seq + + kmer = 'caggcgcc'.upper() + x.add_tag(kmer) + x.set_partition_id(kmer, 1) + + kmer = 'ACTGGGCG' + x.add_tag(kmer) + x.set_partition_id(kmer, 2) + + kmer = 'CCGGCGTG' + x.add_tag(kmer) + x.set_partition_id(kmer, 3) + + x.output_partitions(infile, savepath) + + read_names = [ read.name for read in ReadParser(savepath) ] + print(read_names) + assert len(read_names) == 4 + + assert '895:1:1:1246:14654 1:N:0:NNNNN\t1' in read_names + assert '895:1:1:1248:9583 1:N:0:NNNNN\t2' in read_names + assert '895:1:1:1252:19493 1:N:0:NNNNN\t3' in read_names + + assert 'lowercase_to_uppercase\t1' in read_names + + assert 'n_in_read\t2' not in read_names + assert 'zy_in_read\t3' not in read_names + + + # vim: set filetype=python tabstop=4 softtabstop=4 shiftwidth=4 expandtab: # vim: set textwidth=79: From 5adf7bf42040688e5ddec35ef9dd7489bcd53396 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sun, 19 Feb 2017 19:04:32 -0800 Subject: [PATCH 06/32] add test for trim_on_stoptags --- tests/test_read_parsers.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_read_parsers.py b/tests/test_read_parsers.py index c1a4b42019..5d2f1c0896 100644 --- a/tests/test_read_parsers.py +++ b/tests/test_read_parsers.py @@ -653,6 +653,34 @@ def test_read_cleaning_output_partitions(): assert 'zy_in_read\t3' not in read_names +def test_read_cleaning_trim_on_stoptags(): + infile = utils.get_test_data('valid-read-testing.fq') + savepath = utils.get_temp_filename('foo') + + # read this in using "approved good" behavior w/cleaned_seq + x = Nodegraph(8, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.cleaned_seq) # consume cleaned_seq + + # add this as a stop tag + kmer = 'caggcgcc'.upper() + x.add_stop_tag(kmer) + + kmer = 'ACTGGGCG' + x.add_stop_tag(kmer) + + kmer = 'CCGGCGTG' + x.add_stop_tag(kmer) + + _, pos = x.trim_on_stoptags('caggcgcccaccaccgtgccctccaacctgatggt') + assert pos == 6 # should be ?? in future + + _, pos = x.trim_on_stoptags('CCGGCGTGGTTZZYAGGTCACTGAGCTTCATGTC') + assert pos == 0 # should be 6 in future + + _, pos = x.trim_on_stoptags('CCGGCGTGGTTZZYAGGTCACTGAGCTTCATGTC') + assert pos == 0 # should be 6 in future + # vim: set filetype=python tabstop=4 softtabstop=4 shiftwidth=4 expandtab: # vim: set textwidth=79: From fe487879c47c4c96d4f368363c735d0f0ac825dd Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Fri, 24 Feb 2017 20:45:33 -0800 Subject: [PATCH 07/32] fix comments to be clearer --- tests/test_read_parsers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_read_parsers.py b/tests/test_read_parsers.py index 5d2f1c0896..10332a59a4 100644 --- a/tests/test_read_parsers.py +++ b/tests/test_read_parsers.py @@ -515,11 +515,13 @@ def test_read_cleaning_consume_read_by_read(): kmer = "caggcgcccaccacc".upper() assert x.get(kmer) == 1 - # the 2nd read with this k-mer in it has an N in it; 'consume' will ignore. + # consume will ignore the invalid base in 2nd read containing this k-mer, + # so the k-mer will have an abundance of 2. kmer = "CCTCATCGGCACCAG" assert x.get(kmer) == 2 - # the 2nd read with this k-mer in it has a Z in it; 'consume' will ignore. + # consume will ignore the invalid base in 2nd read containing this k-mer, + # so the k-mer will have an abundance of 2. kmer = "ACTGAGCTTCATGTC" assert x.get(kmer) == 2 From 756454e979c2564cb13ee242ed720865b707ec83 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Fri, 24 Feb 2017 20:46:25 -0800 Subject: [PATCH 08/32] fix pep8 --- tests/test_read_parsers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_read_parsers.py b/tests/test_read_parsers.py index 10332a59a4..369be37576 100644 --- a/tests/test_read_parsers.py +++ b/tests/test_read_parsers.py @@ -634,14 +634,14 @@ def test_read_cleaning_output_partitions(): kmer = 'ACTGGGCG' x.add_tag(kmer) x.set_partition_id(kmer, 2) - + kmer = 'CCGGCGTG' x.add_tag(kmer) x.set_partition_id(kmer, 3) - + x.output_partitions(infile, savepath) - read_names = [ read.name for read in ReadParser(savepath) ] + read_names = [read.name for read in ReadParser(savepath)] print(read_names) assert len(read_names) == 4 From 2db818063a48970b7c280fd93e6b5effc373de7d Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Fri, 24 Feb 2017 21:04:12 -0800 Subject: [PATCH 09/32] moved read validity foo over to test_sequence_validation.py --- tests/test_read_parsers.py | 200 ------------------------ tests/test_sequence_validation.py | 248 ++++++++++++++++++++++++++++++ 2 files changed, 248 insertions(+), 200 deletions(-) create mode 100644 tests/test_sequence_validation.py diff --git a/tests/test_read_parsers.py b/tests/test_read_parsers.py index 369be37576..a919bb5a00 100644 --- a/tests/test_read_parsers.py +++ b/tests/test_read_parsers.py @@ -484,205 +484,5 @@ def test_clean_seq(): assert clean == read.cleaned_seq -def test_read_cleaning_consume_seqfile(): - infile = utils.get_test_data('valid-read-testing.fq') - - x = Counttable(15, int(1e6), 4) - x.consume_seqfile(infile) - - # the relevant read will automatically get uppercased => abundance of 2 - kmer = "caggcgcccaccacc".upper() - assert x.get(kmer) == 2 - - # the 2nd read with this k-mer in it has an N in it. - kmer = "CCTCATCGGCACCAG" - assert x.get(kmer) == 1 # this should be 2 in the future - - # the 2nd read with this k-mer in it has a Z in it - kmer = "ACTGAGCTTCATGTC" - assert x.get(kmer) == 1 # this should be 2 in the future - - -def test_read_cleaning_consume_read_by_read(): - infile = utils.get_test_data('valid-read-testing.fq') - - x = Counttable(15, int(1e6), 4) - for read in ReadParser(infile): - x.consume(read.sequence) # consume raw sequence - - # the relevant read will be entirely ignored - # (b/c ReadParser does not uppercase) - kmer = "caggcgcccaccacc".upper() - assert x.get(kmer) == 1 - - # consume will ignore the invalid base in 2nd read containing this k-mer, - # so the k-mer will have an abundance of 2. - kmer = "CCTCATCGGCACCAG" - assert x.get(kmer) == 2 - - # consume will ignore the invalid base in 2nd read containing this k-mer, - # so the k-mer will have an abundance of 2. - kmer = "ACTGAGCTTCATGTC" - assert x.get(kmer) == 2 - - -def test_read_cleaning_consume_read_by_read_cleaned_seq(): - infile = utils.get_test_data('valid-read-testing.fq') - - x = Counttable(15, int(1e6), 4) - for read in ReadParser(infile): - x.consume(read.cleaned_seq) # consume cleaned_seq - - # the relevant read will be cleaned & loaded - kmer = "caggcgcccaccacc".upper() - assert x.get(kmer) == 2 - - # this k-mer will be correctly loaded - kmer = "CCTCATCGGCACCAG" - assert x.get(kmer) == 2 - - # this k-mer will be correctly loaded - kmer = "ACTGAGCTTCATGTC" - assert x.get(kmer) == 2 - - -def test_read_cleaning_abundance_distribution(): - infile = utils.get_test_data('valid-read-testing.fq') - - x = Counttable(15, int(1e6), 4) - y = Nodegraph(15, int(1e6), 4) - - x.consume_seqfile(infile) - - dist = x.abundance_distribution(infile, y) - assert dist[1] == 41 - assert dist[2] == 42 - - -def test_read_cleaning_trim_functions_lowercase(): - infile = utils.get_test_data('valid-read-testing.fq') - - # read this in using "approved good" behavior w/cleaned_seq - x = Counttable(8, int(1e6), 4) - for read in ReadParser(infile): - x.consume(read.cleaned_seq) # consume cleaned_seq - - s = "caggcgcccaccaccgtgccctccaacctgatggt" - _, where = x.trim_on_abundance(s, 1) - assert where == 35 # in future, should be '0' - - _, where = x.trim_below_abundance(s, 2) - assert where == 35 # in future, should be ?? @CTB - - posns = x.find_spectral_error_positions(s, 1) - assert posns == [] # in future, should do same - - -def test_read_cleaning_trim_functions_N(): - infile = utils.get_test_data('valid-read-testing.fq') - - # read this in using "approved good" behavior w/cleaned_seq - x = Counttable(8, int(1e6), 4) - for read in ReadParser(infile): - x.consume(read.cleaned_seq) # consume cleaned_seq - - s = "ACTGGGCGTAGNCGGTGTCCTCATCGGCACCAGC" - _, where = x.trim_on_abundance(s, 1) - assert where == 0 # in future, should be ?? - - _, where = x.trim_below_abundance(s, 2) - assert where == 0 # in future, should be ?? - - with pytest.raises(ValueError): - posns = x.find_spectral_error_positions(s, 1) - # assert posns == [] # in future, should return [] - - -def test_read_cleaning_trim_functions_bad_dna(): - infile = utils.get_test_data('valid-read-testing.fq') - - # read this in using "approved good" behavior w/cleaned_seq - x = Counttable(8, int(1e6), 4) - for read in ReadParser(infile): - x.consume(read.cleaned_seq) # consume cleaned_seq - - s = "CCGGCGTGGTTZZYAGGTCACTGAGCTTCATGTC" - _, where = x.trim_on_abundance(s, 1) - assert where == 0 # in future, should be ?? - - _, where = x.trim_below_abundance(s, 2) - assert where == 0 # in future, should be ?? - - with pytest.raises(ValueError): - posns = x.find_spectral_error_positions(s, 1) - # assert posns == [] # in future, should return [11] - - -def test_read_cleaning_output_partitions(): - infile = utils.get_test_data('valid-read-testing.fq') - savepath = utils.get_temp_filename('foo') - - # read this in using "approved good" behavior w/cleaned_seq - x = Nodegraph(8, int(1e6), 4) - for read in ReadParser(infile): - x.consume(read.cleaned_seq) # consume cleaned_seq - - kmer = 'caggcgcc'.upper() - x.add_tag(kmer) - x.set_partition_id(kmer, 1) - - kmer = 'ACTGGGCG' - x.add_tag(kmer) - x.set_partition_id(kmer, 2) - - kmer = 'CCGGCGTG' - x.add_tag(kmer) - x.set_partition_id(kmer, 3) - - x.output_partitions(infile, savepath) - - read_names = [read.name for read in ReadParser(savepath)] - print(read_names) - assert len(read_names) == 4 - - assert '895:1:1:1246:14654 1:N:0:NNNNN\t1' in read_names - assert '895:1:1:1248:9583 1:N:0:NNNNN\t2' in read_names - assert '895:1:1:1252:19493 1:N:0:NNNNN\t3' in read_names - - assert 'lowercase_to_uppercase\t1' in read_names - - assert 'n_in_read\t2' not in read_names - assert 'zy_in_read\t3' not in read_names - - -def test_read_cleaning_trim_on_stoptags(): - infile = utils.get_test_data('valid-read-testing.fq') - savepath = utils.get_temp_filename('foo') - - # read this in using "approved good" behavior w/cleaned_seq - x = Nodegraph(8, int(1e6), 4) - for read in ReadParser(infile): - x.consume(read.cleaned_seq) # consume cleaned_seq - - # add this as a stop tag - kmer = 'caggcgcc'.upper() - x.add_stop_tag(kmer) - - kmer = 'ACTGGGCG' - x.add_stop_tag(kmer) - - kmer = 'CCGGCGTG' - x.add_stop_tag(kmer) - - _, pos = x.trim_on_stoptags('caggcgcccaccaccgtgccctccaacctgatggt') - assert pos == 6 # should be ?? in future - - _, pos = x.trim_on_stoptags('CCGGCGTGGTTZZYAGGTCACTGAGCTTCATGTC') - assert pos == 0 # should be 6 in future - - _, pos = x.trim_on_stoptags('CCGGCGTGGTTZZYAGGTCACTGAGCTTCATGTC') - assert pos == 0 # should be 6 in future - - # vim: set filetype=python tabstop=4 softtabstop=4 shiftwidth=4 expandtab: # vim: set textwidth=79: diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py new file mode 100644 index 0000000000..8c062613a6 --- /dev/null +++ b/tests/test_sequence_validation.py @@ -0,0 +1,248 @@ +# This file is part of khmer, https://github.com/dib-lab/khmer/, and is +# Copyright (C) 2013-2015, Michigan State University. +# Copyright (C) 2015-2016, The Regents of the University of California. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# * Neither the name of the Michigan State University nor the names +# of its contributors may be used to endorse or promote products +# derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Contact: khmer-project@idyll.org +# pylint: disable=missing-docstring,invalid-name + +# Tests for the ReadParser and Read classes. +from __future__ import print_function +from __future__ import absolute_import +from khmer import ReadParser, Counttable, Nodegraph +from screed import Record +from . import khmer_tst_utils as utils +import pytest +from functools import reduce # pylint: disable=redefined-builtin + + +def test_read_cleaning_consume_seqfile(): + infile = utils.get_test_data('valid-read-testing.fq') + + x = Counttable(15, int(1e6), 4) + x.consume_seqfile(infile) + + # the relevant read will automatically get uppercased => abundance of 2 + kmer = "caggcgcccaccacc".upper() + assert x.get(kmer) == 2 + + # the 2nd read with this k-mer in it has an N in it. + kmer = "CCTCATCGGCACCAG" + assert x.get(kmer) == 1 # this should be 2 in the future + + # the 2nd read with this k-mer in it has a Z in it + kmer = "ACTGAGCTTCATGTC" + assert x.get(kmer) == 1 # this should be 2 in the future + + +def test_read_cleaning_consume_read_by_read(): + infile = utils.get_test_data('valid-read-testing.fq') + + x = Counttable(15, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.sequence) # consume raw sequence + + # the relevant read will be entirely ignored + # (b/c ReadParser does not uppercase) + kmer = "caggcgcccaccacc".upper() + assert x.get(kmer) == 1 + + # consume will ignore the invalid base in 2nd read containing this k-mer, + # so the k-mer will have an abundance of 2. + kmer = "CCTCATCGGCACCAG" + assert x.get(kmer) == 2 + + # consume will ignore the invalid base in 2nd read containing this k-mer, + # so the k-mer will have an abundance of 2. + kmer = "ACTGAGCTTCATGTC" + assert x.get(kmer) == 2 + + +def test_read_cleaning_consume_read_by_read_cleaned_seq(): + infile = utils.get_test_data('valid-read-testing.fq') + + x = Counttable(15, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.cleaned_seq) # consume cleaned_seq + + # the relevant read will be cleaned & loaded + kmer = "caggcgcccaccacc".upper() + assert x.get(kmer) == 2 + + # this k-mer will be correctly loaded + kmer = "CCTCATCGGCACCAG" + assert x.get(kmer) == 2 + + # this k-mer will be correctly loaded + kmer = "ACTGAGCTTCATGTC" + assert x.get(kmer) == 2 + + +def test_read_cleaning_abundance_distribution(): + infile = utils.get_test_data('valid-read-testing.fq') + + x = Counttable(15, int(1e6), 4) + y = Nodegraph(15, int(1e6), 4) + + x.consume_seqfile(infile) + + dist = x.abundance_distribution(infile, y) + assert dist[1] == 41 + assert dist[2] == 42 + + +def test_read_cleaning_trim_functions_lowercase(): + infile = utils.get_test_data('valid-read-testing.fq') + + # read this in using "approved good" behavior w/cleaned_seq + x = Counttable(8, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.cleaned_seq) # consume cleaned_seq + + s = "caggcgcccaccaccgtgccctccaacctgatggt" + _, where = x.trim_on_abundance(s, 1) + assert where == 35 # in future, should be '0' + + _, where = x.trim_below_abundance(s, 2) + assert where == 35 # in future, should be ?? @CTB + + posns = x.find_spectral_error_positions(s, 1) + assert posns == [] # in future, should do same + + +def test_read_cleaning_trim_functions_N(): + infile = utils.get_test_data('valid-read-testing.fq') + + # read this in using "approved good" behavior w/cleaned_seq + x = Counttable(8, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.cleaned_seq) # consume cleaned_seq + + s = "ACTGGGCGTAGNCGGTGTCCTCATCGGCACCAGC" + _, where = x.trim_on_abundance(s, 1) + assert where == 0 # in future, should be ?? + + _, where = x.trim_below_abundance(s, 2) + assert where == 0 # in future, should be ?? + + with pytest.raises(ValueError): + posns = x.find_spectral_error_positions(s, 1) + # assert posns == [] # in future, should return [] + + +def test_read_cleaning_trim_functions_bad_dna(): + infile = utils.get_test_data('valid-read-testing.fq') + + # read this in using "approved good" behavior w/cleaned_seq + x = Counttable(8, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.cleaned_seq) # consume cleaned_seq + + s = "CCGGCGTGGTTZZYAGGTCACTGAGCTTCATGTC" + _, where = x.trim_on_abundance(s, 1) + assert where == 0 # in future, should be ?? + + _, where = x.trim_below_abundance(s, 2) + assert where == 0 # in future, should be ?? + + with pytest.raises(ValueError): + posns = x.find_spectral_error_positions(s, 1) + # assert posns == [] # in future, should return [11] + + +def test_read_cleaning_output_partitions(): + infile = utils.get_test_data('valid-read-testing.fq') + savepath = utils.get_temp_filename('foo') + + # read this in using "approved good" behavior w/cleaned_seq + x = Nodegraph(8, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.cleaned_seq) # consume cleaned_seq + + kmer = 'caggcgcc'.upper() + x.add_tag(kmer) + x.set_partition_id(kmer, 1) + + kmer = 'ACTGGGCG' + x.add_tag(kmer) + x.set_partition_id(kmer, 2) + + kmer = 'CCGGCGTG' + x.add_tag(kmer) + x.set_partition_id(kmer, 3) + + x.output_partitions(infile, savepath) + + read_names = [read.name for read in ReadParser(savepath)] + print(read_names) + assert len(read_names) == 4 + + assert '895:1:1:1246:14654 1:N:0:NNNNN\t1' in read_names + assert '895:1:1:1248:9583 1:N:0:NNNNN\t2' in read_names + assert '895:1:1:1252:19493 1:N:0:NNNNN\t3' in read_names + + assert 'lowercase_to_uppercase\t1' in read_names + + assert 'n_in_read\t2' not in read_names + assert 'zy_in_read\t3' not in read_names + + +def test_read_cleaning_trim_on_stoptags(): + infile = utils.get_test_data('valid-read-testing.fq') + savepath = utils.get_temp_filename('foo') + + # read this in using "approved good" behavior w/cleaned_seq + x = Nodegraph(8, int(1e6), 4) + for read in ReadParser(infile): + x.consume(read.cleaned_seq) # consume cleaned_seq + + # add this as a stop tag + kmer = 'caggcgcc'.upper() + x.add_stop_tag(kmer) + + kmer = 'ACTGGGCG' + x.add_stop_tag(kmer) + + kmer = 'CCGGCGTG' + x.add_stop_tag(kmer) + + _, pos = x.trim_on_stoptags('caggcgcccaccaccgtgccctccaacctgatggt') + assert pos == 6 # should be ?? in future + + _, pos = x.trim_on_stoptags('CCGGCGTGGTTZZYAGGTCACTGAGCTTCATGTC') + assert pos == 0 # should be 6 in future + + _, pos = x.trim_on_stoptags('CCGGCGTGGTTZZYAGGTCACTGAGCTTCATGTC') + assert pos == 0 # should be 6 in future + + +# vim: set filetype=python tabstop=4 softtabstop=4 shiftwidth=4 expandtab: +# vim: set textwidth=79: From 870678e45a25aca8f956df9f7a5062951ea54b11 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Fri, 24 Feb 2017 21:00:47 -0800 Subject: [PATCH 10/32] split tests out to test_sequence_validation From b2b22d75af604d390297ca6cfbf5c0727efceefa Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Fri, 24 Feb 2017 21:11:56 -0800 Subject: [PATCH 11/32] parameterized with tabletype --- tests/test_sequence_validation.py | 43 +++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index 8c062613a6..6cc2e326b8 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -37,6 +37,8 @@ # Tests for the ReadParser and Read classes. from __future__ import print_function from __future__ import absolute_import +from khmer import _Countgraph, _Counttable, _SmallCountgraph, _SmallCounttable +from khmer import _Nodegraph, _Nodetable from khmer import ReadParser, Counttable, Nodegraph from screed import Record from . import khmer_tst_utils as utils @@ -44,10 +46,19 @@ from functools import reduce # pylint: disable=redefined-builtin -def test_read_cleaning_consume_seqfile(): +PRIMES_1m = [1000003, 1009837] + + +# all the table types! +@pytest.fixture(params=[_Countgraph, _Counttable, _SmallCountgraph, + _SmallCounttable, _Nodegraph, _Nodetable]) +def tabletype(request): + return request.param + +def test_read_cleaning_consume_seqfile(tabletype): infile = utils.get_test_data('valid-read-testing.fq') - x = Counttable(15, int(1e6), 4) + x = tabletype(15, PRIMES_1m) x.consume_seqfile(infile) # the relevant read will automatically get uppercased => abundance of 2 @@ -63,10 +74,10 @@ def test_read_cleaning_consume_seqfile(): assert x.get(kmer) == 1 # this should be 2 in the future -def test_read_cleaning_consume_read_by_read(): +def test_read_cleaning_consume_read_by_read(tabletype): infile = utils.get_test_data('valid-read-testing.fq') - x = Counttable(15, int(1e6), 4) + x = tabletype(15, PRIMES_1m) for read in ReadParser(infile): x.consume(read.sequence) # consume raw sequence @@ -86,10 +97,10 @@ def test_read_cleaning_consume_read_by_read(): assert x.get(kmer) == 2 -def test_read_cleaning_consume_read_by_read_cleaned_seq(): +def test_read_cleaning_consume_read_by_read_cleaned_seq(tabletype): infile = utils.get_test_data('valid-read-testing.fq') - x = Counttable(15, int(1e6), 4) + x = tabletype(15, PRIMES_1m) for read in ReadParser(infile): x.consume(read.cleaned_seq) # consume cleaned_seq @@ -106,11 +117,11 @@ def test_read_cleaning_consume_read_by_read_cleaned_seq(): assert x.get(kmer) == 2 -def test_read_cleaning_abundance_distribution(): +def test_read_cleaning_abundance_distribution(tabletype): infile = utils.get_test_data('valid-read-testing.fq') - x = Counttable(15, int(1e6), 4) - y = Nodegraph(15, int(1e6), 4) + x = tabletype(15, PRIMES_1m) + y = _Nodegraph(15, PRIMES_1m) x.consume_seqfile(infile) @@ -119,11 +130,11 @@ def test_read_cleaning_abundance_distribution(): assert dist[2] == 42 -def test_read_cleaning_trim_functions_lowercase(): +def test_read_cleaning_trim_functions_lowercase(tabletype): infile = utils.get_test_data('valid-read-testing.fq') # read this in using "approved good" behavior w/cleaned_seq - x = Counttable(8, int(1e6), 4) + x = tabletype(8, PRIMES_1m) for read in ReadParser(infile): x.consume(read.cleaned_seq) # consume cleaned_seq @@ -138,11 +149,11 @@ def test_read_cleaning_trim_functions_lowercase(): assert posns == [] # in future, should do same -def test_read_cleaning_trim_functions_N(): +def test_read_cleaning_trim_functions_N(tabletype): infile = utils.get_test_data('valid-read-testing.fq') # read this in using "approved good" behavior w/cleaned_seq - x = Counttable(8, int(1e6), 4) + x = tabletype(8, PRIMES_1m) for read in ReadParser(infile): x.consume(read.cleaned_seq) # consume cleaned_seq @@ -158,11 +169,11 @@ def test_read_cleaning_trim_functions_N(): # assert posns == [] # in future, should return [] -def test_read_cleaning_trim_functions_bad_dna(): +def test_read_cleaning_trim_functions_bad_dna(tabletype): infile = utils.get_test_data('valid-read-testing.fq') # read this in using "approved good" behavior w/cleaned_seq - x = Counttable(8, int(1e6), 4) + x = tabletype(8, PRIMES_1m) for read in ReadParser(infile): x.consume(read.cleaned_seq) # consume cleaned_seq @@ -183,7 +194,7 @@ def test_read_cleaning_output_partitions(): savepath = utils.get_temp_filename('foo') # read this in using "approved good" behavior w/cleaned_seq - x = Nodegraph(8, int(1e6), 4) + x = _Nodegraph(8, PRIMES_1m) for read in ReadParser(infile): x.consume(read.cleaned_seq) # consume cleaned_seq From 12b88a5fa027f839062179dd907e70a39c962943 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Fri, 24 Feb 2017 21:15:36 -0800 Subject: [PATCH 12/32] add exceptions --- tests/test_sequence_validation.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index 6cc2e326b8..337f83d253 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -58,6 +58,9 @@ def tabletype(request): def test_read_cleaning_consume_seqfile(tabletype): infile = utils.get_test_data('valid-read-testing.fq') + if tabletype == _Nodegraph or tabletype == _Nodetable: + return + x = tabletype(15, PRIMES_1m) x.consume_seqfile(infile) @@ -77,6 +80,9 @@ def test_read_cleaning_consume_seqfile(tabletype): def test_read_cleaning_consume_read_by_read(tabletype): infile = utils.get_test_data('valid-read-testing.fq') + if tabletype == _Nodegraph or tabletype == _Nodetable: + return + x = tabletype(15, PRIMES_1m) for read in ReadParser(infile): x.consume(read.sequence) # consume raw sequence @@ -100,6 +106,9 @@ def test_read_cleaning_consume_read_by_read(tabletype): def test_read_cleaning_consume_read_by_read_cleaned_seq(tabletype): infile = utils.get_test_data('valid-read-testing.fq') + if tabletype == _Nodegraph or tabletype == _Nodetable: + return + x = tabletype(15, PRIMES_1m) for read in ReadParser(infile): x.consume(read.cleaned_seq) # consume cleaned_seq @@ -120,6 +129,9 @@ def test_read_cleaning_consume_read_by_read_cleaned_seq(tabletype): def test_read_cleaning_abundance_distribution(tabletype): infile = utils.get_test_data('valid-read-testing.fq') + if tabletype == _Nodegraph or tabletype == _Nodetable: + return + x = tabletype(15, PRIMES_1m) y = _Nodegraph(15, PRIMES_1m) From d303d46627cc3a9ed4e0c1ee6cd23b1d00b2b673 Mon Sep 17 00:00:00 2001 From: Tim Head Date: Tue, 28 Feb 2017 12:01:20 +0100 Subject: [PATCH 13/32] Add a fixture for ReadParser use With the fixture we can explicitly close all the ReadParser which might help with the too many open files error on OSX Travis --- tests/test_sequence_validation.py | 44 ++++++++++++++----------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index 337f83d253..8e1e48973e 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -39,11 +39,9 @@ from __future__ import absolute_import from khmer import _Countgraph, _Counttable, _SmallCountgraph, _SmallCounttable from khmer import _Nodegraph, _Nodetable -from khmer import ReadParser, Counttable, Nodegraph -from screed import Record +from khmer import ReadParser, Nodegraph from . import khmer_tst_utils as utils import pytest -from functools import reduce # pylint: disable=redefined-builtin PRIMES_1m = [1000003, 1009837] @@ -55,9 +53,17 @@ def tabletype(request): return request.param -def test_read_cleaning_consume_seqfile(tabletype): + +@pytest.fixture +def reads(): infile = utils.get_test_data('valid-read-testing.fq') + reads = ReadParser(infile) + yield reads + reads.close() + +def test_read_cleaning_consume_seqfile(tabletype): + infile = utils.get_test_data('valid-read-testing.fq') if tabletype == _Nodegraph or tabletype == _Nodetable: return @@ -77,14 +83,12 @@ def test_read_cleaning_consume_seqfile(tabletype): assert x.get(kmer) == 1 # this should be 2 in the future -def test_read_cleaning_consume_read_by_read(tabletype): - infile = utils.get_test_data('valid-read-testing.fq') - +def test_read_cleaning_consume_read_by_read(tabletype, reads): if tabletype == _Nodegraph or tabletype == _Nodetable: return x = tabletype(15, PRIMES_1m) - for read in ReadParser(infile): + for read in reads: x.consume(read.sequence) # consume raw sequence # the relevant read will be entirely ignored @@ -103,14 +107,12 @@ def test_read_cleaning_consume_read_by_read(tabletype): assert x.get(kmer) == 2 -def test_read_cleaning_consume_read_by_read_cleaned_seq(tabletype): - infile = utils.get_test_data('valid-read-testing.fq') - +def test_read_cleaning_consume_read_by_read_cleaned_seq(tabletype, reads): if tabletype == _Nodegraph or tabletype == _Nodetable: return x = tabletype(15, PRIMES_1m) - for read in ReadParser(infile): + for read in reads: x.consume(read.cleaned_seq) # consume cleaned_seq # the relevant read will be cleaned & loaded @@ -142,12 +144,10 @@ def test_read_cleaning_abundance_distribution(tabletype): assert dist[2] == 42 -def test_read_cleaning_trim_functions_lowercase(tabletype): - infile = utils.get_test_data('valid-read-testing.fq') - +def test_read_cleaning_trim_functions_lowercase(tabletype, reads): # read this in using "approved good" behavior w/cleaned_seq x = tabletype(8, PRIMES_1m) - for read in ReadParser(infile): + for read in reads: x.consume(read.cleaned_seq) # consume cleaned_seq s = "caggcgcccaccaccgtgccctccaacctgatggt" @@ -161,12 +161,10 @@ def test_read_cleaning_trim_functions_lowercase(tabletype): assert posns == [] # in future, should do same -def test_read_cleaning_trim_functions_N(tabletype): - infile = utils.get_test_data('valid-read-testing.fq') - +def test_read_cleaning_trim_functions_N(tabletype, reads): # read this in using "approved good" behavior w/cleaned_seq x = tabletype(8, PRIMES_1m) - for read in ReadParser(infile): + for read in reads: x.consume(read.cleaned_seq) # consume cleaned_seq s = "ACTGGGCGTAGNCGGTGTCCTCATCGGCACCAGC" @@ -181,12 +179,10 @@ def test_read_cleaning_trim_functions_N(tabletype): # assert posns == [] # in future, should return [] -def test_read_cleaning_trim_functions_bad_dna(tabletype): - infile = utils.get_test_data('valid-read-testing.fq') - +def test_read_cleaning_trim_functions_bad_dna(tabletype, reads): # read this in using "approved good" behavior w/cleaned_seq x = tabletype(8, PRIMES_1m) - for read in ReadParser(infile): + for read in reads: x.consume(read.cleaned_seq) # consume cleaned_seq s = "CCGGCGTGGTTZZYAGGTCACTGAGCTTCATGTC" From 08d2f28f55256dbf7e25c4fee5905855e8517e33 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 18 Mar 2017 19:27:36 -0600 Subject: [PATCH 14/32] fix setup.py for offline operation --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2c11f4d8b1..7fc8d91c8a 100755 --- a/setup.py +++ b/setup.py @@ -227,7 +227,7 @@ def check_for_openmp(): "packages": ['khmer', 'khmer.tests', 'oxli'], "package_dir": {'khmer.tests': 'tests'}, "install_requires": ['screed >= 0.9', 'bz2file'], - "setup_requires": ["pytest-runner>=2.0,<3dev"], +# "setup_requires": ["pytest-runner>=2.0,<3dev"], "extras_require": {':python_version=="2.6"': ['argparse>=1.2.1'], 'docs': ['sphinx', 'sphinxcontrib-autoprogram'], 'tests': ['pytest>=2.9'], From 29ed27596df47c9f2ffcf4473dfe0fc7b06b9a4d Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 18 Mar 2017 19:35:35 -0600 Subject: [PATCH 15/32] fix pytest fixture problem on my laptop --- tests/test_sequence_validation.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index 8e1e48973e..e3e6bb3f85 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -58,8 +58,12 @@ def tabletype(request): def reads(): infile = utils.get_test_data('valid-read-testing.fq') reads = ReadParser(infile) - yield reads - reads.close() + try: + return reads + finally: + reads.close() +# yield reads +# reads.close() def test_read_cleaning_consume_seqfile(tabletype): From 18d8577b248f9cd2630e2bc41cfb292abdb558a4 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 18 Mar 2017 19:45:57 -0600 Subject: [PATCH 16/32] introduce graphtype fixture --- tests/test_sequence_validation.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index e3e6bb3f85..a33bf133ad 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -54,6 +54,12 @@ def tabletype(request): return request.param +# all the graph types! +@pytest.fixture(params=[_Countgraph, _Nodegraph]) +def graphtype(request): + return request.param + + @pytest.fixture def reads(): infile = utils.get_test_data('valid-read-testing.fq') @@ -238,7 +244,7 @@ def test_read_cleaning_output_partitions(): assert 'zy_in_read\t3' not in read_names -def test_read_cleaning_trim_on_stoptags(): +def test_read_cleaning_trim_on_stoptags(graphtype): infile = utils.get_test_data('valid-read-testing.fq') savepath = utils.get_temp_filename('foo') From 4c9c63b3cab51ea8594e23960bed9d32ec58a0ab Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 18 Mar 2017 19:51:17 -0600 Subject: [PATCH 17/32] check the number of tags created by consume_fasta_and_tag --- tests/test_sequence_validation.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index a33bf133ad..2cd8340bf6 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -207,7 +207,7 @@ def test_read_cleaning_trim_functions_bad_dna(tabletype, reads): # assert posns == [] # in future, should return [11] -def test_read_cleaning_output_partitions(): +def test_read_cleaning_output_partitions(graphtype): infile = utils.get_test_data('valid-read-testing.fq') savepath = utils.get_temp_filename('foo') @@ -249,7 +249,7 @@ def test_read_cleaning_trim_on_stoptags(graphtype): savepath = utils.get_temp_filename('foo') # read this in using "approved good" behavior w/cleaned_seq - x = Nodegraph(8, int(1e6), 4) + x = graphtype(8, PRIMES_1m) for read in ReadParser(infile): x.consume(read.cleaned_seq) # consume cleaned_seq @@ -273,5 +273,16 @@ def test_read_cleaning_trim_on_stoptags(graphtype): assert pos == 0 # should be 6 in future +def test_consume_seqfile_and_tag(graphtype): + infile = utils.get_test_data('valid-read-testing.fq') + savepath = utils.get_temp_filename('foo') + + # read this in consume_and_tag + x = graphtype(8, PRIMES_1m) + x.consume_seqfile_and_tag(infile) + _, n_tags = x.count_partitions() + assert n_tags == 4 # total # of tags + + # vim: set filetype=python tabstop=4 softtabstop=4 shiftwidth=4 expandtab: # vim: set textwidth=79: From 5e01a81f1f3edc487fa5030f7ba28b10965c4493 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 18 Mar 2017 20:03:34 -0600 Subject: [PATCH 18/32] add partition IDs to valid-dna testing fq --- tests/test-data/valid-read-testing.fq | 16 ++++++++-------- tests/test_sequence_validation.py | 25 +++++++++++++++++++------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/tests/test-data/valid-read-testing.fq b/tests/test-data/valid-read-testing.fq index e52c058709..fc0b85ea41 100644 --- a/tests/test-data/valid-read-testing.fq +++ b/tests/test-data/valid-read-testing.fq @@ -1,32 +1,32 @@ -@895:1:1:1246:14654 1:N:0:NNNNN +@895:1:1:1246:14654 1:N:0:NNNNN 1 CAGGCGCCCACCACCGTGCCCTCCAACCTGATGGT + ][aaX__aa[`ZUZ[NONNFNNNNNO_____^RQ_ -@895:1:1:1248:9583 1:N:0:NNNNN +@895:1:1:1248:9583 1:N:0:NNNNN 2 ACTGGGCGTAGACGGTGTCCTCATCGGCACCAGC + \UJUWSSV[JQQWNP]]SZ]ZWU^]ZX][^TXR` -@895:1:1:1252:19493 1:N:0:NNNNN +@895:1:1:1252:19493 1:N:0:NNNNN 3 CCGGCGTGGTTGGTGAGGTCACTGAGCTTCATGTC + OOOKONNNNN__`R]O[TGTRSY[IUZ]]]__X__ -@895:1:1:1255:18861 1:N:0:NNNNN +@895:1:1:1255:18861 1:N:0:NNNNN 4 ACGACGAGAAGCTGATCTACCGCGCCGAGCGCATC + bb_^^bb_XTbbbbbb_bab]KTITZQTZ]ZYT^^ -@lowercase_to_uppercase +@lowercase_to_uppercase 5 caggcgcccaccaccgtgccctccaacctgatggt + ][aaX__aa[`ZUZ[NONNFNNNNNO_____^RQ_ -@n_in_read +@n_in_read 6 ACTGGGCGTAGNCGGTGTCCTCATCGGCACCAGC + \UJUWSSV[JQQWNP]]SZ]ZWU^]ZX][^TXR` -@zy_in_read +@zy_in_read 7 CCGGCGTGGTTZZYAGGTCACTGAGCTTCATGTC + OOOKONNNNN__`R]O[TGTRSY[IUZ]]]__X__ -@895:1:1:1255:18861 1:N:0:NNNNN +@895:1:1:1255:18861 1:N:0:NNNNN 8 ACGACGAGAAGCTGATCTACCGCGCCGAGCGCATC + bb_^^bb_XTbbbbbb_bab]KTITZQTZ]ZYT^^ diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index 2cd8340bf6..d650facb00 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -234,14 +234,15 @@ def test_read_cleaning_output_partitions(graphtype): print(read_names) assert len(read_names) == 4 - assert '895:1:1:1246:14654 1:N:0:NNNNN\t1' in read_names - assert '895:1:1:1248:9583 1:N:0:NNNNN\t2' in read_names - assert '895:1:1:1252:19493 1:N:0:NNNNN\t3' in read_names + print(read_names) + assert '895:1:1:1246:14654 1:N:0:NNNNN\t1\t1' in read_names + assert '895:1:1:1248:9583 1:N:0:NNNNN\t2\t2' in read_names + assert '895:1:1:1252:19493 1:N:0:NNNNN\t3\t3' in read_names - assert 'lowercase_to_uppercase\t1' in read_names + assert 'lowercase_to_uppercase\t5\t1' in read_names - assert 'n_in_read\t2' not in read_names - assert 'zy_in_read\t3' not in read_names + assert 'n_in_read\t6\t2' not in read_names + assert 'zy_in_read\t7\t3' not in read_names def test_read_cleaning_trim_on_stoptags(graphtype): @@ -284,5 +285,17 @@ def test_consume_seqfile_and_tag(graphtype): assert n_tags == 4 # total # of tags +def test_consume_partitioned_seqfile(graphtype): + infile = utils.get_test_data('valid-read-testing.fq') + savepath = utils.get_temp_filename('foo') + + # read this in consume_and_tag + x = graphtype(8, PRIMES_1m) + x.consume_partitioned_fasta(infile) + n_partitions, n_tags = x.count_partitions() + assert n_partitions == 4 + assert n_tags == 0 + + # vim: set filetype=python tabstop=4 softtabstop=4 shiftwidth=4 expandtab: # vim: set textwidth=79: From 85b8fa22e70da6e6941c18eaa46b55049d5e7c6d Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 18 Mar 2017 20:07:58 -0600 Subject: [PATCH 19/32] add test for output_partitions --- tests/test_sequence_validation.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index d650facb00..26218224ec 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -247,7 +247,6 @@ def test_read_cleaning_output_partitions(graphtype): def test_read_cleaning_trim_on_stoptags(graphtype): infile = utils.get_test_data('valid-read-testing.fq') - savepath = utils.get_temp_filename('foo') # read this in using "approved good" behavior w/cleaned_seq x = graphtype(8, PRIMES_1m) @@ -276,7 +275,6 @@ def test_read_cleaning_trim_on_stoptags(graphtype): def test_consume_seqfile_and_tag(graphtype): infile = utils.get_test_data('valid-read-testing.fq') - savepath = utils.get_temp_filename('foo') # read this in consume_and_tag x = graphtype(8, PRIMES_1m) @@ -287,7 +285,6 @@ def test_consume_seqfile_and_tag(graphtype): def test_consume_partitioned_seqfile(graphtype): infile = utils.get_test_data('valid-read-testing.fq') - savepath = utils.get_temp_filename('foo') # read this in consume_and_tag x = graphtype(8, PRIMES_1m) @@ -297,5 +294,28 @@ def test_consume_partitioned_seqfile(graphtype): assert n_tags == 0 +def test_output_partitioned_file(graphtype): + infile = utils.get_test_data('valid-read-testing.fq') + savepath = utils.get_temp_filename('foo') + + # read this in consume_and_tag + x = graphtype(8, PRIMES_1m) + x.consume_partitioned_fasta(infile) + x.output_partitions(infile, savepath) + + read_names = [read.name for read in ReadParser(savepath)] + read_names = set(read_names) + + good_names = ['895:1:1:1246:14654 1:N:0:NNNNN\t1\t5', + '895:1:1:1248:9583 1:N:0:NNNNN\t2\t2', + '895:1:1:1252:19493 1:N:0:NNNNN\t3\t3', + '895:1:1:1255:18861 1:N:0:NNNNN\t4\t8', + 'lowercase_to_uppercase\t5\t5', + '895:1:1:1255:18861 1:N:0:NNNNN\t8\t8'] + good_names = set(good_names) + + assert good_names == read_names + + # vim: set filetype=python tabstop=4 softtabstop=4 shiftwidth=4 expandtab: # vim: set textwidth=79: From f61e37ca582962030d451fc76b1f7c617399441e Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 18 Mar 2017 20:21:23 -0600 Subject: [PATCH 20/32] increase ksize to 15 for partition reading tests --- tests/test_sequence_validation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index 26218224ec..ecb14dd856 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -287,7 +287,7 @@ def test_consume_partitioned_seqfile(graphtype): infile = utils.get_test_data('valid-read-testing.fq') # read this in consume_and_tag - x = graphtype(8, PRIMES_1m) + x = graphtype(15, PRIMES_1m) x.consume_partitioned_fasta(infile) n_partitions, n_tags = x.count_partitions() assert n_partitions == 4 @@ -299,7 +299,7 @@ def test_output_partitioned_file(graphtype): savepath = utils.get_temp_filename('foo') # read this in consume_and_tag - x = graphtype(8, PRIMES_1m) + x = graphtype(15, PRIMES_1m) x.consume_partitioned_fasta(infile) x.output_partitions(infile, savepath) From b1519a3b07f0d903855860cad1ddb746d7ec19ec Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 18 Mar 2017 20:31:37 -0600 Subject: [PATCH 21/32] add tests for labelhash --- tests/test_sequence_validation.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index ecb14dd856..4d9633ce67 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -39,7 +39,7 @@ from __future__ import absolute_import from khmer import _Countgraph, _Counttable, _SmallCountgraph, _SmallCounttable from khmer import _Nodegraph, _Nodetable -from khmer import ReadParser, Nodegraph +from khmer import ReadParser, Nodegraph, _GraphLabels from . import khmer_tst_utils as utils import pytest @@ -317,5 +317,27 @@ def test_output_partitioned_file(graphtype): assert good_names == read_names +def test_consume_seqfile_and_tag_with_labels(graphtype): + infile = utils.get_test_data('valid-read-testing.fq') + + # read this in consume_and_tag + graph = graphtype(15, PRIMES_1m) + x = _GraphLabels(graph) + x.consume_seqfile_and_tag_with_labels(infile) + + assert x.n_labels() == 6 + + +def test_consume_partitioned_seqfile_and_label(graphtype): + infile = utils.get_test_data('valid-read-testing.fq') + + # read this in consume_and_tag + graph = graphtype(15, PRIMES_1m) + x = _GraphLabels(graph) + x.consume_partitioned_fasta_and_tag_with_labels(infile) + + assert x.n_labels() == 6 + + # vim: set filetype=python tabstop=4 softtabstop=4 shiftwidth=4 expandtab: # vim: set textwidth=79: From 08eca98bc3aa43cedfd9e9b9d5f1d512d7359d95 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 18 Mar 2017 23:07:45 -0600 Subject: [PATCH 22/32] uncomment pytest-runner req --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7fc8d91c8a..2c11f4d8b1 100755 --- a/setup.py +++ b/setup.py @@ -227,7 +227,7 @@ def check_for_openmp(): "packages": ['khmer', 'khmer.tests', 'oxli'], "package_dir": {'khmer.tests': 'tests'}, "install_requires": ['screed >= 0.9', 'bz2file'], -# "setup_requires": ["pytest-runner>=2.0,<3dev"], + "setup_requires": ["pytest-runner>=2.0,<3dev"], "extras_require": {':python_version=="2.6"': ['argparse>=1.2.1'], 'docs': ['sphinx', 'sphinxcontrib-autoprogram'], 'tests': ['pytest>=2.9'], From caa85b4ab02e4cc0b396d1a77773d5190ed419e4 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 18 Mar 2017 23:09:47 -0600 Subject: [PATCH 23/32] remove unnecessary imports --- tests/test_read_parsers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_read_parsers.py b/tests/test_read_parsers.py index a919bb5a00..4834cdcd78 100644 --- a/tests/test_read_parsers.py +++ b/tests/test_read_parsers.py @@ -38,7 +38,7 @@ from __future__ import print_function from __future__ import absolute_import from khmer import Read -from khmer import ReadParser, Counttable, Nodegraph +from khmer import ReadParser from screed import Record from . import khmer_tst_utils as utils import pytest From bf94884807d8b23ce4d9dff05f0e21dde96a2732 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 18 Mar 2017 23:10:18 -0600 Subject: [PATCH 24/32] remove line spacing --- tests/test_read_parsers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_read_parsers.py b/tests/test_read_parsers.py index 4834cdcd78..22cdf32ad7 100644 --- a/tests/test_read_parsers.py +++ b/tests/test_read_parsers.py @@ -483,6 +483,5 @@ def test_clean_seq(): clean = read.sequence.upper().replace("N", "A") assert clean == read.cleaned_seq - # vim: set filetype=python tabstop=4 softtabstop=4 shiftwidth=4 expandtab: # vim: set textwidth=79: From 15bc92c00614293c95f3390740a4270883f3385f Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 18 Mar 2017 22:18:32 -0700 Subject: [PATCH 25/32] distinguished tabletype from countingtype --- tests/test_sequence_validation.py | 34 ++++++++++++++----------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index 4d9633ce67..96d6ee30df 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -54,6 +54,13 @@ def tabletype(request): return request.param +# all the counting types! +@pytest.fixture(params=[_Countgraph, _Counttable, _SmallCountgraph, + _SmallCounttable]) +def countingtype(request): + return request.param + + # all the graph types! @pytest.fixture(params=[_Countgraph, _Nodegraph]) def graphtype(request): @@ -72,12 +79,10 @@ def reads(): # reads.close() -def test_read_cleaning_consume_seqfile(tabletype): +def test_read_cleaning_consume_seqfile(countingtype): infile = utils.get_test_data('valid-read-testing.fq') - if tabletype == _Nodegraph or tabletype == _Nodetable: - return - x = tabletype(15, PRIMES_1m) + x = countingtype(15, PRIMES_1m) x.consume_seqfile(infile) # the relevant read will automatically get uppercased => abundance of 2 @@ -93,11 +98,8 @@ def test_read_cleaning_consume_seqfile(tabletype): assert x.get(kmer) == 1 # this should be 2 in the future -def test_read_cleaning_consume_read_by_read(tabletype, reads): - if tabletype == _Nodegraph or tabletype == _Nodetable: - return - - x = tabletype(15, PRIMES_1m) +def test_read_cleaning_consume_read_by_read(countingtype, reads): + x = countingtype(15, PRIMES_1m) for read in reads: x.consume(read.sequence) # consume raw sequence @@ -117,11 +119,8 @@ def test_read_cleaning_consume_read_by_read(tabletype, reads): assert x.get(kmer) == 2 -def test_read_cleaning_consume_read_by_read_cleaned_seq(tabletype, reads): - if tabletype == _Nodegraph or tabletype == _Nodetable: - return - - x = tabletype(15, PRIMES_1m) +def test_read_cleaning_consume_read_by_read_cleaned_seq(countingtype, reads): + x = countingtype(15, PRIMES_1m) for read in reads: x.consume(read.cleaned_seq) # consume cleaned_seq @@ -138,13 +137,10 @@ def test_read_cleaning_consume_read_by_read_cleaned_seq(tabletype, reads): assert x.get(kmer) == 2 -def test_read_cleaning_abundance_distribution(tabletype): +def test_read_cleaning_abundance_distribution(countingtype): infile = utils.get_test_data('valid-read-testing.fq') - if tabletype == _Nodegraph or tabletype == _Nodetable: - return - - x = tabletype(15, PRIMES_1m) + x = countingtype(15, PRIMES_1m) y = _Nodegraph(15, PRIMES_1m) x.consume_seqfile(infile) From 6304e2f81cdc5e516ce6a03fdfbd7e45eedb074c Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sun, 19 Mar 2017 07:18:58 -0700 Subject: [PATCH 26/32] remove commented-out code --- tests/test_sequence_validation.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index 96d6ee30df..bd6e797ebd 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -75,8 +75,6 @@ def reads(): return reads finally: reads.close() -# yield reads -# reads.close() def test_read_cleaning_consume_seqfile(countingtype): From d2a20d8f7f335113cc64361fd27091e4c70c2dbe Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sun, 19 Mar 2017 07:20:56 -0700 Subject: [PATCH 27/32] add a test where bad DNA is at beginning of string --- tests/test-data/valid-read-testing.fq | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test-data/valid-read-testing.fq b/tests/test-data/valid-read-testing.fq index fc0b85ea41..91a1ff76f8 100644 --- a/tests/test-data/valid-read-testing.fq +++ b/tests/test-data/valid-read-testing.fq @@ -30,3 +30,7 @@ OOOKONNNNN__`R]O[TGTRSY[IUZ]]]__X__ ACGACGAGAAGCTGATCTACCGCGCCGAGCGCATC + bb_^^bb_XTbbbbbb_bab]KTITZQTZ]ZYT^^ +@bad_dna_in_beginning +YGAGCTGAGAGCTGAGAGCTGA ++ +bbbbbbbbbbbbbbbbbbbbbb From 86e70813f120049d5fdc75ffac9a1788df6d6bf6 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sun, 19 Mar 2017 07:31:09 -0700 Subject: [PATCH 28/32] write test for consume_partitioned_fasta on unpartitioned file --- lib/read_parsers.hh | 8 +++++--- tests/test_nodegraph.py | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/read_parsers.hh b/lib/read_parsers.hh index 2773b1ff67..6d8fcd2408 100644 --- a/lib/read_parsers.hh +++ b/lib/read_parsers.hh @@ -208,9 +208,11 @@ inline PartitionID _parse_partition_id(std::string name) if (*s == '\t') { p = (PartitionID) atoi(s + 1); } else { - std::cerr << "consume_partitioned_fasta barfed on read " - << name << "\n"; - throw khmer_exception(); + std::string err; + err = "consume_partitioned_fasta cannot find partition ID for read"; + err += name; + + throw khmer_value_exception(err); } return p; diff --git a/tests/test_nodegraph.py b/tests/test_nodegraph.py index 204d9a1b4b..774c2e962f 100644 --- a/tests/test_nodegraph.py +++ b/tests/test_nodegraph.py @@ -337,6 +337,14 @@ def test_load_partitioned(): assert nodegraph.get(third_s) +def test_consume_partitioned_fail(): + inpfile = utils.get_test_data('test-reads.fa') + nodegraph = khmer._Nodegraph(32, [1]) + + with pytest.raises(ValueError): + nodegraph.consume_partitioned_fasta(inpfile) + + def test_count_within_radius_simple(): inpfile = utils.get_test_data('all-A.fa') nodegraph = khmer._Nodegraph(4, [3, 5]) From f47a36096596e76363b81914347a490e8b2442d2 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sun, 19 Mar 2017 07:37:32 -0700 Subject: [PATCH 29/32] add space in reporting --- lib/read_parsers.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/read_parsers.hh b/lib/read_parsers.hh index 6d8fcd2408..04a9bdbfa9 100644 --- a/lib/read_parsers.hh +++ b/lib/read_parsers.hh @@ -209,7 +209,7 @@ inline PartitionID _parse_partition_id(std::string name) p = (PartitionID) atoi(s + 1); } else { std::string err; - err = "consume_partitioned_fasta cannot find partition ID for read"; + err = "consume_partitioned_fasta cannot find partition ID for read "; err += name; throw khmer_value_exception(err); From 7e9c7a0b0cab36a3a4d634126692ab0258cd41b3 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sun, 19 Mar 2017 07:44:24 -0700 Subject: [PATCH 30/32] add partition ID to new 'bad' sequence --- tests/test-data/valid-read-testing.fq | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-data/valid-read-testing.fq b/tests/test-data/valid-read-testing.fq index 91a1ff76f8..f2b8984e5a 100644 --- a/tests/test-data/valid-read-testing.fq +++ b/tests/test-data/valid-read-testing.fq @@ -30,7 +30,7 @@ OOOKONNNNN__`R]O[TGTRSY[IUZ]]]__X__ ACGACGAGAAGCTGATCTACCGCGCCGAGCGCATC + bb_^^bb_XTbbbbbb_bab]KTITZQTZ]ZYT^^ -@bad_dna_in_beginning +@bad_dna_in_beginning 9 YGAGCTGAGAGCTGAGAGCTGA + bbbbbbbbbbbbbbbbbbbbbb From e419a7bf203fb0135d92e319042a804d04b1c12f Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Mon, 20 Mar 2017 06:04:34 -0700 Subject: [PATCH 31/32] address review comments <- minor changes --- tests/test_sequence_validation.py | 69 +++++++++++++++---------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index bd6e797ebd..37b2ccc4f1 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -50,37 +50,34 @@ # all the table types! @pytest.fixture(params=[_Countgraph, _Counttable, _SmallCountgraph, _SmallCounttable, _Nodegraph, _Nodetable]) -def tabletype(request): +def Tabletype(request): return request.param # all the counting types! @pytest.fixture(params=[_Countgraph, _Counttable, _SmallCountgraph, _SmallCounttable]) -def countingtype(request): +def Countingtype(request): return request.param # all the graph types! @pytest.fixture(params=[_Countgraph, _Nodegraph]) -def graphtype(request): +def Graphtype(request): return request.param -@pytest.fixture +@pytest.yield_fixture def reads(): infile = utils.get_test_data('valid-read-testing.fq') reads = ReadParser(infile) - try: - return reads - finally: - reads.close() + yield reads -def test_read_cleaning_consume_seqfile(countingtype): +def test_read_cleaning_consume_seqfile(Countingtype): infile = utils.get_test_data('valid-read-testing.fq') - x = countingtype(15, PRIMES_1m) + x = Countingtype(15, PRIMES_1m) x.consume_seqfile(infile) # the relevant read will automatically get uppercased => abundance of 2 @@ -96,8 +93,8 @@ def test_read_cleaning_consume_seqfile(countingtype): assert x.get(kmer) == 1 # this should be 2 in the future -def test_read_cleaning_consume_read_by_read(countingtype, reads): - x = countingtype(15, PRIMES_1m) +def test_read_cleaning_consume_read_by_read(Countingtype, reads): + x = Countingtype(15, PRIMES_1m) for read in reads: x.consume(read.sequence) # consume raw sequence @@ -117,8 +114,8 @@ def test_read_cleaning_consume_read_by_read(countingtype, reads): assert x.get(kmer) == 2 -def test_read_cleaning_consume_read_by_read_cleaned_seq(countingtype, reads): - x = countingtype(15, PRIMES_1m) +def test_read_cleaning_consume_read_by_read_cleaned_seq(Countingtype, reads): + x = Countingtype(15, PRIMES_1m) for read in reads: x.consume(read.cleaned_seq) # consume cleaned_seq @@ -135,10 +132,10 @@ def test_read_cleaning_consume_read_by_read_cleaned_seq(countingtype, reads): assert x.get(kmer) == 2 -def test_read_cleaning_abundance_distribution(countingtype): +def test_read_cleaning_abundance_distribution(Countingtype): infile = utils.get_test_data('valid-read-testing.fq') - x = countingtype(15, PRIMES_1m) + x = Countingtype(15, PRIMES_1m) y = _Nodegraph(15, PRIMES_1m) x.consume_seqfile(infile) @@ -148,9 +145,9 @@ def test_read_cleaning_abundance_distribution(countingtype): assert dist[2] == 42 -def test_read_cleaning_trim_functions_lowercase(tabletype, reads): +def test_read_cleaning_trim_functions_lowercase(Tabletype, reads): # read this in using "approved good" behavior w/cleaned_seq - x = tabletype(8, PRIMES_1m) + x = Tabletype(8, PRIMES_1m) for read in reads: x.consume(read.cleaned_seq) # consume cleaned_seq @@ -165,9 +162,9 @@ def test_read_cleaning_trim_functions_lowercase(tabletype, reads): assert posns == [] # in future, should do same -def test_read_cleaning_trim_functions_N(tabletype, reads): +def test_read_cleaning_trim_functions_N(Tabletype, reads): # read this in using "approved good" behavior w/cleaned_seq - x = tabletype(8, PRIMES_1m) + x = Tabletype(8, PRIMES_1m) for read in reads: x.consume(read.cleaned_seq) # consume cleaned_seq @@ -183,9 +180,9 @@ def test_read_cleaning_trim_functions_N(tabletype, reads): # assert posns == [] # in future, should return [] -def test_read_cleaning_trim_functions_bad_dna(tabletype, reads): +def test_read_cleaning_trim_functions_bad_dna(Tabletype, reads): # read this in using "approved good" behavior w/cleaned_seq - x = tabletype(8, PRIMES_1m) + x = Tabletype(8, PRIMES_1m) for read in reads: x.consume(read.cleaned_seq) # consume cleaned_seq @@ -201,12 +198,12 @@ def test_read_cleaning_trim_functions_bad_dna(tabletype, reads): # assert posns == [] # in future, should return [11] -def test_read_cleaning_output_partitions(graphtype): +def test_read_cleaning_output_partitions(Graphtype): infile = utils.get_test_data('valid-read-testing.fq') savepath = utils.get_temp_filename('foo') # read this in using "approved good" behavior w/cleaned_seq - x = _Nodegraph(8, PRIMES_1m) + x = Graphtype(8, PRIMES_1m) for read in ReadParser(infile): x.consume(read.cleaned_seq) # consume cleaned_seq @@ -239,11 +236,11 @@ def test_read_cleaning_output_partitions(graphtype): assert 'zy_in_read\t7\t3' not in read_names -def test_read_cleaning_trim_on_stoptags(graphtype): +def test_read_cleaning_trim_on_stoptags(Graphtype): infile = utils.get_test_data('valid-read-testing.fq') # read this in using "approved good" behavior w/cleaned_seq - x = graphtype(8, PRIMES_1m) + x = Graphtype(8, PRIMES_1m) for read in ReadParser(infile): x.consume(read.cleaned_seq) # consume cleaned_seq @@ -267,33 +264,33 @@ def test_read_cleaning_trim_on_stoptags(graphtype): assert pos == 0 # should be 6 in future -def test_consume_seqfile_and_tag(graphtype): +def test_consume_seqfile_and_tag(Graphtype): infile = utils.get_test_data('valid-read-testing.fq') # read this in consume_and_tag - x = graphtype(8, PRIMES_1m) + x = Graphtype(8, PRIMES_1m) x.consume_seqfile_and_tag(infile) _, n_tags = x.count_partitions() assert n_tags == 4 # total # of tags -def test_consume_partitioned_seqfile(graphtype): +def test_consume_partitioned_seqfile(Graphtype): infile = utils.get_test_data('valid-read-testing.fq') # read this in consume_and_tag - x = graphtype(15, PRIMES_1m) + x = Graphtype(15, PRIMES_1m) x.consume_partitioned_fasta(infile) n_partitions, n_tags = x.count_partitions() assert n_partitions == 4 assert n_tags == 0 -def test_output_partitioned_file(graphtype): +def test_output_partitioned_file(Graphtype): infile = utils.get_test_data('valid-read-testing.fq') savepath = utils.get_temp_filename('foo') # read this in consume_and_tag - x = graphtype(15, PRIMES_1m) + x = Graphtype(15, PRIMES_1m) x.consume_partitioned_fasta(infile) x.output_partitions(infile, savepath) @@ -311,22 +308,22 @@ def test_output_partitioned_file(graphtype): assert good_names == read_names -def test_consume_seqfile_and_tag_with_labels(graphtype): +def test_consume_seqfile_and_tag_with_labels(Graphtype): infile = utils.get_test_data('valid-read-testing.fq') # read this in consume_and_tag - graph = graphtype(15, PRIMES_1m) + graph = Graphtype(15, PRIMES_1m) x = _GraphLabels(graph) x.consume_seqfile_and_tag_with_labels(infile) assert x.n_labels() == 6 -def test_consume_partitioned_seqfile_and_label(graphtype): +def test_consume_partitioned_seqfile_and_label(Graphtype): infile = utils.get_test_data('valid-read-testing.fq') # read this in consume_and_tag - graph = graphtype(15, PRIMES_1m) + graph = Graphtype(15, PRIMES_1m) x = _GraphLabels(graph) x.consume_partitioned_fasta_and_tag_with_labels(infile) From 3cb741bf6ec15fd762479a587ff573ceacb03ad0 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Mon, 20 Mar 2017 06:26:44 -0700 Subject: [PATCH 32/32] re-added reads.close to yield_fixture --- tests/test_sequence_validation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_sequence_validation.py b/tests/test_sequence_validation.py index 37b2ccc4f1..d3ac8af94e 100644 --- a/tests/test_sequence_validation.py +++ b/tests/test_sequence_validation.py @@ -72,6 +72,7 @@ def reads(): infile = utils.get_test_data('valid-read-testing.fq') reads = ReadParser(infile) yield reads + reads.close() def test_read_cleaning_consume_seqfile(Countingtype):