예제 #1
0
def run_interleaved(params,
                    inpath1,
                    inpath2=None,
                    expected1=None,
                    expected2=None,
                    cores=1):
    """
	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', '--cores', str(cores), '--buffer-size=512']
    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 main(params + paths) is None
                assert_files_equal(cutpath(expected2), tmp2)
        else:
            assert main(params + paths) is None
        assert_files_equal(cutpath(expected1), tmp1)
예제 #2
0
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']
				with pytest.raises(SystemExit):
					main(params)
예제 #3
0
def run_paired(params, in1, in2, expected1, expected2, cores):
    if type(params) is str:
        params = params.split()
    params += ['--cores', str(cores), '--buffer-size=512']
    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 main(params) is None
            assert_files_equal(cutpath(expected1), p1)
            assert_files_equal(cutpath(expected2), p2)
예제 #4
0
def test_explicit_format_with_paired():
    # Use --format=fastq with input files whose extension is .txt
    with temporary_path("paired.1.txt") as txt1:
        with temporary_path("paired.2.txt") as txt2:
            shutil.copyfile(datapath("paired.1.fastq"), txt1)
            shutil.copyfile(datapath("paired.2.fastq"), txt2)
            run_paired('--format=fastq -a TTAGACATAT -m 14',
                       in1=txt1,
                       in2=txt2,
                       expected1='paired.m14.1.fastq',
                       expected2='paired.m14.2.fastq',
                       cores=1)
예제 #5
0
def test_too_long_output():
    with temporary_path('temp-too-long.1.fastq') as p1:
        with temporary_path('temp-too-long.2.fastq') as p2:
            run_paired('-a TTAGACATAT -A CAGTGGAGTA -M 14 --too-long-output '
                       '{0} --too-long-paired-output {1}'.format(p1, p2),
                       in1='paired.1.fastq',
                       in2='paired.2.fastq',
                       expected1='paired-too-short.1.fastq',
                       expected2='paired-too-short.2.fastq',
                       cores=1)
            assert_files_equal(cutpath('paired.1.fastq'), p1)
            assert_files_equal(cutpath('paired.2.fastq'), p2)
예제 #6
0
def test_untrimmed_paired_output():
	with temporary_path("tmp-untrimmed.1.fastq") as untrimmed1:
		with temporary_path("tmp-untrimmed.2.fastq") as untrimmed2:
			run_paired(
				['-a', 'TTAGACATAT',
					'--untrimmed-output', untrimmed1,
					'--untrimmed-paired-output', untrimmed2],
				in1='paired.1.fastq', in2='paired.2.fastq',
				expected1='paired-trimmed.1.fastq', expected2='paired-trimmed.2.fastq',
				cores=1
			)
			assert_files_equal(cutpath('paired-untrimmed.1.fastq'), untrimmed1)
			assert_files_equal(cutpath('paired-untrimmed.2.fastq'), untrimmed2)
예제 #7
0
def test_paired_end_legacy():
    '''--paired-output, no -A/-B/-G'''
    with temporary_path("paired-tmp.fastq") as pairedtmp:
        # the -m 14 filters out one read, which should then also be filtered out in the second output file
        run(['-a', 'TTAGACATAT', '-m', '14', '--paired-output', pairedtmp],
            'paired.m14.1.fastq', 'paired.1.fastq', 'paired.2.fastq')
        assert files_equal(cutpath('paired.m14.2.fastq'), pairedtmp)
예제 #8
0
def test_info_file():
    with temporary_path("infotmp.txt") as infotmp:
        run([
            "--info-file", infotmp, '-a',
            'adapt=GCCGAACTTCTTAGACTGCCTTAAGGACGT'
        ], "illumina.fastq", "illumina.fastq.gz")
        assert files_equal(cutpath('illumina.info.txt'), infotmp)
예제 #9
0
def test_info_file_times():
    with temporary_path("infotmp.txt") as infotmp:
        run([
            "--info-file", infotmp, '--times', '2', '-a',
            'adapt=GCCGAACTTCTTA', '-a', 'adapt2=GACTGCCTTAAGGACGT'
        ], "illumina5.fastq", "illumina5.fastq")
        assert_files_equal(cutpath('illumina5.info.txt'), infotmp)
예제 #10
0
def test_info_file_fasta():
    with temporary_path("infotmp.txt") as infotmp:
        # Just make sure that it runs
        run([
            '--info-file', infotmp, '-a', 'TTAGACATAT', '-g', 'GAGATTGCCA',
            '--no-indels'
        ], 'no_indels.fasta', 'no_indels.fasta')
예제 #11
0
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)
예제 #12
0
def test_too_short_output_paired_option_missing():
    with temporary_path('temp-too-short.1.fastq') as p1:
        run_paired('-a TTAGACATAT -A CAGTGGAGTA -m 14 --too-short-output '
                   '{0}'.format(p1),
                   in1='paired.1.fastq',
                   in2='paired.2.fastq',
                   expected1='paired.1.fastq',
                   expected2='paired.2.fastq',
                   cores=1)
예제 #13
0
def test_info_file():
    # The true adapter sequence in the illumina.fastq.gz data set is
    # GCCTAACTTCTTAGACTGCCTTAAGGACGT (fourth base is different)
    #
    with temporary_path("infotmp.txt") as infotmp:
        run([
            "--info-file", infotmp, '-a',
            'adapt=GCCGAACTTCTTAGACTGCCTTAAGGACGT'
        ], "illumina.fastq", "illumina.fastq.gz")
        assert_files_equal(cutpath('illumina.info.txt'), infotmp)
예제 #14
0
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)
예제 #15
0
def test_adapter_wildcard():
	'''wildcards in adapter'''
	for adapter_type, expected in (
			("-a", "wildcard_adapter.fa"),
			("-b", "wildcard_adapter_anywhere.fa")):
		with temporary_path("wildcardtmp.txt") as wildcardtmp:
			run("--wildcard-file {0} {1} ACGTNNNACGT".format(wildcardtmp, adapter_type),
				expected, "wildcard_adapter.fa")
			with open(wildcardtmp) as wct:
				lines = wct.readlines()
			lines = [ line.strip() for line in lines ]
			assert lines == ['AAA 1', 'GGG 2', 'CCC 3b', 'TTT 4b']
예제 #16
0
def test_second_too_short(cores):
    with pytest.raises(SystemExit):
        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():
                main('-a XX -o /dev/null --paired-output out.fastq'.split() +
                     ['--cores', str(cores)] +
                     [datapath('paired.1.fastq'), trunc2])
예제 #17
0
def test_adapter_wildcard():
    """wildcards in adapter"""
    for adapter_type, expected in (("-a", "wildcard_adapter.fa"),
                                   ("-b", "wildcard_adapter_anywhere.fa")):
        with temporary_path("wildcardtmp.txt") as wildcardtmp:
            run(
                "--wildcard-file {0} {1} ACGTNNNACGT".format(
                    wildcardtmp, adapter_type), expected,
                "wildcard_adapter.fa")
            with open(wildcardtmp) as wct:
                lines = wct.readlines()
            lines = [line.strip() for line in lines]
            assert lines == ['AAA 1', 'GGG 2', 'CCC 3b', 'TTT 4b']
예제 #18
0
def test_unmatched_read_names(cores):
    with pytest.raises(SystemExit):
        with temporary_path("swapped.1.fastq") as swapped:
            # Create a file in which reads 2 and 1 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():
                main('-a XX -o out1.fastq --paired-output out2.fastq'.split() +
                     ['--cores', str(cores)] +
                     [swapped, datapath('paired.2.fastq')])
예제 #19
0
def test_info_file():
	with temporary_path("infotmp.txt") as infotmp:
		run(["--info-file", infotmp, '-a', 'adapt=GCCGAACTTCTTAGACTGCCTTAAGGACGT'], "illumina.fastq", "illumina.fastq.gz")
		assert files_equal(cutpath('illumina.info.txt'), infotmp)
예제 #20
0
def test_rest():
	'''-r/--rest-file'''
	with temporary_path('rest.tmp') as rest_tmp:
		run(['-b', 'ADAPTER', '-N', '-r', rest_tmp], "rest.fa", "rest.fa")
		assert files_equal(datapath('rest.txt'), rest_tmp)
예제 #21
0
def test_paired_end_legacy():
	'''--paired-output, no -A/-B/-G'''
	with temporary_path("paired-tmp.fastq") as pairedtmp:
		# the -m 14 filters out one read, which should then also be filtered out in the second output file
		run(['-a', 'TTAGACATAT', '-m', '14', '--paired-output', pairedtmp], 'paired.m14.1.fastq', 'paired.1.fastq', 'paired.2.fastq')
		assert files_equal(cutpath('paired.m14.2.fastq'), pairedtmp)
예제 #22
0
def test_restfront():
    with temporary_path("rest.txt") as path:
        run(['-g', 'ADAPTER', '-N', '-r', path], "restfront.fa", "rest.fa")
        assert_files_equal(datapath('restfront.txt'), path)
예제 #23
0
def test_untrimmed_output():
	with temporary_path('untrimmed.tmp.fastq') as tmp:
		run(['-a', 'TTAGACATATCTCCGTCG', '--untrimmed-output', tmp], 'small.trimmed.fastq', 'small.fastq')
		assert files_equal(cutpath('small.untrimmed.fastq'), tmp)
예제 #24
0
def test_rest():
    """-r/--rest-file"""
    with temporary_path('rest.tmp') as rest_tmp:
        run(['-b', 'ADAPTER', '-N', '-r', rest_tmp], "rest.fa", "rest.fa")
        assert_files_equal(datapath('rest.txt'), rest_tmp)
예제 #25
0
def test_untrimmed_output():
    with temporary_path('untrimmed.tmp.fastq') as tmp:
        run(['-a', 'TTAGACATATCTCCGTCG', '--untrimmed-output', tmp],
            'small.trimmed.fastq', 'small.fastq')
        assert_files_equal(cutpath('small.untrimmed.fastq'), tmp)
예제 #26
0
def test_restfront():
	with temporary_path("rest.txt") as path:
		run(['-g', 'ADAPTER', '-N', '-r', path], "restfront.fa", "rest.fa")
		assert files_equal(datapath('restfront.txt'), path)
예제 #27
0
def test_explicit_format_with_paired():
	with temporary_path("paired-tmp.fastq") as pairedtmp:
		run(['--format=fastq', '-a', 'TTAGACATAT', '-m', '14', '-p', pairedtmp], 'paired.m14.1.fastq', 'paired.1.txt', 'paired.2.txt')
		assert files_equal(cutpath('paired.m14.2.fastq'), pairedtmp)
예제 #28
0
def test_explicit_format_with_paired():
    with temporary_path("paired-tmp.fastq") as pairedtmp:
        run([
            '--format=fastq', '-a', 'TTAGACATAT', '-m', '14', '-p', pairedtmp
        ], 'paired.m14.1.fastq', 'paired.1.txt', 'paired.2.txt')
        assert files_equal(cutpath('paired.m14.2.fastq'), pairedtmp)
예제 #29
0
def test_issue_46():
    """issue 46 - IndexError with --wildcard-file"""
    with temporary_path("wildcardtmp.txt") as wildcardtmp:
        run("--anywhere=AACGTN --wildcard-file={0}".format(wildcardtmp),
            "issue46.fasta", "issue46.fasta")
예제 #30
0
def test_issue_46():
	'''issue 46 - IndexError with --wildcard-file'''
	with temporary_path("wildcardtmp.txt") as wildcardtmp:
		run("--anywhere=AACGTN --wildcard-file={0}".format(wildcardtmp), "issue46.fasta", "issue46.fasta")