def test_interleaved_no_paired_output(): with temporary_path("temp-paired.1.fastq") as p1: with temporary_path("temp-paired.2.fastq") as p2: params = '-a XX --interleaved'.split() with redirect_stderr(): params += [ '-o', p1, '-p1', p2, 'paired.1.fastq', 'paired.2.fastq'] atropos.main(params)
def test_no_trimming_legacy(): # make sure that this doesn't divide by zero atropos.main([ '-a', 'XXXXX', '-o', '/dev/null', '-p', '/dev/null', '-pe1', datapath('paired.1.fastq'), '-pe2', datapath('paired.2.fastq') ])
def test_E3M(): '''Read the E3M dataset''' # not really colorspace, but a fasta/qual file pair main([ '-o', '/dev/null', '-se', datapath("E3M.fasta"), '-sq', datapath("E3M.qual") ])
def test_interleaved_no_paired_output(): with temporary_path("temp-paired.1.fastq") as p1: with temporary_path("temp-paired.2.fastq") as p2: params = '-a XX --interleaved'.split() with raises(SystemExit), redirect_stderr(): params += [ '-o', p1, '-p1', p2, 'paired.1.fastq', 'paired.2.fastq' ] atropos.main(params)
def test_second_too_short(): with temporary_path("truncated.2.fastq") as trunc2: # Create a truncated file in which the last read is missing with open(datapath('paired.2.fastq')) as f: lines = f.readlines() lines = lines[:-4] with open(trunc2, 'w') as f: f.writelines(lines) with redirect_stderr(): atropos.main('-a XX --paired-output out.fastq'.split() + [datapath('paired.1.fastq'), trunc2])
def test_second_too_short(): with temporary_path("truncated.2.fastq") as trunc2: # Create a truncated file in which the last read is missing with open(datapath('paired.2.fastq')) as f: lines = f.readlines() lines = lines[:-4] with open(trunc2, 'w') as f: f.writelines(lines) with raises(SystemExit), redirect_stderr(): atropos.main('-a XX --paired-output out.fastq'.split() + [datapath('paired.1.fastq'), trunc2])
def test_quiet_is_quiet(): captured_standard_output = StringIO() captured_standard_error = StringIO() try: old_stdout = sys.stdout old_stderr = sys.stderr sys.stdout = captured_standard_output sys.stderr = captured_standard_error atropos.main(['-o', '/dev/null', '--quiet', '-a', 'XXXX', '-se', datapath('illumina.fastq.gz')]) finally: sys.stdout = old_stdout sys.stderr = old_stderr assert captured_standard_output.getvalue() == '' assert captured_standard_error.getvalue() == ''
def run(params, expected, inpath, inpath2=None, qualfile=None, interleaved_input=False, interleaved_output=False): if type(params) is str: params = params.split() with temporary_path(expected) as tmp_fastaq: if interleaved_input: params += ['-l', inpath] elif inpath2: params += ['-pe1', datapath(inpath)] params += ['-pe2', datapath(inpath2)] else: params += ['-se', datapath(inpath)] if qualfile: params += ['-sq', datapath(qualfile)] if interleaved_output: params += ['-L', tmp_fastaq] else: params += ['-o', tmp_fastaq] # TODO not parallelizable print(params) result = atropos.main(params) assert isinstance(result, tuple) assert len(result) == 3 # TODO redirect standard output assert files_equal(cutpath(expected), tmp_fastaq)
def run_paired(params, in1, in2, expected1, expected2, aligners=('adapter', ), callback=None, assert_files_equal=True, error_on_rc=True): if type(params) is str: params = params.split() for aligner in aligners: with temporary_path('tmp1-' + expected1.format(aligner=aligner)) as p1: with temporary_path('tmp2-' + expected2.format(aligner=aligner)) as p2: p = params.copy() p += ['--aligner', aligner, '-o', p1, '-p', p2] p += [ '-pe1', datapath(in1.format(aligner=aligner)), '-pe2', datapath(in2.format(aligner=aligner)) ] result = atropos.main(p) assert isinstance(result, tuple) assert len(result) == 3 if error_on_rc: assert result[0] == 0, "Return code {} != 0".format( result[0]) if assert_files_equal: assert files_equal( cutpath(expected1.format(aligner=aligner)), p1) assert files_equal( cutpath(expected2.format(aligner=aligner)), p2) if callback: callback(aligner, p1, p2, result)
def run_interleaved(params, inpath, expected, aligners=('adapter',)): if type(params) is str: params = params.split() for aligner in aligners: with temporary_path(expected.format(aligner=aligner)) as tmp: p = params.copy() p += ['--aligner', aligner, '-l', datapath(inpath.format(aligner=aligner)), '-L', tmp] result = atropos.main(p) assert isinstance(result, tuple) assert len(result) == 3 assert files_equal(cutpath(expected.format(aligner=aligner)), tmp)
def test_demultiplex(): multiout = os.path.join(os.path.dirname(__file__), 'data', 'tmp-demulti.{name}.fasta') params = ['-a', 'first=AATTTCAGGAATT', '-a', 'second=GTTCTCTAGTTCT', '-o', multiout, '-se', datapath('twoadapters.fasta')] result = atropos.main(params) assert isinstance(result, tuple) assert len(result) == 3 assert result[0] == 0 assert files_equal(cutpath('twoadapters.first.fasta'), multiout.format(name='first')) assert files_equal(cutpath('twoadapters.second.fasta'), multiout.format(name='second')) assert files_equal(cutpath('twoadapters.unknown.fasta'), multiout.format(name='unknown')) os.remove(multiout.format(name='first')) os.remove(multiout.format(name='second')) os.remove(multiout.format(name='unknown'))
def run_interleaved(params, inpath, expected, aligners=('adapter', )): if type(params) is str: params = params.split() for aligner in aligners: with temporary_path(expected.format(aligner=aligner)) as tmp: p = params.copy() p += [ '--aligner', aligner, '-l', datapath(inpath.format(aligner=aligner)), '-L', tmp ] result = atropos.main(p) assert isinstance(result, tuple) assert len(result) == 3 assert files_equal(cutpath(expected.format(aligner=aligner)), tmp)
def test_unmatched_read_names(): with temporary_path("swapped.1.fastq") as swapped: try: # Create a file in which reads 2 and are swapped with open(datapath('paired.1.fastq')) as f: lines = f.readlines() lines = lines[0:4] + lines[8:12] + lines[4:8] + lines[12:] with open(swapped, 'w') as f: f.writelines(lines) with redirect_stderr(): result = atropos.main( '-a XX -o out1.fastq -p out2.fastq'.split() + ['-pe1', swapped, '-pe2', datapath('paired.2.fastq')]) assert isinstance(result, tuple) assert len(result) == 3 assert result[0] != 0 finally: os.remove('out1.fastq') os.remove('out2.fastq')
def run_paired(params, in1, in2, expected1, expected2, aligners=('adapter',), callback=None, assert_files_equal=True): if type(params) is str: params = params.split() for aligner in aligners: with temporary_path('tmp1-' + expected1.format(aligner=aligner)) as p1: with temporary_path('tmp2-' + expected2.format(aligner=aligner)) as p2: p = params.copy() p += ['--aligner', aligner, '-o', p1, '-p', p2] p += ['-pe1', datapath(in1.format(aligner=aligner)), '-pe2', datapath(in2.format(aligner=aligner))] result = atropos.main(p) assert isinstance(result, tuple) assert len(result) == 3 if assert_files_equal: assert files_equal(cutpath(expected1.format(aligner=aligner)), p1) assert files_equal(cutpath(expected2.format(aligner=aligner)), p2) if callback: callback(aligner, p1, p2, result)
def test_qualfile_only(): with redirect_stderr(): atropos.main(['-sq', datapath('E3M.qual')])
def test_no_trimming_legacy(): # make sure that this doesn't divide by zero atropos.main(['-a', 'XXXXX', '-o', '/dev/null', '-p', '/dev/null', '-pe1', datapath('paired.1.fastq'), '-pe2', datapath('paired.2.fastq')])
def test_missing_file(): with raises(SystemExit), redirect_stderr(): atropos.main([ '-a', 'XX', '--paired-output', 'out.fastq', datapath('paired.1.fastq') ])
def test_missing_file(): with redirect_stderr(): atropos.main(['-a', 'XX', '--paired-output', 'out.fastq', datapath('paired.1.fastq')])
def test_two_fastqs(): with redirect_stderr(): atropos.main(['-pe1', datapath('paired.1.fastq'), '-pe2', datapath('paired.2.fastq')])
def test_no_args(): with redirect_stderr(): result = atropos.main([]) assert isinstance(result, tuple) assert len(result) == 3 assert result[0] != 0
def test_E3M(): '''Read the E3M dataset''' # not really colorspace, but a fasta/qual file pair main(['-o', '/dev/null', '-se', datapath("E3M.fasta"), '-sq', datapath("E3M.qual")])