INNER CODE UNIT · Python
validate_bed
nloyfer/wgbs_tools · src/python/add_cpg_counts.py:88
def validate_bed(self):
if self.bed_path is None:
return
df = load_bed(self.bed_path).iloc[:, :3]
# check start before end
if ((df['start'] >= df['end']).any()):
eprint(f'[wt add_cpg_counts] bed file is not legal - end before start')
raise IllegalArgumentError('Bed file is not legal')
# check start is monotonic
ref_chroms = self.gr.genome.get_chroms()
for chrom in ref_chroms:
if not df[df['chr'] == chrom]['start'].is_monotonic_increasing:
eprint(f'[wt add_cpg_counts] bed file is not sorted')
raise IllegalArgumentError('Bed file is not sorted')
# create tmp files from bed file (extend each region with +-1000 bp)