Skip to content

Commit

Permalink
Added a new option mz for markers.bed that allows adjusting the zor…
Browse files Browse the repository at this point in the history
…der of markers (#77)
  • Loading branch information
mnshgl0110 committed May 22, 2024
1 parent 89b8eb8 commit d30309e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
9 changes: 5 additions & 4 deletions example/markers.bed
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
##mt = marker type
##mc = marker colour
##ms = marker size
##mz = marker zorder (objects with higher zorder value are plotted over objects with lower zorder values)
##tt = text
##tc = text colour
##ts = text size
##tf = text font
##tp = text position
#chr start end genome_id tags
Chr3 4035330 4035331 eri mt:v;mc:black;ms:3;tt:Inversion 1;tp:0.02;ts:8;tf:Arial;tc:black
Chr4 2322547 2322548 ler mt:^;mc:black;ms:3;tt:Inversion 2;tp:-0.07;ts:8;tf:Arial;tc:black
Chr3 8792851 8792852 col-0 mt:.;mc:red;ms:10;tt:Notal aligned;tp:0.02;ts:8;tf:Arial;tc:black
Chr1 1 10000000 ler mt:_;mc:black;ms:1;tt:contig;tp:0.02;ts:8;tf:Tinos;tc:black
Chr3 4035330 4035331 eri mt:v;mc:black;ms:3;mz:2;tt:Inversion 1;tp:0.02;ts:8;tf:Arial;tc:black
Chr4 2322547 2322548 ler mt:^;mc:black;ms:3;mz:2;tt:Inversion 2;tp:-0.07;ts:8;tf:Arial;tc:black
Chr3 8792851 8792852 col-0 mt:.;mc:red;ms:10;mz:2;tt:Notal aligned;tp:0.02;ts:8;tf:Arial;tc:black
Chr1 1 10000000 ler mt:_;mc:black;ms:1;mz:2;tt:contig;tp:0.02;ts:8;tf:Tinos;tc:black
35 changes: 18 additions & 17 deletions plotsr/scripts/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def __init__(self, c, start, end, genome, v):
self.mt = '.'
self.mc = 'black'
self.ms = 8
self.mz = 1
self.tt = ''
self.tc = 'black'
self.ts = matplotlib.rcParams['font.size']
Expand All @@ -368,7 +369,7 @@ def addtags(self, tags):
self.logger.error("Error in using colour: {} for position {}:{}-{}. Use correct hexadecimal colours or named colours define in matplotlib (https://matplotlib.org/stable/gallery/color/named_colors.html)".format(v, self.chr, self.start, self.end))
sys.exit()
setattr(self, n, v)
elif n in ['ms', 'ts', 'tp']:
elif n in ['ms', 'ts', 'tp', 'mz']:
try: float(v)
except ValueError:
self.logger.error("Non-numerical value {} for {} at marker position: {}:{}-{}".format(v, n, self.chr, self.start, self.end))
Expand Down Expand Up @@ -1738,24 +1739,24 @@ def drawmarkers(ax, b, v, chrlengths, indents, chrs, chrgrps, S, cfg, itx, minl=
indent = indents[ind]
if not v:
if m.mt != '_':
ax.plot(m.start, indent-offset, marker=m.mt, color=m.mc, markersize=m.ms)
ax.text(m.start, indent-offset+m.tp, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='center', va='bottom')
ax.plot(m.start, indent-offset, marker=m.mt, color=m.mc, markersize=m.ms, zorder=m.mz)
ax.text(m.start, indent-offset+m.tp, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='center', va='bottom', zorder=m.mz)
else:
# https://github.com/schneebergerlab/plotsr/issues/72
# ax.axhline(y=indent-offset, xmin=m.start/ax.get_xlim()[1], xmax=m.end/ax.get_xlim()[1], color=m.mc, linewidth=m.ms)
ax_xlim = ax.get_xlim()[1] - ax.get_xlim()[0]
ax.axhline(y=indent-offset, xmin=(m.start-ax.get_xlim()[0])/ax_xlim, xmax=(m.end-ax.get_xlim()[0])/ax_xlim, color=m.mc, linewidth=m.ms, solid_capstyle='butt')
ax.text((m.start + m.end)/2, indent-offset+m.tp, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='center', va='bottom')
ax.axhline(y=indent-offset, xmin=(m.start-ax.get_xlim()[0])/ax_xlim, xmax=(m.end-ax.get_xlim()[0])/ax_xlim, color=m.mc, linewidth=m.ms, solid_capstyle='butt', zorder=m.mz)
ax.text((m.start + m.end)/2, indent-offset+m.tp, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='center', va='bottom', zorder=m.mz)
# if m.tt != '':
# ax.text(m.start, indent-offset+m.tp, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='center', va='bottom')
elif v:
if m.mt != '|':
ax.plot(indent+offset, m.start, marker=m.mt, color=m.mc, markersize=m.ms)
ax.text(indent+offset-m.tp, m.start, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='left', va='center', rotation='vertical')
ax.plot(indent+offset, m.start, marker=m.mt, color=m.mc, markersize=m.ms, zorder=m.mz)
ax.text(indent+offset-m.tp, m.start, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='left', va='center', rotation='vertical', zorder=m.mz)
else:
ax_ylim = ax.get_ylim()[1] - ax.get_ylim()[0]
ax.axvline(x=indent+offset, ymin=(m.start - ax.get_ylim()[0])/ax_ylim, ymax=(m.end - ax.get_ylim()[0])/ax_ylim, color=m.mc, linewidth=m.ms, solid_capstyle='butt')
ax.text(indent+offset-m.tp, (m.start+m.end)/2, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='left', va='center', rotation='vertical')
ax.axvline(x=indent+offset, ymin=(m.start - ax.get_ylim()[0])/ax_ylim, ymax=(m.end - ax.get_ylim()[0])/ax_ylim, color=m.mc, linewidth=m.ms, solid_capstyle='butt', zorder=m.mz)
ax.text(indent+offset-m.tp, (m.start+m.end)/2, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='left', va='center', rotation='vertical', zorder=m.mz)
# if m.tt != '':
# ax.text(indent+offset-m.tp, m.start, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='left', va='center', rotation='vertical')
elif itx:
Expand All @@ -1764,22 +1765,22 @@ def drawmarkers(ax, b, v, chrlengths, indents, chrs, chrgrps, S, cfg, itx, minl=
step = S/(len(chrlengths)-1)
if not v:
if m.mt != '_':
ax.plot(m.start+buff[chrgrps[chrid][ind]], S - (step*ind), marker=m.mt, color=m.mc, markersize=m.ms)
ax.text(m.start+buff[chrgrps[chrid][ind]], S - (step*ind) + m.tp, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='center', va='bottom')
ax.plot(m.start+buff[chrgrps[chrid][ind]], S - (step*ind), marker=m.mt, color=m.mc, markersize=m.ms, zorder=m.mz)
ax.text(m.start+buff[chrgrps[chrid][ind]], S - (step*ind) + m.tp, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='center', va='bottom', zorder=m.mz)
else:
# TODO: Check and fix the issue reported in https://github.com/schneebergerlab/plotsr/issues/72
ax.axhline(y=S - (step*ind), xmin=(m.start+buff[chrgrps[chrid][ind]])/ax.get_xlim()[1], xmax=(m.end+buff[chrgrps[chrid][ind]])/ax.get_xlim()[1], color=m.mc, linewidth=m.ms)
ax.text(((m.start+m.end)/2)+buff[chrgrps[chrid][ind]], S - (step*ind) + m.tp, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='center', va='bottom')
ax.axhline(y=S - (step*ind), xmin=(m.start+buff[chrgrps[chrid][ind]])/ax.get_xlim()[1], xmax=(m.end+buff[chrgrps[chrid][ind]])/ax.get_xlim()[1], color=m.mc, linewidth=m.ms, zorder=m.mz)
ax.text(((m.start+m.end)/2)+buff[chrgrps[chrid][ind]], S - (step*ind) + m.tp, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='center', va='bottom', zorder=m.mz)
# if m.tt != '':
# ax.text(m.start+buff[chrgrps[chrid][ind]], S - (step*ind) + m.tp, m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='center', va='bottom')
elif v:
if m.mt != '|':
ax.plot(1 - S + (step*ind), m.start+buff[chrgrps[chrid][ind]], marker=m.mt, color=m.mc, markersize=m.ms)
ax.text(1 - S + (step*ind)-m.tp, m.start+buff[chrgrps[chrid][ind]], m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='left', va='center', rotation='vertical')
ax.plot(1 - S + (step*ind), m.start+buff[chrgrps[chrid][ind]], marker=m.mt, color=m.mc, markersize=m.ms, zorder=m.mz)
ax.text(1 - S + (step*ind)-m.tp, m.start+buff[chrgrps[chrid][ind]], m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='left', va='center', rotation='vertical', zorder=m.mz)
else:
# TODO: Check and fix the issue reported in https://github.com/schneebergerlab/plotsr/issues/72
ax.axvline(x=1 - S + (step*ind), ymin=(m.start+buff[chrgrps[chrid][ind]])/ax.get_ylim()[1], ymax=(m.end+buff[chrgrps[chrid][ind]])/ax.get_ylim()[1], color=m.mc, linewidth=m.ms)
ax.text(1 - S + (step*ind)-m.tp, ((m.start+m.end)/2)+buff[chrgrps[chrid][ind]], m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='left', va='center', rotation='vertical')
ax.axvline(x=1 - S + (step*ind), ymin=(m.start+buff[chrgrps[chrid][ind]])/ax.get_ylim()[1], ymax=(m.end+buff[chrgrps[chrid][ind]])/ax.get_ylim()[1], color=m.mc, linewidth=m.ms, zorder=m.mz)
ax.text(1 - S + (step*ind)-m.tp, ((m.start+m.end)/2)+buff[chrgrps[chrid][ind]], m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='left', va='center', rotation='vertical', zorder=m.mz)
# if m.tt != '':
# ax.text(1 - S + (step*ind)-m.tp, m.start+buff[chrgrps[chrid][ind]], m.tt, color=m.tc, fontsize=m.ts, fontfamily=m.tf, ha='left', va='center', rotation='vertical')
return ax
Expand Down

0 comments on commit d30309e

Please sign in to comment.