Skip to content

Commit

Permalink
add bedfile read exception
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Sep 17, 2024
1 parent 1b0c4ef commit 171a685
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
15 changes: 14 additions & 1 deletion bedboss/refgenome_validator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from geniml.io.utils import is_gzipped
import logging

from bedboss.exceptions import BedBossException

_LOGGER = logging.getLogger("bedboss")

Expand Down Expand Up @@ -67,7 +68,7 @@ def _read_file_pd(*args, **kwargs) -> pd.DataFrame:
except (pd.errors.ParserError, pd.errors.EmptyDataError) as _:
if row_count <= max_rows:
row_count += 1
return _read_gzipped_file(*args)
raise BedfileReadException(reason="Cannot read bed file.")


def get_bed_chrom_info(bedfile: str) -> dict:
Expand All @@ -84,3 +85,15 @@ def get_bed_chrom_info(bedfile: str) -> dict:

max_end_for_each_chrom = df.groupby(0)[2].max()
return max_end_for_each_chrom.to_dict()


class BedfileReadException(BedBossException):
"""Exception when there is an exception during refgenome validation"""

def __init__(self, reason: str = ""):
"""
Optionally provide explanation for exceptional condition.
:param str reason: some context why error occurred
"""
super(BedfileReadException, self).__init__(reason)
9 changes: 7 additions & 2 deletions scripts/ref_genome_validating/validate_genome.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
# BEDFILE_DIRECTORY = (
# "/home/drc/GITHUB/bedboss/bedboss/scripts/ref_genome_validating/results"
# )
BEDFILE_DIRECTORY = "/home/drc/GITHUB/bedboss/bedboss/scripts/ref_genome_validating/data/bed_small_subset"
# BEDFILE_DIRECTORY = "/home/drc/GITHUB/bedboss/bedboss/scripts/ref_genome_validating/data/bed_small_subset"
BEDFILE_DIRECTORY = "/home/drc/GITHUB/bedboss/bedboss/scripts/ref_genome_validating/data/test_singles"

try:
PEP_URL = os.environ["PEP_URL"]
Expand Down Expand Up @@ -72,6 +73,11 @@ def main():
# build genome models
# for each reference genome in the user's config file, build a genome model

# from geniml.io import RegionSet
#
# ff =RegionSet("/home/drc/GITHUB/bedboss/bedboss/scripts/ref_genome_validating/data/test_singles/GSM8196564_435_RUNX3_KO_H3K27AC_v_435_ctrl_IgG_seacr.relaxed.bed")
# ff

all_genome_models = []

# for reference_genome in rgc.list():
Expand Down Expand Up @@ -213,7 +219,6 @@ def main():
tier = {
"tier_rating": {}
} # add this to a column to make comparisons easier for human eyes on pephub
all_vals = {}
if compat_vector:
for i in compat_vector.keys():
if i is not None:
Expand Down

0 comments on commit 171a685

Please sign in to comment.