methylseg.MethylDataPrep
- class methylseg.MethylDataPrep(meth_file, sample_id, resolution='auto', min_coverage=10, remove_low_coverage_like_cpgs=False, chunk_size=1000000, retain_removed_rows=True)[source]
Bases:
objectNormalize methylation input tables into the canonical
SampleInfoschema.- __init__(meth_file, sample_id, resolution='auto', min_coverage=10, remove_low_coverage_like_cpgs=False, chunk_size=1000000, retain_removed_rows=True)[source]
Initialize methylation-table preparation for one sample.
- Parameters:
meth_file – Path to the methylation data file.
sample_id – Unique identifier for the prepared sample.
resolution – Methylation data format:
"auto","wgbs","450k","27k", or"850k".min_coverage – Minimum coverage threshold for WGBS data.
remove_low_coverage_like_cpgs – If
True, remove CpGs with beta values commonly produced by very low coverage counts, such as 0.0, 0.25, 0.33, 0.5, 0.66/0.67, 0.75, and 1.0.chunk_size – Number of rows to read at a time when processing large files.
retain_removed_rows – If
True, retain removed rows in a separate DataFrame for downstream analysis. Otherwise, discard them.
Methods
__init__(meth_file, sample_id[, resolution, ...])Initialize methylation-table preparation for one sample.
prepare()Prepare the methylation file and wrap it in
SampleInfo.Load and normalize the configured methylation file.
write_prepared_tsv(out_file[, sep])Write the prepared methylation table to disk.
Attributes
- REQUIRED_COLUMNS = ['CpG_chrm', 'CpG_beg', 'CpG_end', 'beta']
- INPUT_ROW_INDEX_COL = '__input_row_index__'
- LOW_COVERAGE_LIKE_BETA_VALUES = frozenset({0.0, 0.25, 0.33, 0.5, 0.66, 0.67, 0.75, 1.0})
- COMMON_ALIASES = {'CpG_beg': ['CpG_beg', 'start', 'pos', 'position'], 'CpG_chrm': ['CpG_chrm', 'chrom', 'chr', 'chromosome'], 'CpG_end': ['CpG_end', 'end', 'stop'], 'beta': ['beta', 'meth_beta', 'methylation', 'meth_percent']}
- HEADER_ALIASES = {'CpG_beg': {'cpg_beg', 'pos', 'position', 'start'}, 'CpG_chrm': {'chr', 'chrom', 'chromosome', 'cpg_chrm'}, 'CpG_end': {'cpg_end', 'end', 'stop'}, 'beta': {'beta', 'meth_beta', 'meth_percent', 'methylation'}, 'coverage': {'cov', 'coverage', 'depth', 'total_reads'}, 'meth': {'meth', 'methylated', 'methylated_reads'}, 'probe': {'cpg', 'cpg_id', 'probe', 'probe_id'}}
- prepare_dataframe()[source]
Load and normalize the configured methylation file.
- Returns:
Two data frames containing the filtered canonical methylation table and the rows removed during preparation. The filtered table contains
CpG_chrm,CpG_beg,CpG_end, andbetacolumns.- Return type:
tuple of pandas.DataFrame
- Raises:
ValueError – If the requested
resolutionis unsupported or the input cannot be normalized into the canonical schema.