Skip to content

Commit f0c4ab7

Browse files
committed
Handle unnormalized HiC data
1 parent 9b0007e commit f0c4ab7

File tree

6 files changed

+16
-7
lines changed

6 files changed

+16
-7
lines changed

figeno/cli/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from figeno.cli import gui, init,make
44

5-
__version__ = "1.3.2"
5+
__version__ = "1.3.3"
66

77
def main():
88
parser = ArgumentParser("figeno",formatter_class=ArgumentDefaultsHelpFormatter)

figeno/figeno.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __init__(self,config=None,config_file=None,reference=None,genes_file=None,cy
8989
for s in config["regions"]:
9090
if not "chr" in s: raise KnownException("Please provide at least the chromosome for each region (and optionally the start and end coordinates, otherwise figeno will assume than the region spans the whole chromosome).")
9191
if s["chr"]=="" or s["chr"]=="chr" or s["chr"] is None: raise KnownException("Please provide at least the chromosome for each region (and optionally the start and end coordinates, otherwise figeno will assume than the region spans the whole chromosome).")
92-
chr = str(s["chr"]).lstrip("chr")
92+
chr = str(s["chr"]).lstrip("chr").lstrip("Chr")
9393
orientation = s["orientation"] if "orientation" in s else "+"
9494

9595
if "start" in s and (s["start"] is not None) and (s["start"]!=""):

figeno/gui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "figeno",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"private": true,
55
"homepage": "./",
66
"dependencies": {

figeno/track_hic.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ def draw(self, regions, box ,hmargin,warnings=[]):
6464
max_bindist=self.max_dist//resolution /2
6565
n = len(regions)
6666

67+
self.balanced= "weight" in c.bins()[:].columns
68+
if not self.balanced:
69+
warnings.append("No balancing weights were found for file "+self.file+". Figeno will show the raw, unnormalized data. If you want to show normalized data, please run: \"cooler balance "+self.file+"\" and re-generate the figure."\
70+
" See https://cooler.readthedocs.io/en/latest/cli.html#cooler-balance for more information and options.")
71+
6772
angle = self.find_angle(regions,boxes,max_bindist)
6873

6974

@@ -125,7 +130,7 @@ def draw(self, regions, box ,hmargin,warnings=[]):
125130
start2 = region2.start - right_offset *resolution
126131

127132
#start1,end1,left_offset = region1.start, region1.end,0
128-
mat = c.matrix(balance=True).fetch(region1.chr+":"+str(start1)+"-"+str(end1),
133+
mat = c.matrix(balance=self.balanced).fetch(region1.chr+":"+str(start1)+"-"+str(end1),
129134
region2.chr+":"+str(start2)+"-"+str(end2))
130135
mat[np.isnan(mat)]=0
131136
if region1.orientation=="-": mat = mat[::-1,:]
@@ -222,7 +227,7 @@ def get_min_max_values(self,regions,low_percentile,high_percentile):
222227
for b in range(a,len(regions)):
223228
if (not self.interactions_across_regions) and a!=b: continue
224229
region1,region2 = correct_region_chr(regions[a],c.chromnames), correct_region_chr(regions[b],c.chromnames,file=self.file)
225-
mat = c.matrix(balance=True).fetch(region1.chr+":"+str(region1.start)+"-"+str(region1.end),
230+
mat = c.matrix(balance=self.balanced).fetch(region1.chr+":"+str(region1.start)+"-"+str(region1.end),
226231
region2.chr+":"+str(region2.start)+"-"+str(region2.end))
227232
mat[np.isnan(mat)]=0
228233
if a!=b and self.double_interactions_across_regions: mat = 1+2*mat
@@ -237,9 +242,11 @@ def find_angle(self,regions,boxes,max_bindist):
237242
if boxes[0]["left"]>boxes[0]["right"]: min_angle=-100
238243
for a in range(len(regions)):
239244
region1 = correct_region_chr(regions[a],c.chromnames,file=self.file)
245+
if not region1.chr in c.chromnames: raise KnownException("Could not find chromosome "+region1.chr+" in the .cool file. Please make sure that you specified the correct chromosome name (the chr prefix can be omitted). "\
246+
"Only the following chromosome names were found in the .cool file: "+", ".join(c.chromnames))
240247
box1 = boxes[a]
241248
try:
242-
mat = 1+c.matrix(balance=True).fetch(region1.chr+":"+str(region1.start)+"-"+str(region1.end))
249+
mat = 1+c.matrix(balance=self.balanced).fetch(region1.chr+":"+str(region1.start)+"-"+str(region1.end))
243250
except ValueError:
244251
raise KnownException("Could not retrieve region "+region1.chr+":"+str(region1.start)+"-"+str(region1.end)+" in file "+self.file+"."\
245252
" Make sure that the region that you specified does not extend beyond the chromosome length, and that you did not subset your .cool file.")

figeno/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def correct_region_chr(region,chromosomes,file=""):
1414
return region
1515
elif "chr"+region.chr in chromosomes:
1616
return Region("chr"+region.chr,region.start,region.end,region.orientation,region.color)
17+
elif "Chr"+region.chr in chromosomes:
18+
return Region("Chr"+region.chr,region.start,region.end,region.orientation,region.color)
1719
elif region.chr.lstrip("chr") in chromosomes:
1820
return Region(region.chr.lstrip("chr"),region.start,region.end,region.orientation,region.color)
1921
else:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ packages = ["figeno", "figeno.data", "figeno.cli", "figeno.gui"]
99

1010
[project]
1111
name = 'figeno'
12-
version = "1.3.2"
12+
version = "1.3.3"
1313
description = 'Package for generating genomics figures.'
1414
readme = 'README.md'
1515
authors = [

0 commit comments

Comments
 (0)