Skip to content

Commit

Permalink
Include in try-catch blocks with error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Chiara Rasi committed Sep 30, 2024
1 parent f6ec8da commit e6e7334
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/chanjo2/meta/handle_completeness_stats.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
import logging
import subprocess
import tempfile
from typing import Dict, List, Tuple

CHROM_INDEX = 0
START_INDEX = 1
STOP_INDEX = 2
LOG = logging.getLogger(__name__)


def get_d4tools_intervals_completeness(
d4_file_path: str, bed_file_path: str, completeness_thresholds: List[int]
) -> List[Dict]:
"""Return coverage completeness over all intervals of a bed file using the perc_cov d4tools command."""
threshold_stats = []
d4tools_stats_perc_cov: str = subprocess.check_output(
[
"d4tools",
"stat",
"-s",
f"perc_cov={','.join(str(threshold) for threshold in completeness_thresholds)}",
"--region",
bed_file_path,
d4_file_path,
],
text=True,
)
for line in d4tools_stats_perc_cov.splitlines():
stats_dict: Dict = dict(
(
zip(
completeness_thresholds,
[float(stat) for stat in line.rstrip().split("\t")[3:]],
try:
d4tools_stats_perc_cov: str = subprocess.check_output(
[
"d4tools",
"stat",
"-s",
f"perc_cov={','.join(str(threshold) for threshold in completeness_thresholds)}",
"--region",
bed_file_path,
d4_file_path,
],
text=True,
)

for line in d4tools_stats_perc_cov.splitlines():
stats_dict: Dict = dict(
(
zip(
completeness_thresholds,
[float(stat) for stat in line.rstrip().split("\t")[3:]],
)
)
)
)
threshold_stats.append(stats_dict)
threshold_stats.append(stats_dict)
except subprocess.CalledProcessError, e:
LOG.error(f"d4tools stat -s perc_cov failed with the following error:{e}")

return threshold_stats

Expand Down

0 comments on commit e6e7334

Please sign in to comment.