Skip to content

Commit d6309a8

Browse files
committed
Improve warnings for hic track
1 parent c243c1b commit d6309a8

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

figeno/track_hic.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def get_min_max_values(self,regions,low_percentile,high_percentile):
221221
for a in range(len(regions)):
222222
for b in range(a,len(regions)):
223223
if (not self.interactions_across_regions) and a!=b: continue
224-
region1,region2 = correct_region_chr(regions[a],c.chromnames), correct_region_chr(regions[b],c.chromnames)
224+
region1,region2 = correct_region_chr(regions[a],c.chromnames), correct_region_chr(regions[b],c.chromnames,file=self.file)
225225
mat = c.matrix(balance=True).fetch(region1.chr+":"+str(region1.start)+"-"+str(region1.end),
226226
region2.chr+":"+str(region2.start)+"-"+str(region2.end))
227227
mat[np.isnan(mat)]=0
@@ -236,9 +236,15 @@ def find_angle(self,regions,boxes,max_bindist):
236236
min_angle=100
237237
if boxes[0]["left"]>boxes[0]["right"]: min_angle=-100
238238
for a in range(len(regions)):
239-
region1 = correct_region_chr(regions[a],c.chromnames)
239+
region1 = correct_region_chr(regions[a],c.chromnames,file=self.file)
240240
box1 = boxes[a]
241-
mat = 1+c.matrix(balance=True).fetch(region1.chr+":"+str(region1.start)+"-"+str(region1.end))
241+
try:
242+
mat = 1+c.matrix(balance=True).fetch(region1.chr+":"+str(region1.start)+"-"+str(region1.end))
243+
except ValueError:
244+
raise KnownException("Could not retrieve region "+region1.chr+":"+str(region1.start)+"-"+str(region1.end)+" in file "+self.file+"."\
245+
" Make sure that the region that you specified does not extend beyond the chromosome length, and that you did not subset your .cool file.")
246+
except Exception as e:
247+
raise e
242248
width = (box1["right"]-box1["left"]) / mat.shape[0]
243249
height = (box1["top"]-box1["bottom"]) / max_bindist
244250
angle = height / width

figeno/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def correct_region_chr(region,chromosomes,file=""):
1717
elif region.chr.lstrip("chr") in chromosomes:
1818
return Region(region.chr.lstrip("chr"),region.start,region.end,region.orientation,region.color)
1919
else:
20-
error_message="Could not find chromosome: "+region.chr
20+
error_message="Could not find chromosome "+region.chr
2121
if file!="": error_message+=" in file "+file+"."
2222
else: error_message+="."
2323
raise KnownException(error_message)

0 commit comments

Comments
 (0)