Example #1
0
 def test_iterate_fastq_reader(self, fastq_filename):
     fastq_path = test_utils.genomics_core_testdata(fastq_filename)
     expected_ids = [
         'NODESC:header', 'M01321:49:000000000-A6HWP:1:1101:17009:2216',
         'FASTQ'
     ]
     with fastq.FastqReader(fastq_path) as reader:
         records = list(reader.iterate())
     self.assertLen(records, 3)
     self.assertEqual([r.id for r in records], expected_ids)
Example #2
0
    def test_roundtrip_writer(self, filename):
        output_path = test_utils.test_tmpfile(filename)
        with fastq.FastqWriter(output_path) as writer:
            for record in self.records:
                writer.write(record)

        with fastq.FastqReader(output_path) as reader:
            v2_records = list(reader.iterate())

        self.assertEqual(self.records, v2_records)
  def test_round_trip_fastq(self, test_datum_name):
    # Round-trip FASTQ records through writing and reading:
    # 1. Read records v1 from FastqReader;
    # 2. Write v1 to fastq using our FastqWriter;
    # 3. Read back in using FastqReader -- v2;
    # 4. compare v1 and v2.
    in_file = test_utils.genomics_core_testdata(test_datum_name)
    out_file = test_utils.test_tmpfile('output_' + test_datum_name)

    v1_reader = fastq.FastqReader(in_file)
    v1_records = list(v1_reader.iterate())
    self.assertTrue(v1_records, 'Reader failed to find records')

    writer_options = fastq_pb2.FastqWriterOptions()

    with fastq_writer.FastqWriter.to_file(out_file, writer_options) as writer:
      for record in v1_records:
        writer.write(record)

    v2_reader = fastq.FastqReader(out_file)
    v2_records = list(v2_reader.iterate())
    self.assertEqual(v1_records, v2_records,
                     'Round-tripped FASTQ files not as expected')