DiChIPMunk: on peaks and on multi-task seqlets and on single-task seqlets
HOMER: on peaks and on multi-task seqlets and on single-task seqlets
MEME: on peaks and on multitask seqlets and on single-task seqlets
import sys
import os
sys.path.append(os.path.abspath("/users/amtseng/tfmodisco/src/"))
from util import figure_to_vdom_image
import motif.read_motifs as read_motifs
from motif.read_motifs import pfm_to_pwm
import plot.viz_sequence as viz_sequence
import numpy as np
import matplotlib.pyplot as plt
import vdom.helpers as vdomh
from IPython.display import display
# Define parameters/fetch arguments
tf_name = os.environ["TFM_TF_NAME"]
multitask_fold = int(os.environ["TFM_MULTITASK_FOLD"])
if "TFM_TASK_INDEX" in os.environ:
task_index = int(os.environ["TFM_TASK_INDEX"])
singletask_fold = int(os.environ["TFM_SINGLETASK_FOLD"])
else:
task_index = None
singletask_fold = None
print("TF name: %s" % tf_name)
print("Multi-task fold: %s" % multitask_fold)
print("Task index: %s" % task_index)
print("Single-task fold: %s" % singletask_fold)
TF name: NR3C1-reddytime Multi-task fold: 5 Task index: 8 Single-task fold: 5
# Define paths and constants
base_path = "/users/amtseng/tfmodisco/results/classic_motifs/"
multitask_seqlets_dir = os.path.join(
base_path, "seqlets", "multitask_profile_finetune",
"%s_multitask_profile_finetune_fold%s" % (tf_name, multitask_fold)
)
if task_index is None:
peaks_path = os.path.join(base_path, "peaks", tf_name, "%s_peaks_taskall" % tf_name)
multitask_profile_seqlets_path = os.path.join(
multitask_seqlets_dir,
"%s_seqlets_profile_taskall" % tf_name
)
multitask_count_seqlets_path = os.path.join(
multitask_seqlets_dir,
"%s_seqlets_count_taskall" % tf_name
)
else:
peaks_path = os.path.join(base_path, "peaks", tf_name, "%s_peaks_task%d" % (tf_name, task_index))
multitask_profile_seqlets_path = os.path.join(
multitask_seqlets_dir,
"%s_seqlets_profile_task%d" % (tf_name, task_index)
)
multitask_count_seqlets_path = os.path.join(
multitask_seqlets_dir,
"%s_seqlets_count_task%d" % (tf_name, task_index)
)
singletask_seqlets_dir = os.path.join(
base_path, "seqlets", "singletask_profile_finetune",
"%s_singletask_profile_finetune_fold%s" % (tf_name, singletask_fold),
"task_%d" % task_index
)
singletask_profile_seqlets_path = os.path.join(
singletask_seqlets_dir,
"%s_seqlets_profile_task%d" % (tf_name, task_index)
)
singletask_count_seqlets_path = os.path.join(
singletask_seqlets_dir,
"%s_seqlets_count_task%d" % (tf_name, task_index)
)
def show_peaks_motif_table(results_path, mode):
"""
Shows a table of motifs from the given results path.
`mode` is either `dichipmunk`, `homer`, `meme`, or `memechip`.
"""
assert mode in ("dichipmunk", "homer", "meme", "memechip")
if mode == "dichipmunk":
score_name = "Supporting sequences"
pfms, score_vals = read_motifs.import_dichipmunk_pfms(results_path)
elif mode == "homer":
score_name = "Log enrichment"
pfms, score_vals = read_motifs.import_homer_pfms(results_path)
elif mode == "meme":
score_name = "E-value"
pfms, score_vals = read_motifs.import_meme_pfms(results_path)
else:
score_name = "E-value"
pfms, score_vals = read_motifs.import_meme_pfms(
os.path.join(results_path, "meme_out")
)
colgroup = vdomh.colgroup(
vdomh.col(style={"width": "5%"}),
vdomh.col(style={"width": "5%"}),
vdomh.col(style={"width": "40%"})
)
header = vdomh.thead(
vdomh.tr(
vdomh.th("Motif", style={"text-align": "center"}),
vdomh.th(score_name, style={"text-align": "center"}),
vdomh.th("PWM", style={"text-align": "center"})
)
)
body = []
for i, pfm in enumerate(pfms):
pwm = pfm_to_pwm(pfm)
if np.sum(pwm[:, [0, 2]]) < 0.5 * np.sum(pwm):
# Flip to purine-rich version
pwm = np.flip(pwm, axis=(0, 1))
fig = viz_sequence.plot_weights(pwm, figsize=(20, 4), return_fig=True)
fig.tight_layout()
body.append(
vdomh.tr(
vdomh.td(str(i + 1)),
vdomh.td(str(score_vals[i])),
vdomh.td(figure_to_vdom_image(fig))
)
)
display(vdomh.table(colgroup, header, vdomh.tbody(*body)))
plt.close("all")
def show_seqlets_motif_table(profile_results_path, count_results_path, mode):
"""
Shows a table of motifs from the given results path.
`mode` is either `dichipmunk`, `homer`, `meme`, or `memechip`
"""
assert mode in ("dichipmunk", "homer", "meme", "memechip")
if mode == "dichipmunk":
score_name = "Supporting sequences"
p_pfms, p_score_vals = read_motifs.import_dichipmunk_pfms(profile_results_path)
c_pfms, c_score_vals = read_motifs.import_dichipmunk_pfms(count_results_path)
elif mode == "homer":
score_name = "Log enrichment"
p_pfms, p_score_vals = read_motifs.import_homer_pfms(profile_results_path)
c_pfms, c_score_vals = read_motifs.import_homer_pfms(count_results_path)
elif mode == "meme":
score_name = "E-value"
p_pfms, p_score_vals = read_motifs.import_meme_pfms(profile_results_path)
c_pfms, c_score_vals = read_motifs.import_meme_pfms(count_results_path)
else:
score_name = "E-value"
p_pfms, p_score_vals = read_motifs.import_meme_pfms(
os.path.join(profile_results_path, "meme_out")
)
c_pfms, c_score_vals = read_motifs.import_meme_pfms(
os.path.join(count_results_path, "meme_out")
)
colgroup = vdomh.colgroup(
vdomh.col(style={"width": "5%"}),
vdomh.col(style={"width": "5%"}),
vdomh.col(style={"width": "40%"}),
vdomh.col(style={"width": "5%"}),
vdomh.col(style={"width": "40%"})
)
header = vdomh.thead(
vdomh.tr(
vdomh.th("Motif", style={"text-align": "center"}),
vdomh.th(score_name + " (profile)", style={"text-align": "center"}),
vdomh.th("PWM (profile)", style={"text-align": "center"}),
vdomh.th(score_name + " (count)", style={"text-align": "center"}),
vdomh.th("PWM (count)", style={"text-align": "center"})
)
)
body = []
for i in range(max(len(p_pfms), len(c_pfms))):
rows = [vdomh.td(str(i + 1))]
if i < len(p_pfms):
pwm = pfm_to_pwm(p_pfms[i])
if np.sum(pwm[:, [0, 2]]) < 0.5 * np.sum(pwm):
# Flip to purine-rich version
pwm = np.flip(pwm, axis=(0, 1))
fig = viz_sequence.plot_weights(pwm, figsize=(20, 4), return_fig=True)
fig.tight_layout()
rows.extend([
vdomh.td(str(p_score_vals[i])),
vdomh.td(figure_to_vdom_image(fig))
])
else:
rows.extend([vdomh.td(), vdomh.td()])
if i < len(c_pfms):
pwm = pfm_to_pwm(c_pfms[i])
if np.sum(pwm[:, [0, 2]]) < 0.5 * np.sum(pwm):
# Flip to purine-rich version
pwm = np.flip(pwm, axis=(0, 1))
fig = viz_sequence.plot_weights(pwm, figsize=(20, 4), return_fig=True)
fig.tight_layout()
rows.extend([
vdomh.td(str(c_score_vals[i])),
vdomh.td(figure_to_vdom_image(fig))
])
else:
rows.extend([vdomh.td(), vdomh.td()])
body.append(vdomh.tr(*rows))
display(vdomh.table(colgroup, header, vdomh.tbody(*body)))
plt.close("all")
show_peaks_motif_table(os.path.join(peaks_path, "dichipmunk"), "dichipmunk")
| Motif | Supporting sequences | PWM |
|---|---|---|
| 1 | 1462 | |
| 2 | 1235 | |
| 3 | 1197 | |
| 4 | 1245 | |
| 5 | 1973 | |
| 6 | 1010 | |
| 7 | 1980 | |
| 8 | 1968 | |
| 9 | 1633 | |
| 10 | 1455 |
show_seqlets_motif_table(
os.path.join(multitask_profile_seqlets_path, "dichipmunk"),
os.path.join(multitask_count_seqlets_path, "dichipmunk"),
"dichipmunk"
)
| Motif | Supporting sequences (profile) | PWM (profile) | Supporting sequences (count) | PWM (count) |
|---|---|---|---|---|
| 1 | 9711 | 4917 | ||
| 2 | 110 | 607 | ||
| 3 | 59 | 153 | ||
| 4 | 12 | 55 | ||
| 5 | 34 | |||
| 6 | 13 |
if task_index is not None:
show_seqlets_motif_table(
os.path.join(singletask_profile_seqlets_path, "dichipmunk"),
os.path.join(singletask_count_seqlets_path, "dichipmunk"),
"dichipmunk"
)
| Motif | Supporting sequences (profile) | PWM (profile) | Supporting sequences (count) | PWM (count) |
|---|---|---|---|---|
| 1 | 8500 | 2929 | ||
| 2 | 185 | 922 | ||
| 3 | 21 | 358 | ||
| 4 | 1 | 64 | ||
| 5 | 1 |
show_peaks_motif_table(os.path.join(peaks_path, "homer"), "homer")
/users/amtseng/tfmodisco/src/plot/viz_sequence.py:152: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). fig = plt.figure(figsize=figsize)
| Motif | Log enrichment | PWM |
|---|---|---|
| 1 | -3134.730652 | |
| 2 | -2957.639872 | |
| 3 | -1909.726442 | |
| 4 | -1725.120938 | |
| 5 | -1472.246547 | |
| 6 | -1228.294966 | |
| 7 | -1126.505047 | |
| 8 | -1061.21036 | |
| 9 | -947.633033 | |
| 10 | -718.556834 | |
| 11 | -642.702391 | |
| 12 | -551.415368 | |
| 13 | -546.550189 | |
| 14 | -441.420651 | |
| 15 | -353.781029 | |
| 16 | -282.61656 | |
| 17 | -196.048665 | |
| 18 | -182.062885 | |
| 19 | -128.288751 | |
| 20 | -128.271174 | |
| 21 | -62.615552 |
show_seqlets_motif_table(
os.path.join(multitask_profile_seqlets_path, "homer"),
os.path.join(multitask_count_seqlets_path, "homer"),
"homer"
)
| Motif | Log enrichment (profile) | PWM (profile) | Log enrichment (count) | PWM (count) |
|---|---|---|---|---|
| 1 | -5433.567919 | -5608.532528 | ||
| 2 | -5235.986132 | -4509.389014 | ||
| 3 | -4383.739602 | -2325.48348 | ||
| 4 | -1817.240397 | -800.610007 | ||
| 5 | -1108.829201 | -443.721845 | ||
| 6 | -513.162214 | -301.454831 | ||
| 7 | -241.534057 | -241.367603 | ||
| 8 | -124.915893 | -178.72833 | ||
| 9 | -124.037713 | -95.913342 | ||
| 10 | -110.569922 | -62.8285 | ||
| 11 | -110.569922 | |||
| 12 | -82.830791 | |||
| 13 | -82.709405 | |||
| 14 | -56.041277 | |||
| 15 | -36.61504 |
if task_index is not None:
show_seqlets_motif_table(
os.path.join(singletask_profile_seqlets_path, "homer"),
os.path.join(singletask_count_seqlets_path, "homer"),
"homer"
)
| Motif | Log enrichment (profile) | PWM (profile) | Log enrichment (count) | PWM (count) |
|---|---|---|---|---|
| 1 | -6128.074994 | -6640.075493 | ||
| 2 | -5034.100376 | -3087.528004 | ||
| 3 | -4652.816383 | -2689.724405 | ||
| 4 | -859.919643 | -475.174246 | ||
| 5 | -548.068582 | -351.426446 | ||
| 6 | -452.411042 | -294.747358 | ||
| 7 | -296.453102 | -260.46893 | ||
| 8 | -271.633643 | -138.608965 | ||
| 9 | -209.178202 | -109.509218 | ||
| 10 | -158.725898 | -59.037673 | ||
| 11 | -132.486066 | -28.530834 | ||
| 12 | -111.358273 | |||
| 13 | -0.978755 |
show_peaks_motif_table(os.path.join(peaks_path, "memechip"), "memechip")
| Motif | E-value | PWM |
|---|---|---|
| 1 | 5.5e-214 | |
| 2 | 5.6e-80 | |
| 3 | 1.4e-55 | |
| 4 | 1.9e-44 | |
| 5 | 9.5e-37 | |
| 6 | 1.3e-22 | |
| 7 | 5.5e-17 | |
| 8 | 1e-10 | |
| 9 | 7.6e-10 | |
| 10 | 2.6e-10 |
show_seqlets_motif_table(
os.path.join(multitask_profile_seqlets_path, "meme"),
os.path.join(multitask_count_seqlets_path, "meme"),
"meme"
)
| Motif | E-value (profile) | PWM (profile) | E-value (count) | PWM (count) |
|---|---|---|---|---|
| 1 | 2.5e-310 | 0.0 | ||
| 2 | 1.1e-182 | 1e-297 | ||
| 3 | 3.9e-104 | 1.2e-112 | ||
| 4 | 9.3e-22 | 6.2e-21 | ||
| 5 | 0.0012 | 0.015 | ||
| 6 | 1.5 | 0.29 | ||
| 7 | 220.0 | 0.48 | ||
| 8 | 3900.0 | 1800000.0 | ||
| 9 | 530.0 | 2000000.0 | ||
| 10 | 230000.0 | 3600000.0 |
if task_index is not None:
show_seqlets_motif_table(
os.path.join(singletask_profile_seqlets_path, "meme"),
os.path.join(singletask_count_seqlets_path, "meme"),
"meme"
)
| Motif | E-value (profile) | PWM (profile) | E-value (count) | PWM (count) |
|---|---|---|---|---|
| 1 | 2.6e-315 | 0.0 | ||
| 2 | 5.1e-182 | 5.8e-244 | ||
| 3 | 1.8e-133 | 2.8e-176 | ||
| 4 | 0.26 | 0.031 | ||
| 5 | 3.7 | 0.11 | ||
| 6 | 2300.0 | 0.93 | ||
| 7 | 3500.0 | 86000.0 | ||
| 8 | 40000.0 | 290000.0 | ||
| 9 | 160000.0 | 1100000.0 | ||
| 10 | 140000.0 | 1200000.0 |