I generate bigwig files using a shell script based on bedtools genomecov (to generate a bedgraph from a bam file) bedmap (to compute means across 10 bp bins) and bedGraphToBigWig to convert the binned bedgraph into bigwig.
Sometimes, the bam file has no data on some chromosomes, this results in a bedgraph file with no entries for the empty chromosomes.
I would like to add the missing entries. How could I do this?
I tried to see what I could do with pyBigWig, opening the bedgraph file in "a" mode, but don't really know how to proceed:
# I have the chromosome sizes for my genome of interest already in a list:
chrom_sizes
#[('I', 15072434),
# ('II', 15279421),
# ('III', 13783801),
# ('IV', 17493829),
# ('MtDNA', 13794),
# ('V', 20924180),
# ('X', 17718942)]
bw_test = pyBigWig.open("path/to/bigwig", "a")
bw_test.chroms()
# {'IV': 17493829, 'V': 20924180, 'X': 17718942}
bw_test.addHeader(chrom_sizes)
# RuntimeError: Received an error in bwCreateHdr
chrom_sizeslist, which should be the same as thehdryou obtain by parsing the bam header. – bli Oct 31 '17 at 08:38_placeholder as looping variable if you then use it to access its first element. I supposefor (chrom, _) in hdr:would work as well while avoiding you the_[0]. – bli Oct 31 '17 at 08:44