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'] cutadapt.main(params)
def test_no_trimming_legacy(): # make sure that this doesn't divide by zero cutadapt.main([ '-a', 'XXXXX', '-o', '/dev/null', '-p', '/dev/null', datapath('paired.1.fastq'), datapath('paired.2.fastq') ])
def test_second_too_short(): # paired-truncated.2.fastq is paired.2.fastq without the last read with redirect_stderr(): cutadapt.main( '-a XX --paired-output out.fastq'.split() + [datapath('paired.1.fastq'), datapath('paired-truncated.2.fastq')])
def test_unmatched_read_names(): # paired-swapped.1.fastq: paired.1.fastq with reads 2 and 3 swapped with redirect_stderr(): cutadapt.main( '-a XX --paired-output out.fastq'.split() + [datapath('paired-swapped.1.fastq'), datapath('paired.2.fastq')])
def run_interleaved(params, inpath1, inpath2=None, expected1=None, expected2=None): """ Interleaved input or output (or both) """ assert not (inpath1 and inpath2 and expected1 and expected2) assert not (expected2 and not expected1) assert not (inpath2 and not inpath1) if type(params) is str: params = params.split() params += ['--interleaved'] with temporary_path('tmp1-' + expected1) as tmp1: params += ['-o', tmp1] paths = [datapath(inpath1)] if inpath2: paths += [datapath(inpath2)] if expected2: with temporary_path('tmp2-' + expected2) as tmp2: params += ['-p', tmp2] assert cutadapt.main(params + paths) is None assert_files_equal(cutpath(expected2), tmp2) else: assert cutadapt.main(params + paths) is None assert_files_equal(cutpath(expected1), tmp1)
def test_second_too_short(): # paired-truncated.2.fastq is paired.2.fastq without the last read with redirect_stderr(): cutadapt.main( "-a XX --paired-output out.fastq".split() + [datapath("paired.1.fastq"), datapath("paired-truncated.2.fastq")] )
def test_interleaved_neither_nor(): """Option --interleaved used, but pairs of files given for input and 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'] cutadapt.main(params)
def test_unmatched_read_names(): with temporary_path("swapped.1.fastq") as swapped: # 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(): cutadapt.main('-a XX --paired-output out.fastq'.split() + [swapped, datapath('paired.2.fastq')])
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(): cutadapt.main('-a XX --paired-output out.fastq'.split() + [datapath('paired.1.fastq'), trunc2])
def test_interleaved_neither_nor(): """Option --interleaved used, but pairs of files given for input and 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' ] cutadapt.main(params)
def test_quiet_is_quiet(): captured_standard_output = StringIO() captured_standard_error = StringIO() old_stdout = sys.stdout old_stderr = sys.stderr try: sys.stdout = captured_standard_output sys.stderr = captured_standard_error cutadapt.main(['-o', '/dev/null', '--quiet', '-a', 'XXXX', datapath('illumina.fastq.gz')]) finally: sys.stdout = old_stdout sys.stderr = old_stderr assert captured_standard_output.getvalue() == '' assert captured_standard_error.getvalue() == ''
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 cutadapt.main(['-o', '/dev/null', '--quiet', '-a', 'XXXX', datapath('illumina.fastq.gz')]) finally: sys.stdout = old_stdout sys.stderr = old_stderr assert captured_standard_output.getvalue() == '' assert captured_standard_error.getvalue() == ''
def test_untrimmed_paired_output(): paired1 = datapath("paired.1.fastq") paired2 = datapath("paired.2.fastq") tmp1 = dpath("tmp-paired.1.fastq") tmp2 = dpath("tmp-paired.2.fastq") untrimmed1 = dpath("tmp-untrimmed.1.fastq") untrimmed2 = dpath("tmp-untrimmed.2.fastq") params = [ "--quiet", "-a", "TTAGACATAT", "-o", tmp1, "-p", tmp2, "--untrimmed-output", untrimmed1, "--untrimmed-paired-output", untrimmed2, paired1, paired2, ] assert cutadapt.main(params) is None assert files_equal(dpath(os.path.join("cut", "paired-untrimmed.1.fastq")), untrimmed1) assert files_equal(dpath(os.path.join("cut", "paired-untrimmed.2.fastq")), untrimmed2) assert files_equal(dpath(os.path.join("cut", "paired-trimmed.1.fastq")), tmp1) assert files_equal(dpath(os.path.join("cut", "paired-trimmed.2.fastq")), tmp2) os.remove(tmp1) os.remove(tmp2) os.remove(untrimmed1) os.remove(untrimmed2)
def run_interleaved(params, inpath, expected): if type(params) is str: params = params.split() with temporary_path("temp-interleaved.fastq") as tmp: params += ['--interleaved', '-o', tmp, datapath(inpath)] assert cutadapt.main(params) is None assert files_equal(cutpath(expected), tmp)
def test_paired_demultiplex(): tempdir = tempfile.mkdtemp(prefix='cutadapt-tests.') multiout1 = os.path.join(tempdir, 'demultiplexed.{name}.1.fastq') multiout2 = os.path.join(tempdir, 'demultiplexed.{name}.2.fastq') params = [ '-a', 'first=AACATTAGACA', '-a', 'second=CATTAGACATATCGG', '-A', 'ignored=CAGTGGAGTA', '-A', 'alsoignored=AATAACAGTGGAGTA', '-o', multiout1, '-p', multiout2, datapath('paired.1.fastq'), datapath('paired.2.fastq') ] assert cutadapt.main(params) is None assert_files_equal(cutpath('demultiplexed.first.1.fastq'), multiout1.format(name='first')) assert_files_equal(cutpath('demultiplexed.second.1.fastq'), multiout1.format(name='second')) assert_files_equal(cutpath('demultiplexed.unknown.1.fastq'), multiout1.format(name='unknown')) assert_files_equal(cutpath('demultiplexed.first.2.fastq'), multiout2.format(name='first')) assert_files_equal(cutpath('demultiplexed.second.2.fastq'), multiout2.format(name='second')) assert_files_equal(cutpath('demultiplexed.unknown.2.fastq'), multiout2.format(name='unknown')) shutil.rmtree(tempdir)
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, datapath("twoadapters.fasta")] assert cutadapt.main(params) is None 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 test_demultiplex(): multiout = os.path.join(os.path.dirname(__file__), 'data', 'tmp-demulti.{name}.fasta') params = ['-a', 'first=AATTTCAGGAATT', '-a', 'second=GTTCTCTAGTTCT', '-o', multiout, datapath('twoadapters.fasta')] assert cutadapt.main(params) is None 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_interleaved2(params, inpath, expected1, expected2): if type(params) is str: params = params.split() with temporary_path("temp-paired.1.fastq") as p1: with temporary_path("temp-paired.2.fastq") as p2: params += ['--interleaved', '-o', p1, '-p', p2] params += [datapath(inpath)] assert cutadapt.main(params) is None assert files_equal(cutpath(expected), p1) assert files_equal(cutpath(expected), p2)
def run_paired(params, in1, in2, expected1, expected2): if type(params) is str: params = params.split() with temporary_path("temp-paired.1.fastq") as p1: with temporary_path("temp-paired.2.fastq") as p2: params += ['-o', p1, '-p', p2] params += [datapath(in1), datapath(in2)] assert cutadapt.main(params) is None assert files_equal(cutpath(expected1), p1) assert files_equal(cutpath(expected2), p2)
def run_paired(params, in1, in2, expected1, expected2): if type(params) is str: params = params.split() with temporary_path('tmp1-' + expected1) as p1: with temporary_path('tmp2-' + expected2) as p2: params += ['-o', p1, '-p', p2] params += [datapath(in1), datapath(in2)] assert cutadapt.main(params) is None assert_files_equal(cutpath(expected1), p1) assert_files_equal(cutpath(expected2), p2)
def run(params, expected, inpath, inpath2=None): if type(params) is str: params = params.split() with temporary_path(expected) as tmp_fastaq: params += ['-o', tmp_fastaq] # TODO not parallelizable params += [datapath(inpath)] if inpath2: params += [datapath(inpath2)] assert cutadapt.main(params) is None # TODO redirect standard output assert_files_equal(cutpath(expected), tmp_fastaq)
def run_interleaved2(params, inpath, expected1, expected2): assert False # unused function if type(params) is str: params = params.split() with temporary_path('tmp1-' + expected1) as p1: with temporary_path('tmp2-' + expected2) as p2: params += ['--interleaved', '-o', p1, '-p', p2] params += [datapath(inpath)] assert cutadapt.main(params) is None assert files_equal(cutpath(expected), p1) assert files_equal(cutpath(expected), p2)
def run(params, expected, inpath, inpath2=None): if type(params) is str: params = params.split() with temporary_path('tmp.fastaq') as tmp_fastaq: params += ['-o', tmp_fastaq ] # TODO not parallelizable params += [ datapath(inpath) ] if inpath2: params += [ datapath(inpath2) ] assert cutadapt.main(params) is None # TODO redirect standard output assert files_equal(cutpath(expected), tmp_fastaq)
def run(params, expected, inpath, inpath2=None): if type(params) is str: params = params.split() params += ['-o', dpath('tmp.fastaq')] # TODO not parallelizable params += [datapath(inpath)] if inpath2: params += [datapath(inpath2)] assert cutadapt.main(params) is None # TODO redirect standard output diff(dpath(os.path.join('cut', expected)), dpath('tmp.fastaq')) os.remove(dpath('tmp.fastaq'))
def run(params, expected, inpath, inpath2=None): if type(params) is str: params = params.split() params += ['-o', dpath('tmp.fastaq') ] # TODO not parallelizable params += [ datapath(inpath) ] if inpath2: params += [ datapath(inpath2) ] assert cutadapt.main(params) == 0 # TODO redirect standard output diff(dpath(os.path.join('cut', expected)), dpath('tmp.fastaq')) os.remove(dpath('tmp.fastaq'))
def run(params, expected, inpath, inpath2=None): if type(params) is str: params = params.split() # params = ['--quiet'] + params params += ["-o", dpath("tmp.fastaq")] # TODO not parallelizable params += [datapath(inpath)] if inpath2: params += [datapath(inpath2)] assert cutadapt.main(params) is None # TODO redirect standard output assert files_equal(dpath(os.path.join("cut", expected)), dpath("tmp.fastaq")) os.remove(dpath("tmp.fastaq"))
def run_interleaved(params, inpath1, inpath2=None, expected1=None, expected2=None): """ Interleaved input or output (or both) """ assert not (inpath1 and inpath2 and expected1 and expected2) assert not (expected2 and not expected1) assert not (inpath2 and not inpath1) if type(params) is str: params = params.split() params += ['--interleaved'] with temporary_path('tmp1-' + expected1) as tmp1: params += ['-o', tmp1] paths = [datapath(inpath1)] if inpath2: paths += [datapath(inpath2)] if expected2: with temporary_path('tmp2-' + expected2) as tmp2: params += ['-p', tmp2] assert cutadapt.main(params + paths) is None assert files_equal(cutpath(expected2), tmp2) else: assert cutadapt.main(params + paths) is None assert files_equal(cutpath(expected1), tmp1)
def test_demultiplex(): tempdir = tempfile.mkdtemp(prefix='cutadapt-tests.') multiout = os.path.join(tempdir, 'tmp-demulti.{name}.fasta') params = [ '-a', 'first=AATTTCAGGAATT', '-a', 'second=GTTCTCTAGTTCT', '-o', multiout, datapath('twoadapters.fasta') ] assert cutadapt.main(params) is None 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')) shutil.rmtree(tempdir)
def test_untrimmed_paired_output(): with temporary_path("tmp-paired.1.fastq") as tmp1: with temporary_path("tmp-paired.2.fastq") as tmp2: with temporary_path("tmp-untrimmed.1.fastq") as untrimmed1: with temporary_path("tmp-untrimmed.2.fastq") as untrimmed2: params = [ '-a', 'TTAGACATAT', '-o', tmp1, '-p', tmp2, '--untrimmed-output', untrimmed1, '--untrimmed-paired-output', untrimmed2, datapath('paired.1.fastq'), datapath('paired.2.fastq') ] assert cutadapt.main(params) is None assert files_equal(cutpath('paired-untrimmed.1.fastq'), untrimmed1) assert files_equal(cutpath('paired-untrimmed.2.fastq'), untrimmed2) assert files_equal(cutpath('paired-trimmed.1.fastq'), tmp1) assert files_equal(cutpath('paired-trimmed.2.fastq'), tmp2)
def test_untrimmed_paired_output(): paired1 = datapath('paired.1.fastq') paired2 = datapath('paired.2.fastq') tmp1 = dpath("tmp-paired.1.fastq") tmp2 = dpath("tmp-paired.2.fastq") untrimmed1 = dpath("tmp-untrimmed.1.fastq") untrimmed2 = dpath("tmp-untrimmed.2.fastq") params = ['--quiet', '-a', 'TTAGACATAT', '-o', tmp1, '-p', tmp2, '--untrimmed-output', untrimmed1, '--untrimmed-paired-output', untrimmed2, paired1, paired2] assert cutadapt.main(params) is None assert files_equal(dpath(os.path.join('cut', 'paired-untrimmed.1.fastq')), untrimmed1) assert files_equal(dpath(os.path.join('cut', 'paired-untrimmed.2.fastq')), untrimmed2) assert files_equal(dpath(os.path.join('cut', 'paired-trimmed.1.fastq')), tmp1) assert files_equal(dpath(os.path.join('cut', 'paired-trimmed.2.fastq')), tmp2) os.remove(tmp1) os.remove(tmp2) os.remove(untrimmed1) os.remove(untrimmed2)
def test_anywhere_anchored_3p(): with redirect_stderr(): cutadapt.main(['-b', 'TTT$', datapath('small.fastq')])
def test_E3M(): '''Read the E3M dataset''' # not really colorspace, but a fasta/qual file pair main(['-o', '/dev/null', datapath("E3M.fasta"), datapath("E3M.qual")])
def test_missing_file(): with redirect_stderr(): cutadapt.main(['-a', 'XX', '--paired-output', 'out.fastq', datapath('paired.1.fastq')])
def test_paired_end_missing_file(): cutadapt.main([ '-a', 'XX', '--paired-output', 'out.fastq', datapath('paired.1.fastq') ])
def test_two_fastqs(): with redirect_stderr(): cutadapt.main([datapath('paired.1.fastq'), datapath('paired.2.fastq')])
def test_paired_but_only_one_input_file(): """Option -p given but only one input file""" cutadapt.main('-a XX -o /dev/null -p /dev/null'.split() + [datapath('paired.1.fastq')])
def test_p_without_o(): """Option -p given but -o missing""" cutadapt.main('-a XX -p /dev/null'.split() + [datapath('paired.1.fastq'), datapath('paired.2.fastq')])
def test_no_args(): with redirect_stderr(): cutadapt.main([])
def test_qualfile_only(): with redirect_stderr(): cutadapt.main(['file.qual'])
def test_unmatched_read_names(): # paired-swapped.1.fastq: paired.1.fastq with reads 2 and 3 swapped with redirect_stderr(): cutadapt.main( "-a XX --paired-output out.fastq".split() + [datapath("paired-swapped.1.fastq"), datapath("paired.2.fastq")] )
#!/usr/bin/env python # coding: utf-8 from __future__ import print_function, division, absolute_import import sys try: import _preamble except ImportError: pass from cutadapt.scripts import cutadapt cutadapt.main()
def test_linked_anywhere(): with redirect_stderr(): cutadapt.main(['-b', 'AAA...TTT', datapath('linked.fasta')])
def test_paired_end_missing_file(): cutadapt.main(['-a', 'XX', '--paired-output', 'out.fastq', datapath('paired.1.fastq')])
def test_missing_file(): with redirect_stderr(): cutadapt.main([ '-a', 'XX', '--paired-output', 'out.fastq', datapath('paired.1.fastq') ])
def test_paired_end_missing_file(): with redirect_stderr(): cutadapt.main(["-a", "XX", "--paired-output", "out.fastq", datapath("paired.1.fastq")])
def test_first_too_short(): # paired-truncated.1.fastq is paired.1.fastq without the last read with redirect_stderr(): cutadapt.main('-a XX --paired-output out.fastq'.split() + [datapath('paired-truncated.1.fastq'), datapath('paired.2.fastq')])
def test_non_iupac_characters(): with redirect_stderr(): cutadapt.main(['-a', 'ZACGT', datapath('small.fastq')])
def test_no_trimming(): # make sure that this doesn't divide by zero cutadapt.main(['-a', 'XXXXX', '-A', 'XXXXX', '-o', '/dev/null', '-p', '/dev/null', datapath('paired.1.fastq'), datapath('paired.2.fastq')])
def test_no_args(): with redirect_stderr(): cutadapt.main()
def test_no_trimming(): # make sure that this doesn't divide by zero cutadapt.main( ["-a", "XXXXX", "-o", "/dev/null", "-p", "/dev/null", datapath("paired.1.fastq"), datapath("paired.2.fastq")] )