def test_generator_to_fastq_no_qual(self): def gen(): yield BiologicalSequence('ACGT', id='foo', description='bar', quality=range(4)) yield BiologicalSequence('ACG', id='foo', description='bar') with self.assertRaisesRegexp(ValueError, '2nd.*quality scores'): _generator_to_fastq(gen(), StringIO(), variant='illumina1.8')
def test_generator_to_fastq_no_qual(self): def gen(): yield Sequence('ACGT', metadata={'id': 'foo', 'description': 'bar'}, positional_metadata={'quality': range(4)}) yield Sequence('ACG', metadata={'id': 'foo', 'description': 'bar'}) with self.assertRaisesRegexp(ValueError, '2nd.*quality scores'): _generator_to_fastq(gen(), StringIO(), variant='illumina1.8')
def test_generator_to_fastq_no_qual(self): def gen(): yield Sequence('ACGT', metadata={'id': 'foo', 'description': 'bar'}, positional_metadata={'quality': range(4)}) yield Sequence('ACG', metadata={'id': 'foo', 'description': 'bar'}) with six.assertRaisesRegex(self, ValueError, '2nd.*quality scores'): _generator_to_fastq(gen(), StringIO(), variant='illumina1.8')
def test_conversion(self): for from_fp, to_fp, kwargs in self.conversions: for from_kwargs, to_kwargs in kwargs: read_gen = _fastq_to_generator(from_fp, **from_kwargs) fh = StringIO() # will issue warning when truncating quality scores with warnings.catch_warnings(record=True): warnings.simplefilter("ignore") _generator_to_fastq(read_gen, fh, **to_kwargs) obs = fh.getvalue() fh.close() with open(to_fp, 'U') as fh: exp = fh.read() self.assertEqual(obs, exp)
def test_generator_to_fastq_kwargs_passed(self): for components, kwargs_expected_fp in self.valid_files: for kwargs, expected_fp in kwargs_expected_fp: def gen(): for c in components: yield BiologicalSequence( c[2], id=c[0], description=c[1], quality=c[3]) fh = StringIO() _generator_to_fastq(gen(), fh, **kwargs) observed = fh.getvalue() fh.close() with open(expected_fp, 'U') as f: expected = f.read() self.assertEqual(observed, expected)
def test_generator_to_fastq_kwargs_passed(self): for components, kwargs_expected_fp in self.valid_files: for kwargs, expected_fp in kwargs_expected_fp: def gen(): for c in components: yield Sequence( c[2], metadata={'id': c[0], 'description': c[1]}, positional_metadata={'quality': c[3]}) fh = StringIO() _generator_to_fastq(gen(), fh, **kwargs) observed = fh.getvalue() fh.close() with open(expected_fp, 'U') as f: expected = f.read() self.assertEqual(observed, expected)
def test_generator_to_fastq_kwargs_passed(self): for components, kwargs_expected_fp in self.valid_files: for kwargs, expected_fp in kwargs_expected_fp: def gen(): for c in components: yield BiologicalSequence(c[2], id=c[0], description=c[1], quality=c[3]) fh = StringIO() _generator_to_fastq(gen(), fh, **kwargs) observed = fh.getvalue() fh.close() with open(expected_fp, 'U') as f: expected = f.read() self.assertEqual(observed, expected)