Esempio n. 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)
Esempio n. 2
0
 def setUp(self):
   out_fname = test_utils.test_tmpfile('output.bed')
   self.writer = bed_writer.BedWriter.to_file(
       out_fname, bed_pb2.BedHeader(num_fields=12), bed_pb2.BedWriterOptions())
   self.expected_bed_content = [
       'chr1\t10\t20\tfirst\t100\t+\t12\t18\t255,124,1\t3\t2,6,2\t10,12,18\n',
       'chr1\t100\t200\tsecond\t250\t.\t120\t180\t252,122,12\t2\t35,40\t'
       '100,160\n'
   ]
   self.record = bed_pb2.BedRecord(
       reference_name='chr1', start=20, end=30, name='r')
Esempio n. 3
0
  def __init__(self, output_path, header=None):
    """Initializer for NativeBedWriter.

    Args:
      output_path: str. The path to which to write the BED file.
      header: nucleus.genomics.v1.BedHeader. The header that defines all
        information germane to the constituent BED records.
    """
    super(NativeBedWriter, self).__init__()
    if header is None:
      header = bed_pb2.BedHeader(num_fields=3)
    writer_options = bed_pb2.BedWriterOptions()
    self._writer = bed_writer.BedWriter.to_file(output_path, header,
                                                writer_options)
Esempio n. 4
0
  def test_writing_canned_records(self):
    """Tests writing all the records that are 'canned' in our tfrecord file."""
    # This file is in TFRecord format.
    tfrecord_file = test_utils.genomics_core_testdata(
        'test_regions.bed.tfrecord')

    header = bed_pb2.BedHeader(num_fields=12)
    writer_options = bed_pb2.BedWriterOptions()
    bed_records = list(
        io_utils.read_tfrecords(tfrecord_file, proto=bed_pb2.BedRecord))
    out_fname = test_utils.test_tmpfile('output.bed')
    with bed_writer.BedWriter.to_file(out_fname, header,
                                      writer_options) as writer:
      for record in bed_records:
        writer.write(record)

    with gfile.GFile(out_fname, 'r') as f:
      self.assertEqual(f.readlines(), self.expected_bed_content)