cell2net.preprocessing.fragment_to_bigwig#
- cell2net.preprocessing.fragment_to_bigwig(fragment_file, chrom_sizes, bw_filename, normalize=True, scaling_factor=1.0, cut_sites=False, extend_cut_sites=0, cell_barcodes=None)#
Convert fragment file to BigWig format.
This function reads a fragment file, calculates coverage or cut-site signal, and writes the resulting data to a BigWig file.
- Parameters:
fragment_file (
str
) – Path to the input fragment file. The file can be plain text or gzip-compressed (“.gz”).chrom_sizes (
dict
[str
,int
]) – A dictionary of chromosome sizes, e.g., {“chr1”: 248956422, “chr2”: 242193529, …}.bw_filename (
str
) – Path to the output BigWig file.normalize (
bool
(default:True
)) – If True, normalize coverage or signal values. Default is True.scaling_factor (float, optional) – Factor to scale signal values if normalize is True. Default is 1.0.
cut_sites (
bool
(default:False
)) – If True, compute the cut-site signal instead of coverage. Default is False.extend_cut_sites (
int
(default:0
)) – If set cut_sites, expand cut sites for both upstream and downstream, by default: 0
- Return type:
- Returns:
Write output to bigwig file
Notes
The input fragment file should be tab-delimited and follow the format: Chromosome, Start, End, Barcode, Count.
Lines starting with # or empty lines are skipped during parsing.
Uses pyBigWig for writing BigWig files and polars for efficient data manipulation.
Example
>>> fragment_file = "example_fragments.tsv.gz" >>> chrom_sizes = {"chr1": 248956422, "chr2": 242193529} >>> bw_filename = "output.bw" >>> fragment_to_bigwig(fragment_file, chrom_sizes, bw_filename, normalize=True, scaling_factor=1.0, cut_sites=False)