Пример #1
0
    def test_roundtrip_writer(self, filename):
        output_path = test_utils.test_tmpfile(filename)
        with bed.BedWriter(output_path,
                           header=bed_pb2.BedHeader(num_fields=5)) as writer:
            for record in self.records:
                writer.write(record)

        with bed.BedReader(output_path) as reader:
            v2_records = list(reader.iterate())

        self.assertEqual(self.records, v2_records)
Пример #2
0
  def test_roundtrip_num_fields(self, num_fields):
    all_num_fields_in_file = [
        n for n in _VALID_NUM_BED_FIELDS if n >= num_fields
    ]
    for num_fields_in_file in all_num_fields_in_file:
      lines = ['\t'.join(line[:num_fields_in_file]) for line in self.tokens]
      contents = '{}\n'.format('\n'.join(lines))
      input_path = test_utils.test_tmpfile('test_field.bed', contents=contents)

      with bed.BedReader(input_path, num_fields=num_fields) as reader:
        records = list(reader.iterate())
      output_path = test_utils.test_tmpfile('test_field2.bed')
      with bed.BedWriter(output_path, header=reader.header) as writer:
        for record in records:
          writer.write(record)

      with bed.BedReader(output_path) as reader2:
        v2_records = list(reader2.iterate())

      self.assertLen(records, 3)
      self.assertEqual(records, v2_records)