Beispiel #1
0
 def test_bed_reader_on_5_columns_because_mistaken_as_fai(
         self, bed_filename):
     bed_path = test_utils.genomics_core_testdata(bed_filename)
     with self.assertRaisesRegex(
             ValueError, 'Could not open .*5col.bed. The file might not '
             'exist, or the format detected by htslib might '
             'be incorrect.'):
         _ = bed_reader.BedReader.from_file(bed_path,
                                            bed_pb2.BedReaderOptions())
Beispiel #2
0
    def __init__(self, input_path, num_fields=0):
        """Initializes a NativeBedReader.

    Args:
      input_path: string. A path to a resource containing BED records.
      num_fields: int. The number of fields to read in the BED. If unset or set
        to zero, all fields in the input are read.
    """
        super(NativeBedReader, self).__init__()

        bed_path = input_path.encode('utf8')
        if bed_path.endswith('.gz'):
            options = bed_pb2.BedReaderOptions(
                compression_type=bed_pb2.BedReaderOptions.GZIP,
                num_fields=num_fields)
        else:
            options = bed_pb2.BedReaderOptions(num_fields=num_fields)
        self._reader = bed_reader.BedReader.from_file(bed_path, options)
        self.header = self._reader.header
Beispiel #3
0
 def setUp(self):
     self.bed = test_utils.genomics_core_testdata('test_regions.bed')
     self.zipped_bed = test_utils.genomics_core_testdata(
         'test_regions.bed.gz')
     self.options = bed_pb2.BedReaderOptions()
     self.first = bed_pb2.BedRecord(reference_name='chr1',
                                    start=10,
                                    end=20,
                                    name='first',
                                    score=100,
                                    strand=bed_pb2.BedRecord.FORWARD_STRAND,
                                    thick_start=12,
                                    thick_end=18,
                                    item_rgb='255,124,1',
                                    block_count=3,
                                    block_sizes='2,6,2',
                                    block_starts='10,12,18')
Beispiel #4
0
    def test_bed_iterate(self):
        with bed_reader.BedReader.from_file(self.bed, self.options) as reader:
            self.assertEqual(reader.header.num_fields, 12)
            iterable = reader.iterate()
            self.assertIsInstance(iterable, clif_postproc.WrappedCppIterable)
            actual = list(iterable)
            self.assertLen(actual, 2)
            self.assertEqual(actual[0], self.first)

        zreader = bed_reader.BedReader.from_file(self.zipped_bed,
                                                 bed_pb2.BedReaderOptions())
        self.assertEqual(zreader.header.num_fields, 12)
        with zreader:
            ziterable = zreader.iterate()
            self.assertIsInstance(ziterable, clif_postproc.WrappedCppIterable)
            zactual = list(ziterable)
            self.assertLen(zactual, 2)
            self.assertEqual(zactual[0], self.first)