From f0c4ab706358dfd4c8e3e9c08e654183c02e8a97 Mon Sep 17 00:00:00 2001 From: e-sollier Date: Mon, 17 Jun 2024 15:39:37 +0200 Subject: [PATCH] Handle unnormalized HiC data --- figeno/cli/cli.py | 2 +- figeno/figeno.py | 2 +- figeno/gui/package.json | 2 +- figeno/track_hic.py | 13 ++++++++++--- figeno/utils.py | 2 ++ pyproject.toml | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/figeno/cli/cli.py b/figeno/cli/cli.py index eb8722d..e072d35 100644 --- a/figeno/cli/cli.py +++ b/figeno/cli/cli.py @@ -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) diff --git a/figeno/figeno.py b/figeno/figeno.py index 36f473b..2a5de0b 100644 --- a/figeno/figeno.py +++ b/figeno/figeno.py @@ -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"]!=""): diff --git a/figeno/gui/package.json b/figeno/gui/package.json index 25abc3f..55857ea 100644 --- a/figeno/gui/package.json +++ b/figeno/gui/package.json @@ -1,6 +1,6 @@ { "name": "figeno", - "version": "1.3.2", + "version": "1.3.3", "private": true, "homepage": "./", "dependencies": { diff --git a/figeno/track_hic.py b/figeno/track_hic.py index 9dacdb1..d12441e 100644 --- a/figeno/track_hic.py +++ b/figeno/track_hic.py @@ -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) @@ -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,:] @@ -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 @@ -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.") diff --git a/figeno/utils.py b/figeno/utils.py index ced34b5..fe42044 100644 --- a/figeno/utils.py +++ b/figeno/utils.py @@ -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: diff --git a/pyproject.toml b/pyproject.toml index 98f9920..cba34c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [