diff --git a/docs/content/describe_figure.rst b/docs/content/describe_figure.rst index baaef9d..c188e14 100644 --- a/docs/content/describe_figure.rst +++ b/docs/content/describe_figure.rst @@ -151,12 +151,18 @@ Parameters: * ``scale``: how the maximum value for the y-axis is chosen * ``auto`` (default): will select as maximum the maximum across all regions. + + * ``group auto`` (default): will select as maximum the maximum across all regions, for all tracks in the same group (defined by the group parameter, see below). * ``auto per region``: will select as maximum the maximum of each region (so a different scale is used for each region) + + * ``group auto per region``: will select as maximum the maximum of each region (so a different scale is used for each region), for all tracks in the same group (defined by the group parameter, see below). * ``custom``: manually specify the maximum value. Can either specify a single value, which will then be used for all regions, or a comma-separated list of values (one per region) * ``scale_max``: in case "scale" is "custom", indicate the maximum value for the y-axis. + +* ``group``: if "scale" is "group auto" or "group auto per region", all tracks with the same value for this parameter will be scaled together. * ``scale_pos``: where the scale (min and max value of the y-axis) will be displayed @@ -218,12 +224,18 @@ Parameters: * ``scale``: how the maximum value for the y-axis is chosen * ``auto`` (default): will select as maximum the maximum across all regions. + + * ``group auto`` (default): will select as maximum the maximum across all regions, for all tracks in the same group (defined by the group parameter, see below). * ``auto per region``: will select as maximum the maximum of each region (so a different scale is used for each region) + + * ``group auto per region``: will select as maximum the maximum of each region (so a different scale is used for each region), for all tracks in the same group (defined by the group parameter, see below). * ``custom``: manually specify the maximum value. Can either specify a single value, which will then be used for all regions, or a comma-separated list of values (one per region) - + * ``scale_max``: in case "scale" is "custom", indicate the maximum value for the y-axis. + +* ``group``: if "scale" is "group auto" or "group auto per region", all tracks with the same value for this parameter will be scaled together. * ``scale_pos``: where the scale (min and max value of the y-axis) will be displayed diff --git a/figeno/cli/cli.py b/figeno/cli/cli.py index e072d35..eacf2e7 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.3" +__version__ = "1.4.0" def main(): parser = ArgumentParser("figeno",formatter_class=ArgumentDefaultsHelpFormatter) diff --git a/figeno/figeno.py b/figeno/figeno.py index 2a5de0b..d2b3630 100644 --- a/figeno/figeno.py +++ b/figeno/figeno.py @@ -316,6 +316,9 @@ def draw(self,output_config=None,warnings=[]): if max_size>100*min_size: warnings.append("You used regions with very different sizes, so the smaller regions may not be visible.") + # Check if group autoscale was used, in which case compute them. + self.compute_scales() + if self.figure_layout=="horizontal": self.draw_horizontal(**self.output,warnings=warnings) elif self.figure_layout=="stacked": @@ -507,6 +510,55 @@ def draw_circular(self,file,width=183,dpi=150,transparent=False,warnings=[]): plt.clf() plt.close('all') + def compute_scales(self): + self.compute_scales_instance(bigwig_track,"bigwig") + self.compute_scales_instance(coverage_track,"coverage") + + def compute_scales_instance(self,instance=bigwig_track,instance_name="bigwig"): + group2scales={} + group2scaletype={} + for t in self.tracks_list: + if isinstance(t,instance): + if t.scale=="custom": + if t.scale_max=="": t.scale_max=None + if t.scale_max is None: raise KnownException("Please provide the scale_max parameter if you use a custom scale.") + if isinstance(t.scale_max,str) and "," in t.scale_max: + try:t.scale_max=[float(x) for x in t.scale_max.split(",")] + except: raise KnownException("The scale_max parameter in a "+instance_name+" track should be a number (or a list of numbers separated by commas): "+str(self.scale_max)) + else: + try: t.scale_max=[float(t.scale_max)] + except: raise KnownException("The scale_max parameter in a "+instance_name+" track should be a number: "+str(self.scale_max)) + elif t.scale=="auto": + t.scale_max=t.compute_max(self.regions,per_region=False) + elif t.scale=="group auto": + if not hasattr(t,"group"): raise KnownException("Please provide the group parameter, if you use the group auto scale.") + maximum=t.compute_max(self.regions,per_region=False) + if t.group in group2scaletype: + if group2scaletype[t.group]!="group auto": raise KnownException("Please use the same scale (group auto or group auto per region) for all bigwig tracks of the same group.") + else: group2scaletype[t.group]="group auto" + if t.group in group2scales: group2scales[t.group] = max(maximum,group2scales[t.group]) + else: group2scales[t.group] = maximum + elif t.scale=="auto per region": + t.scale_max= t.compute_max(self.regions,per_region=True) + elif t.scale=="group auto per region": + if not hasattr(t,"group"): raise KnownException("Please provide the group parameter, if you use the group auto per region scale.") + if t.group in group2scaletype: + if group2scaletype[t.group]!="group auto per region": raise KnownException("Please use the same scale (group auto or group auto per region) for all bigwig tracks of the same group.") + else: group2scaletype[t.group]="group auto per region" + maxima=t.compute_max(self.regions,per_region=True) + if t.group in group2scales: group2scales[t.group] = [max(group2scales[t.group][i],maxima[i]) for i in range(len(maxima))] + else: group2scales[t.group] = maxima + else: + raise KnownException("Invalid scale for "+instance_name+" track: "+str(t.scale)+". Must be auto, auto per region, group auto, group auto per region, or custom.") + + for t in self.tracks_list: + if isinstance(t,instance): + if t.scale=="group auto" or t.scale=="group auto per region": + t.scale_max=group2scales[t.group] + if len(t.scale_max)>1 and t.scale_pos!="none": t.scale_pos="corner all" + + + def figeno_make(config=None,config_file=None,warnings=[]): if config is None and config_file is None: raise Exception("ERROR: a config or a config_file is required for figeno_make.") tp = tracks_plot(config=config,config_file=config_file) diff --git a/figeno/gui/package.json b/figeno/gui/package.json index 55857ea..6cb0221 100644 --- a/figeno/gui/package.json +++ b/figeno/gui/package.json @@ -1,6 +1,6 @@ { "name": "figeno", - "version": "1.3.3", + "version": "1.4.0", "private": true, "homepage": "./", "dependencies": { diff --git a/figeno/gui/src/App.js b/figeno/gui/src/App.js index ea847f9..585715d 100644 --- a/figeno/gui/src/App.js +++ b/figeno/gui/src/App.js @@ -158,12 +158,15 @@ export default function App() { t.bedmethyls = t.bedmethyls.map((b)=>{const newBed={...b};delete newBed.id; return newBed;}) } else if (t.type=="bigwig" || t.type=="coverage"){ - if (t.scale=="auto"){ + if (t.scale!="custom"){ delete t.scale_max; } + if (t.scale!="group auto" && t.scale!="group auto per region"){ + delete t.group; + } } else if (t.type=="hic"){ - if (t.scale=="auto"){ + if (t.scale!="auto"){ delete t.scale_min; delete t.scale_max; } diff --git a/figeno/gui/src/Track.jsx b/figeno/gui/src/Track.jsx index 1fe6af4..f8c7c1c 100644 --- a/figeno/gui/src/Track.jsx +++ b/figeno/gui/src/Track.jsx @@ -244,7 +244,9 @@ function BigWigTrack({track,set_value,openColorPanel, setFileDialogData,setFileD @@ -254,6 +256,13 @@ function BigWigTrack({track,set_value,openColorPanel, setFileDialogData,setFileD set_value("scale_max",e.target.value)} > ):"" } + {(track.scale=="group auto" || track.scale=="group auto per region")?( +
+ + set_value("group",e.target.value)} > +
):"" + } +
{set_value("scale",e.target.value)}}> + +
@@ -304,6 +315,12 @@ function CoverageTrack({track,set_value,openColorPanel, setFileDialogData,setFil set_value("scale_max",e.target.value)} > ):"" } + {(track.scale=="group auto" || track.scale=="group auto per region")?( +
+ + set_value("group",e.target.value)} > +
):"" + }