From de8fc3bc68bc7180cd74dc061dbd773c5f536c55 Mon Sep 17 00:00:00 2001 From: E Croot <20226124+ecroot@users.noreply.github.com> Date: Wed, 9 Apr 2025 12:47:53 +0100 Subject: [PATCH 1/2] prevent negative start coordinate patch for bug 313 (https://github.com/sims-lab/CapCruncher/issues/313) --- capcruncher/api/pileup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/capcruncher/api/pileup.py b/capcruncher/api/pileup.py index 557dd16e..ed85075a 100644 --- a/capcruncher/api/pileup.py +++ b/capcruncher/api/pileup.py @@ -428,7 +428,14 @@ def cooler_to_bedgraph( if viewpoint_distance: viewpoint_coords = cooler.Cooler(clr).info["metadata"]["viewpoint_coords"][0] viewpoint_coords = re.split("[:-]", viewpoint_coords) - region_to_limit = f"{viewpoint_coords[0]}:{int(viewpoint_coords[1]) - viewpoint_distance}-{int(viewpoint_coords[1]) + viewpoint_distance}" + vpstart = (int(viewpoint_coords[1]) - viewpoint_distance) + vpend = (int(viewpoint_coords[1]) + viewpoint_distance) + # set start to 1 if (start - viewpoint distance) would be negative, because a negative coordinate causes + # 'ValueError: Unexpected token "-"' + if vpstart <=0: + vpstart = 1 + # TODO: IF VPEND > CHR SIZE, SET TO CHR SIZE (not sure if this is needed as well?) + region_to_limit = f"{viewpoint_coords[0]}:{vpstart}-{vpend}" else: region_to_limit = None From 11d578cc4692f02c77b543ed9d9a598625fd212a Mon Sep 17 00:00:00 2001 From: E Croot <20226124+ecroot@users.noreply.github.com> Date: Fri, 11 Apr 2025 10:15:19 +0100 Subject: [PATCH 2/2] fix spacing error --- capcruncher/api/pileup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/capcruncher/api/pileup.py b/capcruncher/api/pileup.py index ed85075a..551bcefa 100644 --- a/capcruncher/api/pileup.py +++ b/capcruncher/api/pileup.py @@ -435,7 +435,7 @@ def cooler_to_bedgraph( if vpstart <=0: vpstart = 1 # TODO: IF VPEND > CHR SIZE, SET TO CHR SIZE (not sure if this is needed as well?) - region_to_limit = f"{viewpoint_coords[0]}:{vpstart}-{vpend}" + region_to_limit = f"{viewpoint_coords[0]}:{vpstart}-{vpend}" else: region_to_limit = None