Skip to content

Commit

Permalink
Fixed signal alignment in composite plots
Browse files Browse the repository at this point in the history
- Signal plots with big numbers were not properly aligned with Hi-C
matrix. A fix was added to align signals values with max up to 9999.
  • Loading branch information
Leo Zuber committed Jul 19, 2023
1 parent 431fe52 commit c30d295
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions metaloci/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ def signal_bed(
bed_data["start"].append(lmi_geometry.bin_start[point])
bed_data["end"].append(lmi_geometry.bin_end[point])
bed_data["bin"].append(point)

except:

pass
Expand All @@ -465,7 +466,7 @@ def signal_plot(mlobject: mlo.MetalociObject, lmi_geometry: pd.DataFrame, metalo

for p in metalocis:

plt.axvline(x=p, color="red", linestyle=":", lw=1.5)
plt.axvline(x=p, color="red", linestyle=":", lw=1, zorder=0, alpha=0.3)

plt.axvline(x=mlobject.poi, color="lime", linestyle="--", lw=1.5)

Expand All @@ -479,7 +480,7 @@ def signal_plot(mlobject: mlo.MetalociObject, lmi_geometry: pd.DataFrame, metalo

sns.despine(top=True, right=True, left=False, bottom=True, offset=None, trim=False)

return sig_plt
return sig_plt, g


def place_composite(new_PI, ifile, ifactor, ixloc, iyloc):
Expand Down
14 changes: 11 additions & 3 deletions metaloci/tools/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def run(opts):

# selmetaloci = []

sig_plt = plot.signal_plot(mlobject, merged_lmi_geometry, selmetaloci, bins, coords_b)
sig_plt, ax = plot.signal_plot(mlobject, merged_lmi_geometry, selmetaloci, bins, coords_b)
sig_plt.savefig(f"{plot_filename}_signal.pdf", **plot_opt)
sig_plt.savefig(f"{plot_filename}_signal.png", **plot_opt)
plt.close()
Expand Down Expand Up @@ -312,10 +312,18 @@ def run(opts):

maxx = int((img1.size[1] * 0.4 + img2.size[1] * 0.25 + img3.size[1] * 0.25) * 1.3)

yticks_signal = ax.get_yticks()[1:-1]
max_chr_yax = max(len(str(max(yticks_signal))), len(str(min(yticks_signal))))
signal_left = {3 : 45, 4 : 30, 5 : 20, 6 : 9}

if max_chr_yax not in signal_left.keys():

signal_left[max_chr_yax] = 0

composite_image = Image.new(mode="RGBA", size=(maxx, 1550))

composite_image = plot.place_composite(composite_image, f"{plot_filename}_hic.png", 0.5, 100, 50) # HiC image
composite_image = plot.place_composite(composite_image, f"{plot_filename}_signal.png", 0.4, 42, 660) # Signal image
composite_image = plot.place_composite(composite_image, f"{plot_filename}_hic.png", 0.5, 100, 50) # HiC image
composite_image = plot.place_composite(composite_image, f"{plot_filename}_signal.png", 0.4, signal_left[max_chr_yax], 660) # Signal image
composite_image = plot.place_composite(composite_image, f"{plot_filename}_kk.png", 0.3, 1300, 50) # KK image
composite_image = plot.place_composite(composite_image, f"{plot_filename}_lmi.png", 0.4, 75, 900) # LMI scatter image
composite_image = plot.place_composite(composite_image, f"{plot_filename}_gsp.png", 0.25, 900, 900) # Gaudi signal image
Expand Down

0 comments on commit c30d295

Please sign in to comment.