Skip to content

Commit

Permalink
Improve warnings for hic track
Browse files Browse the repository at this point in the history
  • Loading branch information
e-sollier committed May 16, 2024
1 parent c243c1b commit d6309a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions figeno/track_hic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion figeno/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d6309a8

Please sign in to comment.