def test_quality_raises_on_0_return(new_pipegraph): with pytest.raises(ValueError): fastq2.QualityFilter(lambda qual, seq: 0).generate_aligner_input( "test.fastq", [str(get_sample_data(Path("mbf_align/sample_a/a.fastq")))], False, )
def test_quality_filter_depends_on_function_invariant(new_pipegraph): def f(qual, seq): return True x = fastq2.QualityFilter(f) deps = x.get_dependencies("test.fastq") assert isinstance(deps[0], ppg.FunctionInvariant) assert deps[0].function is f
def test_quality_filter_positive_integer(self): test = b"""@SEQ_ID_1 AATTTGGGGTTCAAAGCAGTATCGATCAAATAGTAAATCCATTTGTTCAACTCACAGTTT + AcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA @SEQ_ID_2 TATTTGGGGTTCAAAGCAGTATCGATCAAATAGTAAATCCATTTGTTCAACTCACAGTTT + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA @SEQ_ID_3 AAAATGGGGTTCAAAGCAGTATCGATCAAATAGTAAATCCATTTGTTCAACTCACAGTTT + BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB @SEQ_ID_4 CATTTGGGGTTCAAAGCAGTATCGATCAAATAGTAAATCCATTTGTTCAACTCACAGTTT + CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCA """ should = b"""@SEQ_ID_1 AATTT + AcAAA @SEQ_ID_3 AAAAT + BBBBB """ try: with open("test_quality_filter_positive_integer.fastq", "wb") as op: op.write(test) def f(qual, seq): if seq.startswith(b"A"): # keep the first 5 bases return 5 else: return False x = fastq2.QualityFilter(f) x.generate_aligner_input( "test_quality_filter_positive_integer.out.fastq", ["test_quality_filter_positive_integer.fastq"], False, ) with open("test_quality_filter_positive_integer.out.fastq", "rb") as op: was = op.read() assert should == was finally: if os.path.exists( "test_quality_filter_positive_integer.out.fastq"): os.unlink("test_quality_filter_positive_integer.out.fastq")
def test_quality_filter_tuple(self): test = b"""@SEQ_ID_1 AATTTGGGGTTCAAAGCAGTATCGATCAAATAGTAAATCCATTTGTTCAACTCACAGTTT + AcAAAAghAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA @SEQ_ID_2 TATTTGGGGTTCAAAGCAGTATCGATCAAATAGTAAATCCATTTGTTCAACTCACAGTTT + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA @SEQ_ID_3 AAAATGGGGTTCAAAGCAGTATCGATCAAATAGTAAATCCATTTGTTCAACTCACAGTTT + BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBcBBBBB @SEQ_ID_4 CATTTGGGGTTCAAAGCAGTATCGATCAAATAGTAAATCCATTTGTTCAACTCACAGTTT + CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCA """ should = b"""@SEQ_ID_1 GGGTTCAAAGCAGTATCGATCAAATAGTAAATCCATTTGTTCAACTCAC + ghAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA @SEQ_ID_3 GGGTTCAAAGCAGTATCGATCAAATAGTAAATCCATTTGTTCAACTCAC + BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBc """ try: with open("test_quality_filter_tuple.fastq", "wb") as op: op.write(test) def f(qual, seq): if seq.startswith(b"A"): return (6, -5) else: return False x = fastq2.QualityFilter(f) x.generate_aligner_input( "test_quality_filter_tuple.out.fastq", ["test_quality_filter_tuple.fastq"], False, ) with open("test_quality_filter_tuple.out.fastq", "rb") as op: was = op.read() assert should == was finally: if os.path.exists("test_quality_filter_tuple.out.fastq"): os.unlink("test_quality_filter_tuple.out.fastq")
def test_read_creator_must_be_fastq_right_now(new_pipegraph): with pytest.raises(ValueError): fastq2.Straight().generate_aligner_input( "test.fastq", [str(get_sample_data(Path("mbf_align/sample_a)/a.fastq")))], False, "fail", ) with pytest.raises(ValueError): fastq2.Filtered(lambda seq, qual, name: True).generate_aligner_input( "test.fastq", [str(get_sample_data(Path("mbf_align/sample_a)/a.fastq")))], False, "fail", ) with pytest.raises(ValueError): fastq2.QualityFilter(lambda qual, seq: True).generate_aligner_input( "test.fastq", [str(get_sample_data(Path("mbf_align/sample_a)/a.fastq")))], False, "fail", )