diff --git a/config/base.cfg b/config/base.cfg index 626c3b4..d6c7652 100644 --- a/config/base.cfg +++ b/config/base.cfg @@ -12,7 +12,7 @@ alpha:0.8 ## Margins and dimensions: chrmar:0.1 ## Adjusts the gap between chromosomes and tracks. Higher values leads to more gap exmar:0.1 ## Extra margin at the top and bottom of plot area -marginchr:0.1 ## Margin between adjacent chromosomes when using --itx +marginchr:0.1 ## Margin between adjacent chromosomes when using --itx ## LEGEND legend:T ## To plot legend use T, use F to not plot legend @@ -20,3 +20,7 @@ genlegcol:-1 ## Number of columns for genome legend, set -1 for autom bbox:0,1.01,0.5,0.3 ## [Left edge, bottom edge, width, height] bbox_v:0,1.1,0.5,0.3 ## For vertical chromosomes (using -v option) bboxmar:0.5 ## Margin between genome and annotation legends + + +## Tracks: +norm:T ## For each chromosome, independently normalise the y-axis of tracks. Use T for normalising independently, and F to normalise based on max value across all chromosomes \ No newline at end of file diff --git a/example/base.cfg b/example/base.cfg index 626c3b4..d6c7652 100644 --- a/example/base.cfg +++ b/example/base.cfg @@ -12,7 +12,7 @@ alpha:0.8 ## Margins and dimensions: chrmar:0.1 ## Adjusts the gap between chromosomes and tracks. Higher values leads to more gap exmar:0.1 ## Extra margin at the top and bottom of plot area -marginchr:0.1 ## Margin between adjacent chromosomes when using --itx +marginchr:0.1 ## Margin between adjacent chromosomes when using --itx ## LEGEND legend:T ## To plot legend use T, use F to not plot legend @@ -20,3 +20,7 @@ genlegcol:-1 ## Number of columns for genome legend, set -1 for autom bbox:0,1.01,0.5,0.3 ## [Left edge, bottom edge, width, height] bbox_v:0,1.1,0.5,0.3 ## For vertical chromosomes (using -v option) bboxmar:0.5 ## Margin between genome and annotation legends + + +## Tracks: +norm:T ## For each chromosome, independently normalise the y-axis of tracks. Use T for normalising independently, and F to normalise based on max value across all chromosomes \ No newline at end of file diff --git a/plotsr/scripts/func.py b/plotsr/scripts/func.py index a14a3aa..bcdb8bf 100644 --- a/plotsr/scripts/func.py +++ b/plotsr/scripts/func.py @@ -199,17 +199,21 @@ def readbasecfg(f, v): cfg['tralwd'] = 0.1 cfg['duplwd'] = 0.1 cfg['alpha'] = 0.8 + # Set chromosome margins cfg['chrmar'] = 0.1 cfg['exmar'] = 0.1 + cfg['marginchr'] = 0.01 # Set ITX margin + # Set legend properties cfg['legend'] = True cfg['genlegcol'] = -1 cfg['bbox'] = [0, 1.01, 0.5, 0.3] cfg['bbox_v'] = [0, 1.1, 0.5, 0.3] cfg['bboxmar'] = 0.5 - # Set ITX margin - cfg['marginchr'] = 0.01 + + # track properties + cfg['norm'] = 'T' if f == '': @@ -257,11 +261,11 @@ def readbasecfg(f, v): logger.error("Non-numerical values {} provided for {}. Using default value.".format(line[1], line[0])) continue cfg['bboxmar'] = [float(i) for i in line[1]] - elif line[0] == 'legend': + elif line[0] in {'legend', 'norm'}: if line[1] not in ['T', 'F']: - logger.warning("Invalid value {} for legend in base.cfg. Valid values: T/F".format(line[1])) + logger.warning("Invalid value {} for {} in base.cfg. Valid values: T/F".format(line[1], line[0])) continue - cfg['legend'] = line[1] == 'T' + cfg[line[0]] = line[1] return cfg # END @@ -1792,7 +1796,7 @@ def drawtracks(ax, tracks, s, chrgrps, chrlengths, v, itx, cfg, minl=0, maxl=-1) rbuff = genbuff(0, chrlengths, chrgrps, chrs, maxl, v, cfg) for i in range(len(tracks)): # Plot background rectangles for the tracks - ti = tracks[i].ti # tranck index + ti = tracks[i].ti # track index for j in range(cl): if not v: x0 = 0 if not itx else 0 + rbuff[chrs[j]] @@ -1806,8 +1810,18 @@ def drawtracks(ax, tracks, s, chrgrps, chrlengths, v, itx, cfg, minl=0, maxl=-1) if tracks[i].ft in ['bed', 'bedgraph']: bedbin = tracks[i].bincnt - # Select positions that are within the limits + globaltposmax = None + if cfg['norm'] == 'F': + for j in range(cl): + # Select positions that are within the limits + if maxl != -1: + tpos = [k[1] for k in bedbin[chrs[j]] if minl <= k[0] <= maxl] + else: + tpos = [k[1] for k in bedbin[chrs[j]]] + globaltposmax = (max(tpos) if globaltposmax is None else max(tpos + [globaltposmax])) if len(tpos) > 0 else globaltposmax + for j in range(cl): + # Select positions that are within the limits if maxl != -1: chrpos = [k[0] if not itx else k[0] + rbuff[chrs[j]] for k in bedbin[chrs[j]] if minl <= k[0] <= maxl] tpos = [k[1] for k in bedbin[chrs[j]] if minl <= k[0] <= maxl] @@ -1815,7 +1829,7 @@ def drawtracks(ax, tracks, s, chrgrps, chrlengths, v, itx, cfg, minl=0, maxl=-1) chrpos = [k[0] if not itx else k[0] + rbuff[chrs[j]] for k in bedbin[chrs[j]]] tpos = [k[1] for k in bedbin[chrs[j]]] # print(cl, len(tpos)) - tposmax = max(tpos) if len(tpos) > 0 else 0 + tposmax = (max(tpos) if len(tpos) > 0 else 0) if cfg['norm'] == 'T' else globaltposmax tvars = {'color': tracks[i].lc, 'lw': tracks[i].lw, 'zorder': 2, 'alpha': tracks[i].ta} if not v: y0 = cl - j - th*(ti) if not itx else 1 - th*(ti)