BigWig Counter¶
Function that uses pyBigWig to get the average bigwig signal in regions from a bed-file from one or multiple bigwig files.
- BigWig_Counter.bigwig_counts(bed_file, bigwigs, n_cores=1)¶
For a bed file or BedTool object gets the mean signal for each bigwig file. If pyBigWig can’t retrieve a count it will be set to 0, and the region listed in the error list.
- Parameters:
bed_file – Either a BedTools object or a path to a bed-file.
bigwigs – List of bigwigs for which pyBigWig will be used to extract the mean signal for.
- Returns:
region_counts: Will give a dataframe of the bed-file’s regions with a column for each bigwig file and the file name as column.
errors: List of regions that are also part of the bed_regions but failed due to not returning a count or throwing an error of invalid interval bounds. Those have a count of 0. Note, the errors are rather unreliable, the behaviour of the pyBigWig is a bit elusive.
- Return type:
import BigWig_Counter
# Take a mini bed-file and get the signal from two chr21 bigwig files from IHEC (https://ihec-epigenomes.org/epiatlas/data/).
bed_file = "ExampleData/H3K27acPeaks_chr21.narrowPeak"
bigwigs = ['ExampleData/IHECRE00000013_chr21.bigwig', 'ExampleData/IHECRE00000017_chr21.bigwig']
bed_counts, errors = BigWig_Counter.bigwig_counts(bed_file, bigwigs, n_cores=1)
print(bed_counts.head())