Пример #1
0
def extract_bigwig_to_npy(bigwig, output_dir, dtype=np.float32):
    wWigIO.open(bigwig)
    chrom_sizes = wWigIO.getChromSize(bigwig)
    file_shapes = {}
    for chrom, size in zip(*chrom_sizes):
        data = np.empty(size)
        wWigIO.getData(bigwig, chrom, 0, size, data)
        np.save('{}.npy'.format(os.path.join(output_dir, chrom)),
                data.astype(dtype))
        file_shapes[chrom] = data.shape
    wWigIO.close(bigwig)

    with open(os.path.join(output_dir, 'metadata.json'), 'w') as fp:
        json.dump(
            {
                'file_shapes': file_shapes,
                'type': 'array',
                'source': bigwig
            }, fp)
Пример #2
0
 def getChromSizesWigIO(self):
     wWigIO.open(self.path)
     out = wWigIO.getChromSize(self.path)
     out = dict(zip(out[0], out[1]))
     wWigIO.close(self.path)
     return out
Пример #3
0
# ------------------------------------
# Misc functions
# ------------------------------------

# ------------------------------------
# Classes
# ------------------------------------

# ------------------------------------
# Main
# ------------------------------------

if __name__=="__main__":
    # get information from bigwig file
    wWigIO.open('test.bw')
    chroms = wWigIO.getChromSize('test.bw')
    wigs = wWigIO.getIntervals('test.bw', 'chr1', 10, 200)
    wWigIO.close('test.bw')
    print wigs

    # bigwig -> wig
    wWigIO.bigWigToWig('test.bw','test.wig')

    # write the chrom sizes into test.sizes
    with open('test.sizes','w') as fh:
        for chrom in chroms:
            print >>fh, chrom+"\t"+str(chroms[chrom])
    
    # wig -> bigwig
    wWigIO.wigToBigWig('test.wig','test.sizes','test2.bw')
Пример #4
0
 def chromSizes(self):
     ''' Get chromosome sizes.'''
     chroms = wWigIO.getChromSize(self.fname)
     return chroms
Пример #5
0
 def chromSizes(self):
     ''' Get chromosome sizes.'''
     chroms=wWigIO.getChromSize(self.fname)
     return chroms
Пример #6
0
# ------------------------------------
# Misc functions
# ------------------------------------

# ------------------------------------
# Classes
# ------------------------------------

# ------------------------------------
# Main
# ------------------------------------

if __name__ == "__main__":
    # get information from bigwig file
    wWigIO.open('test.bw')
    chroms = wWigIO.getChromSize('test.bw')
    wigs = wWigIO.getIntervals('test.bw', 'chr1', 10, 200)
    wWigIO.close('test.bw')
    print wigs

    # bigwig -> wig
    wWigIO.bigWigToWig('test.bw', 'test.wig')

    # write the chrom sizes into test.sizes
    with open('test.sizes', 'w') as fh:
        for chrom in chroms:
            print >> fh, chrom + "\t" + str(chroms[chrom])

    # wig -> bigwig
    wWigIO.wigToBigWig('test.wig', 'test.sizes', 'test2.bw')