|
22 | 22 | _per_sample_lengths, _summarize_lengths, |
23 | 23 | _set_attr_stats, _construct_datasets, to_hdf5, |
24 | 24 | to_ascii, stat, to_per_sample_ascii, |
25 | | - to_per_sample_files) |
| 25 | + to_per_sample_files, to_ascii_file) |
26 | 26 |
|
27 | 27 |
|
28 | 28 | class BufferTests(TestCase): |
@@ -328,6 +328,60 @@ def test_to_per_sample_ascii(self): |
328 | 328 | obs = [(s[0], list(s[1])) for s in to_per_sample_ascii(self.hdf5_file)] |
329 | 329 | self.assertEqual(obs, exp) |
330 | 330 |
|
| 331 | + def test_to_ascii_file(self): |
| 332 | + with tempfile.NamedTemporaryFile('r+', suffix='.fq', |
| 333 | + delete=False) as f: |
| 334 | + f.write(fqdata_variable_length) |
| 335 | + |
| 336 | + self.to_remove.append(f.name) |
| 337 | + |
| 338 | + with tempfile.NamedTemporaryFile('r+', suffix='.demux', |
| 339 | + delete=False) as demux_f: |
| 340 | + pass |
| 341 | + |
| 342 | + self.to_remove.append(demux_f.name) |
| 343 | + |
| 344 | + with h5py.File(demux_f.name, 'r+') as demux: |
| 345 | + to_hdf5(f.name, demux) |
| 346 | + |
| 347 | + with tempfile.NamedTemporaryFile('r+', suffix='.fq', |
| 348 | + delete=False) as obs_fq: |
| 349 | + pass |
| 350 | + self.to_remove.append(obs_fq.name) |
| 351 | + |
| 352 | + to_ascii_file(demux_f.name, obs_fq.name) |
| 353 | + with open(obs_fq.name, 'rb') as obs_f: |
| 354 | + obs = obs_f.read() |
| 355 | + exp = (b'@a_0 orig_bc=abc new_bc=abc bc_diffs=0\nxyz\n+\nABC\n' |
| 356 | + b'@b_0 orig_bc=abw new_bc=wbc bc_diffs=4\nqwe\n+\nDFG\n' |
| 357 | + b'@b_1 orig_bc=abw new_bc=wbc bc_diffs=4\nqwexx\n+\nDEF#G\n') |
| 358 | + self.assertEqual(obs, exp) |
| 359 | + |
| 360 | + with tempfile.NamedTemporaryFile('r+', suffix='.fa', |
| 361 | + delete=False) as obs_fa: |
| 362 | + pass |
| 363 | + self.to_remove.append(obs_fa.name) |
| 364 | + |
| 365 | + to_ascii_file(demux_f.name, obs_fa.name, out_format='fasta') |
| 366 | + with open(obs_fa.name, 'rb') as obs_f: |
| 367 | + obs = obs_f.read() |
| 368 | + exp = (b'>a_0 orig_bc=abc new_bc=abc bc_diffs=0\nxyz\n' |
| 369 | + b'>b_0 orig_bc=abw new_bc=wbc bc_diffs=4\nqwe\n' |
| 370 | + b'>b_1 orig_bc=abw new_bc=wbc bc_diffs=4\nqwexx\n') |
| 371 | + self.assertEqual(obs, exp) |
| 372 | + |
| 373 | + with tempfile.NamedTemporaryFile('r+', suffix='.fq', |
| 374 | + delete=False) as obs_fq: |
| 375 | + pass |
| 376 | + self.to_remove.append(obs_fq.name) |
| 377 | + |
| 378 | + to_ascii_file(demux_f.name, obs_fq.name, samples=['b']) |
| 379 | + with open(obs_fq.name, 'rb') as obs_f: |
| 380 | + obs = obs_f.read() |
| 381 | + exp = (b'@b_0 orig_bc=abw new_bc=wbc bc_diffs=4\nqwe\n+\nDFG\n' |
| 382 | + b'@b_1 orig_bc=abw new_bc=wbc bc_diffs=4\nqwexx\n+\nDEF#G\n') |
| 383 | + self.assertEqual(obs, exp) |
| 384 | + |
331 | 385 | def test_to_files(self): |
332 | 386 | # implicitly tested with test_to_per_sample_fasta |
333 | 387 | pass |
|
0 commit comments