Skip to content

Commit

Permalink
Handle unnormalized HiC data
Browse files Browse the repository at this point in the history
  • Loading branch information
e-sollier committed Jun 17, 2024
1 parent 9b0007e commit f0c4ab7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion figeno/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from figeno.cli import gui, init,make

__version__ = "1.3.2"
__version__ = "1.3.3"

def main():
parser = ArgumentParser("figeno",formatter_class=ArgumentDefaultsHelpFormatter)
Expand Down
2 changes: 1 addition & 1 deletion figeno/figeno.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self,config=None,config_file=None,reference=None,genes_file=None,cy
for s in config["regions"]:
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).")
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).")
chr = str(s["chr"]).lstrip("chr")
chr = str(s["chr"]).lstrip("chr").lstrip("Chr")
orientation = s["orientation"] if "orientation" in s else "+"

if "start" in s and (s["start"] is not None) and (s["start"]!=""):
Expand Down
2 changes: 1 addition & 1 deletion figeno/gui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "figeno",
"version": "1.3.2",
"version": "1.3.3",
"private": true,
"homepage": "./",
"dependencies": {
Expand Down
13 changes: 10 additions & 3 deletions figeno/track_hic.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def draw(self, regions, box ,hmargin,warnings=[]):
max_bindist=self.max_dist//resolution /2
n = len(regions)

self.balanced= "weight" in c.bins()[:].columns
if not self.balanced:
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."\
" See https://cooler.readthedocs.io/en/latest/cli.html#cooler-balance for more information and options.")

angle = self.find_angle(regions,boxes,max_bindist)


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

#start1,end1,left_offset = region1.start, region1.end,0
mat = c.matrix(balance=True).fetch(region1.chr+":"+str(start1)+"-"+str(end1),
mat = c.matrix(balance=self.balanced).fetch(region1.chr+":"+str(start1)+"-"+str(end1),
region2.chr+":"+str(start2)+"-"+str(end2))
mat[np.isnan(mat)]=0
if region1.orientation=="-": mat = mat[::-1,:]
Expand Down Expand Up @@ -222,7 +227,7 @@ def get_min_max_values(self,regions,low_percentile,high_percentile):
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,file=self.file)
mat = c.matrix(balance=True).fetch(region1.chr+":"+str(region1.start)+"-"+str(region1.end),
mat = c.matrix(balance=self.balanced).fetch(region1.chr+":"+str(region1.start)+"-"+str(region1.end),
region2.chr+":"+str(region2.start)+"-"+str(region2.end))
mat[np.isnan(mat)]=0
if a!=b and self.double_interactions_across_regions: mat = 1+2*mat
Expand All @@ -237,9 +242,11 @@ def find_angle(self,regions,boxes,max_bindist):
if boxes[0]["left"]>boxes[0]["right"]: min_angle=-100
for a in range(len(regions)):
region1 = correct_region_chr(regions[a],c.chromnames,file=self.file)
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). "\
"Only the following chromosome names were found in the .cool file: "+", ".join(c.chromnames))
box1 = boxes[a]
try:
mat = 1+c.matrix(balance=True).fetch(region1.chr+":"+str(region1.start)+"-"+str(region1.end))
mat = 1+c.matrix(balance=self.balanced).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.")
Expand Down
2 changes: 2 additions & 0 deletions figeno/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def correct_region_chr(region,chromosomes,file=""):
return region
elif "chr"+region.chr in chromosomes:
return Region("chr"+region.chr,region.start,region.end,region.orientation,region.color)
elif "Chr"+region.chr in chromosomes:
return Region("Chr"+region.chr,region.start,region.end,region.orientation,region.color)
elif region.chr.lstrip("chr") in chromosomes:
return Region(region.chr.lstrip("chr"),region.start,region.end,region.orientation,region.color)
else:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ packages = ["figeno", "figeno.data", "figeno.cli", "figeno.gui"]

[project]
name = 'figeno'
version = "1.3.2"
version = "1.3.3"
description = 'Package for generating genomics figures.'
readme = 'README.md'
authors = [
Expand Down

0 comments on commit f0c4ab7

Please sign in to comment.