Esempio n. 1
0
 def read_as_intervaltree(self):
     '''
     Reads the data from a 'bed' file into an ``intervaltree_bio.GenomeIntervalTree`` data structure.
     Similarly to ``open`` and ``open_text`` it won't download file to cache, if it is not there.
     Reads the whole file to memory during its work.
     
     The file must be a `bed` or `bed.gz` file.
     The ``data`` field of each interval will contain the result of ``ln.split('\t')[3:]`` applied to the corresponding line of the ``bed`` file.
     
     Returns:
         a GenomeIntervalTree instance.
     '''
     assert self['type'] in ['bed', 'narrowPeak', 'broadPeak']
     
     with self.open_text() as f:
         gtree = GenomeIntervalTree.from_bed(fileobj=f)
     return gtree
Esempio n. 2
0
    def read_as_intervaltree(self):
        '''
        Reads the data from a 'bed' file into an ``intervaltree_bio.GenomeIntervalTree`` data structure.
        Similarly to ``open`` and ``open_text`` it won't download file to cache, if it is not there.
        Reads the whole file to memory during its work.
        
        The file must be a `bed` or `bed.gz` file.
        The ``data`` field of each interval will contain the result of ``ln.split('\t')[3:]`` applied to the corresponding line of the ``bed`` file.
        
        Returns:
            a GenomeIntervalTree instance.
        '''
        assert self['type'] in ['bed', 'narrowPeak', 'broadPeak']

        with self.open_text() as f:
            gtree = GenomeIntervalTree.from_bed(fileobj=f)
        return gtree
Esempio n. 3
0
def bed_to_tree(bed):
    with open(bed, 'r') as f:
        btree = GenomeIntervalTree.from_bed(fileobj=f)
    return btree