Skip to content

Commit 7c2537c

Browse files
committed
add group autoscale
1 parent 4d36a66 commit 7c2537c

File tree

11 files changed

+154
-56
lines changed

11 files changed

+154
-56
lines changed

docs/content/describe_figure.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,18 @@ Parameters:
151151
* ``scale``: how the maximum value for the y-axis is chosen
152152

153153
* ``auto`` (default): will select as maximum the maximum across all regions.
154+
155+
* ``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).
154156

155157
* ``auto per region``: will select as maximum the maximum of each region (so a different scale is used for each region)
158+
159+
* ``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).
156160

157161
* ``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)
158162

159163
* ``scale_max``: in case "scale" is "custom", indicate the maximum value for the y-axis.
164+
165+
* ``group``: if "scale" is "group auto" or "group auto per region", all tracks with the same value for this parameter will be scaled together.
160166

161167
* ``scale_pos``: where the scale (min and max value of the y-axis) will be displayed
162168

@@ -218,12 +224,18 @@ Parameters:
218224
* ``scale``: how the maximum value for the y-axis is chosen
219225

220226
* ``auto`` (default): will select as maximum the maximum across all regions.
227+
228+
* ``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).
221229

222230
* ``auto per region``: will select as maximum the maximum of each region (so a different scale is used for each region)
231+
232+
* ``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).
223233

224234
* ``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)
225-
235+
226236
* ``scale_max``: in case "scale" is "custom", indicate the maximum value for the y-axis.
237+
238+
* ``group``: if "scale" is "group auto" or "group auto per region", all tracks with the same value for this parameter will be scaled together.
227239

228240
* ``scale_pos``: where the scale (min and max value of the y-axis) will be displayed
229241

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.3"
5+
__version__ = "1.4.0"
66

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

figeno/figeno.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ def draw(self,output_config=None,warnings=[]):
316316
if max_size>100*min_size:
317317
warnings.append("You used regions with very different sizes, so the smaller regions may not be visible.")
318318

319+
# Check if group autoscale was used, in which case compute them.
320+
self.compute_scales()
321+
319322
if self.figure_layout=="horizontal":
320323
self.draw_horizontal(**self.output,warnings=warnings)
321324
elif self.figure_layout=="stacked":
@@ -507,6 +510,55 @@ def draw_circular(self,file,width=183,dpi=150,transparent=False,warnings=[]):
507510
plt.clf()
508511
plt.close('all')
509512

513+
def compute_scales(self):
514+
self.compute_scales_instance(bigwig_track,"bigwig")
515+
self.compute_scales_instance(coverage_track,"coverage")
516+
517+
def compute_scales_instance(self,instance=bigwig_track,instance_name="bigwig"):
518+
group2scales={}
519+
group2scaletype={}
520+
for t in self.tracks_list:
521+
if isinstance(t,instance):
522+
if t.scale=="custom":
523+
if t.scale_max=="": t.scale_max=None
524+
if t.scale_max is None: raise KnownException("Please provide the scale_max parameter if you use a custom scale.")
525+
if isinstance(t.scale_max,str) and "," in t.scale_max:
526+
try:t.scale_max=[float(x) for x in t.scale_max.split(",")]
527+
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))
528+
else:
529+
try: t.scale_max=[float(t.scale_max)]
530+
except: raise KnownException("The scale_max parameter in a "+instance_name+" track should be a number: "+str(self.scale_max))
531+
elif t.scale=="auto":
532+
t.scale_max=t.compute_max(self.regions,per_region=False)
533+
elif t.scale=="group auto":
534+
if not hasattr(t,"group"): raise KnownException("Please provide the group parameter, if you use the group auto scale.")
535+
maximum=t.compute_max(self.regions,per_region=False)
536+
if t.group in group2scaletype:
537+
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.")
538+
else: group2scaletype[t.group]="group auto"
539+
if t.group in group2scales: group2scales[t.group] = max(maximum,group2scales[t.group])
540+
else: group2scales[t.group] = maximum
541+
elif t.scale=="auto per region":
542+
t.scale_max= t.compute_max(self.regions,per_region=True)
543+
elif t.scale=="group auto per region":
544+
if not hasattr(t,"group"): raise KnownException("Please provide the group parameter, if you use the group auto per region scale.")
545+
if t.group in group2scaletype:
546+
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.")
547+
else: group2scaletype[t.group]="group auto per region"
548+
maxima=t.compute_max(self.regions,per_region=True)
549+
if t.group in group2scales: group2scales[t.group] = [max(group2scales[t.group][i],maxima[i]) for i in range(len(maxima))]
550+
else: group2scales[t.group] = maxima
551+
else:
552+
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.")
553+
554+
for t in self.tracks_list:
555+
if isinstance(t,instance):
556+
if t.scale=="group auto" or t.scale=="group auto per region":
557+
t.scale_max=group2scales[t.group]
558+
if len(t.scale_max)>1 and t.scale_pos!="none": t.scale_pos="corner all"
559+
560+
561+
510562
def figeno_make(config=None,config_file=None,warnings=[]):
511563
if config is None and config_file is None: raise Exception("ERROR: a config or a config_file is required for figeno_make.")
512564
tp = tracks_plot(config=config,config_file=config_file)

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.3",
3+
"version": "1.4.0",
44
"private": true,
55
"homepage": "./",
66
"dependencies": {

figeno/gui/src/App.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,15 @@ export default function App() {
158158
t.bedmethyls = t.bedmethyls.map((b)=>{const newBed={...b};delete newBed.id; return newBed;})
159159
}
160160
else if (t.type=="bigwig" || t.type=="coverage"){
161-
if (t.scale=="auto"){
161+
if (t.scale!="custom"){
162162
delete t.scale_max;
163163
}
164+
if (t.scale!="group auto" && t.scale!="group auto per region"){
165+
delete t.group;
166+
}
164167
}
165168
else if (t.type=="hic"){
166-
if (t.scale=="auto"){
169+
if (t.scale!="auto"){
167170
delete t.scale_min;
168171
delete t.scale_max;
169172
}

figeno/gui/src/Track.jsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ function BigWigTrack({track,set_value,openColorPanel, setFileDialogData,setFileD
244244
<label htmlFor={"scale"+track.id}>Scale:</label>
245245
<select id={"scale"+track.id} value={track.scale} onChange={(e) =>{set_value("scale",e.target.value)}}>
246246
<option className="dropDownOption" key="auto" value="auto">auto</option>
247+
<option className="dropDownOption" key="group auto" value="group auto">group auto</option>
247248
<option className="dropDownOption" key="auto per region" value="auto per region">auto per region</option>
249+
<option className="dropDownOption" key="group auto per region" value="group auto per region">group auto per region</option>
248250
<option className="dropDownOption" key="custom" value="custom">custom</option>
249251
</select>
250252
</div>
@@ -254,6 +256,13 @@ function BigWigTrack({track,set_value,openColorPanel, setFileDialogData,setFileD
254256
<input id={"scale_max"+track.id} style={{width:"3em"}} value={track.scale_max} onChange={(e) => set_value("scale_max",e.target.value)} ></input>
255257
</div>):""
256258
}
259+
{(track.scale=="group auto" || track.scale=="group auto per region")?(
260+
<div className='formItem'>
261+
<label htmlFor={"group"+track.id}>Group:</label>
262+
<input id={"group"+track.id} style={{width:"3em"}} value={track.group} onChange={(e) => set_value("group",e.target.value)} ></input>
263+
</div>):""
264+
}
265+
257266
<div className='formItem'>
258267
<label htmlFor={"scale_pos"+track.id}>Scale pos:</label>
259268
<select id={"scale_pos"+track.id} value={track.scale_pos} onChange={(e) =>{set_value("scale_pos",e.target.value)}}>
@@ -294,7 +303,9 @@ function CoverageTrack({track,set_value,openColorPanel, setFileDialogData,setFil
294303
<label htmlFor={"scale"+track.id}>Scale:</label>
295304
<select id={"scale"+track.id} value={track.scale} onChange={(e) =>{set_value("scale",e.target.value)}}>
296305
<option className="dropDownOption" key="auto" value="auto">auto</option>
306+
<option className="dropDownOption" key="group auto" value="group auto">group auto</option>
297307
<option className="dropDownOption" key="auto per region" value="auto per region">auto per region</option>
308+
<option className="dropDownOption" key="group auto per region" value="group auto per region">group auto per region</option>
298309
<option className="dropDownOption" key="custom" value="custom">custom</option>
299310
</select>
300311
</div>
@@ -304,6 +315,12 @@ function CoverageTrack({track,set_value,openColorPanel, setFileDialogData,setFil
304315
<input id={"scale_max"+track.id} style={{width:"3em"}} value={track.scale_max} onChange={(e) => set_value("scale_max",e.target.value)} ></input>
305316
</div>):""
306317
}
318+
{(track.scale=="group auto" || track.scale=="group auto per region")?(
319+
<div className='formItem'>
320+
<label htmlFor={"group"+track.id}>Group:</label>
321+
<input id={"group"+track.id} style={{width:"3em"}} value={track.group} onChange={(e) => set_value("group",e.target.value)} ></input>
322+
</div>):""
323+
}
307324
<div className='formItem'>
308325
<label htmlFor={"scale_pos"+track.id}>Scale pos:</label>
309326
<select id={"scale_pos"+track.id} value={track.scale_pos} onChange={(e) =>{set_value("scale_pos",e.target.value)}}>

figeno/gui/src/TracksContainer.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export const defaultTrackValues={
5757
n_bins:500,
5858
scale:"auto",
5959
scale_max:"",
60+
group:"1",
6061
scale_pos:"corner",
6162
upside_down:false
6263
},
@@ -72,6 +73,7 @@ export const defaultTrackValues={
7273
n_bins:500,
7374
scale:"auto",
7475
scale_max:"",
76+
group:"1",
7577
scale_pos:"corner",
7678
upside_down:false
7779
},

0 commit comments

Comments
 (0)