def test_fasta__from_file(func, tmp_path): expected = [ FASTQ("This_is_FASTA!", None, "ACGTN", "12345"), FASTQ("This_is_ALSO_FASTA!", None, "CGTNA", "56789"), ] with func(tmp_path / "file", "wt") as handle: for item in expected: item.write(handle) assert list(FASTQ.from_file(tmp_path / "file")) == expected
def main(argv): args = parse_args(argv) seq_retained_nts = 0 seq_retained_reads = 0 for filename in args.files: qualities = FASTQualities() for record in FASTQ.from_file(filename): qualities.update(record) seq_retained_reads += 1 seq_retained_nts += len(record.sequence) offsets = qualities.offsets() if offsets == FASTQualities.BOTH: print( "FASTQ file(s) contains quality scores with both quality offsets (33 " "and 64); file may be unexpected format or corrupt. Please ensure that " "this file contains valid FASTQ reads from a single source.", file=sys.stderr, ) return 1 elif offsets == FASTQualities.MISSING: if args.no_empty: print("FASTQ file is empty.", file=sys.stderr) return 1 elif offsets not in (FASTQualities.AMBIGIOUS, args.offset): print( "FASTQ file contains quality scores with wrong quality score offset " "(%i); expected reads with quality score offset %i. Ensure that the " "'QualityOffset' specified in the makefile corresponds to the input." % (offsets, args.offset), file=sys.stderr, ) return 1 print( json.dumps( { "filenames": args.files, "seq_retained_reads": seq_retained_reads, "seq_retained_nts": seq_retained_nts, "seq_collapsed": seq_retained_reads if args.collapsed else 0, }, indent=2, sort_keys=True, ) ) return 0