# Path: cutadapt-1.12/tests/utils.py
# 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)
# 	# TODO diff log files
# 
# def files_equal(path1, path2):
# 	return os.system("diff -u {0} {1}".format(path1, path2)) == 0
# 
# def datapath(path):
# 	return os.path.join(os.path.dirname(__file__), 'data', path)
# 
# def cutpath(path):
# 	return os.path.join(os.path.dirname(__file__), 'cut', path)
# 
# @contextmanager
# def redirect_stderr():
# 	"Send stderr to stdout. Nose doesn't capture stderr, yet."
# 	old_stderr = sys.stderr
# 	sys.stderr = sys.stdout
# 	yield
# 	sys.stderr = old_stderr
# 
# @contextmanager
# def temporary_path(name):
# 	directory = os.path.join(os.path.dirname(__file__), 'testtmp')
# 	if not os.path.isdir(directory):
# 		os.mkdir(directory)
# 	path = os.path.join(directory, name)
# 	yield path
# 	os.remove(path)


import shutil
from nose.tools import raises
from cutadapt.scripts import cutadapt
from .utils import run, files_equal, datapath, cutpath, redirect_stderr, temporary_path
			assert cutadapt.main(params + paths) is None
		assert files_equal(cutpath(expected1), tmp1)


def test_paired_separate():
	'''test separate trimming of paired-end reads'''
	run('-a TTAGACATAT', 'paired-separate.1.fastq', 'paired.1.fastq')
	run('-a CAGTGGAGTA', 'paired-separate.2.fastq', 'paired.2.fastq')


def test_paired_end_legacy():
	'''--paired-output, not using -A/-B/-G'''
	# the -m 14 filters out one read, which should then also be filtered out in the second output file
	# -q 10 should not change anything: qualities in file 1 are high enough,
	# qualities in file 2 should not be inspected.
	run_paired('-a TTAGACATAT -m 14 -q 10',
		in1='paired.1.fastq', in2='paired.2.fastq',
		expected1='paired.m14.1.fastq', expected2='paired.m14.2.fastq'
	)


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'
			)

# Path: cutadapt-1.12/tests/utils.py
# 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)
# 	# TODO diff log files
# 
# def files_equal(path1, path2):
# 	return os.system("diff -u {0} {1}".format(path1, path2)) == 0
# 
# def datapath(path):
# 	return os.path.join(os.path.dirname(__file__), 'data', path)
# 
# def cutpath(path):
# 	return os.path.join(os.path.dirname(__file__), 'cut', path)
# 
# @contextmanager
# def redirect_stderr():
# 	"Send stderr to stdout. Nose doesn't capture stderr, yet."
# 	old_stderr = sys.stderr
# 	sys.stderr = sys.stdout
# 	yield
# 	sys.stderr = old_stderr
# 
# @contextmanager
# def temporary_path(name):
# 	directory = os.path.join(os.path.dirname(__file__), 'testtmp')
# 	if not os.path.isdir(directory):
# 		os.mkdir(directory)
# 	path = os.path.join(directory, name)
# 	yield path
# 	os.remove(path)


# Path: cutadapt-1.12/tests/testpaired.py
import shutil
from nose.tools import raises
from cutadapt.scripts import cutadapt
from .utils import run, files_equal, datapath, cutpath, redirect_stderr, temporary_path

			assert cutadapt.main(params + paths) is None
		assert files_equal(cutpath(expected1), tmp1)


def test_paired_separate():
	'''test separate trimming of paired-end reads'''
	run('-a TTAGACATAT', 'paired-separate.1.fastq', 'paired.1.fastq')
	run('-a CAGTGGAGTA', 'paired-separate.2.fastq', 'paired.2.fastq')


def test_paired_end_legacy():
	'''--paired-output, not using -A/-B/-G'''
	# the -m 14 filters out one read, which should then also be filtered out in the second output file
	# -q 10 should not change anything: qualities in file 1 are high enough,
	# qualities in file 2 should not be inspected.
	run_paired('-a TTAGACATAT -m 14 -q 10',
		in1='paired.1.fastq', in2='paired.2.fastq',
		expected1='paired.m14.1.fastq', expected2='paired.m14.2.fastq'
	)


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'
			)

			assert files_equal(cutpath('paired-untrimmed.1.fastq'), untrimmed1)