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)
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
# ------------------------------------ # 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')
def chromSizes(self): ''' Get chromosome sizes.''' chroms = wWigIO.getChromSize(self.fname) return chroms
def chromSizes(self): ''' Get chromosome sizes.''' chroms=wWigIO.getChromSize(self.fname) return chroms
# ------------------------------------ # 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')