From d6309a8e6abd33807eb108ae5b111564696d1ced Mon Sep 17 00:00:00 2001 From: e-sollier Date: Thu, 16 May 2024 09:53:45 +0200 Subject: [PATCH] Improve warnings for hic track --- figeno/track_hic.py | 12 +++++++++--- figeno/utils.py | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/figeno/track_hic.py b/figeno/track_hic.py index bb13a19..9dacdb1 100644 --- a/figeno/track_hic.py +++ b/figeno/track_hic.py @@ -221,7 +221,7 @@ def get_min_max_values(self,regions,low_percentile,high_percentile): for a in range(len(regions)): for b in range(a,len(regions)): if (not self.interactions_across_regions) and a!=b: continue - region1,region2 = correct_region_chr(regions[a],c.chromnames), correct_region_chr(regions[b],c.chromnames) + region1,region2 = correct_region_chr(regions[a],c.chromnames), correct_region_chr(regions[b],c.chromnames,file=self.file) mat = c.matrix(balance=True).fetch(region1.chr+":"+str(region1.start)+"-"+str(region1.end), region2.chr+":"+str(region2.start)+"-"+str(region2.end)) mat[np.isnan(mat)]=0 @@ -236,9 +236,15 @@ def find_angle(self,regions,boxes,max_bindist): min_angle=100 if boxes[0]["left"]>boxes[0]["right"]: min_angle=-100 for a in range(len(regions)): - region1 = correct_region_chr(regions[a],c.chromnames) + region1 = correct_region_chr(regions[a],c.chromnames,file=self.file) box1 = boxes[a] - mat = 1+c.matrix(balance=True).fetch(region1.chr+":"+str(region1.start)+"-"+str(region1.end)) + try: + mat = 1+c.matrix(balance=True).fetch(region1.chr+":"+str(region1.start)+"-"+str(region1.end)) + except ValueError: + raise KnownException("Could not retrieve region "+region1.chr+":"+str(region1.start)+"-"+str(region1.end)+" in file "+self.file+"."\ + " Make sure that the region that you specified does not extend beyond the chromosome length, and that you did not subset your .cool file.") + except Exception as e: + raise e width = (box1["right"]-box1["left"]) / mat.shape[0] height = (box1["top"]-box1["bottom"]) / max_bindist angle = height / width diff --git a/figeno/utils.py b/figeno/utils.py index a000e79..ced34b5 100644 --- a/figeno/utils.py +++ b/figeno/utils.py @@ -17,7 +17,7 @@ def correct_region_chr(region,chromosomes,file=""): elif region.chr.lstrip("chr") in chromosomes: return Region(region.chr.lstrip("chr"),region.start,region.end,region.orientation,region.color) else: - error_message="Could not find chromosome: "+region.chr + error_message="Could not find chromosome "+region.chr if file!="": error_message+=" in file "+file+"." else: error_message+="." raise KnownException(error_message)