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: CEBPB Multi-task fold: 7 Task index: 5 Single-task fold: 9
# 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 | 1532 | |
2 | 1999 | |
3 | 2000 | |
4 | 2000 | |
5 | 1994 | |
6 | 1573 | |
7 | 806 | |
8 | 385 | |
9 | 210 | |
10 | 93 |
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 | 13451 | 16163 | ||
2 | 1271 | 863 | ||
3 | 1770 | 562 | ||
4 | 461 | |||
5 | 174 | |||
6 | 45 |
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 | 13934 | 15305 | ||
2 | 3498 | 1055 | ||
3 | 129 | |||
4 | 302 |
show_peaks_motif_table(os.path.join(peaks_path, "homer"), "homer")
Motif | Log enrichment | PWM |
---|---|---|
1 | -70819.268534 | |
2 | -13904.670864 | |
3 | -11347.363051 | |
4 | -9034.936024 | |
5 | -8306.133168 | |
6 | -8069.780233 | |
7 | -7652.101721 | |
8 | -7634.068302 | |
9 | -7119.891098 | |
10 | -6870.945336 | |
11 | -4410.145441 | |
12 | -3573.767699 | |
13 | -2236.461197 | |
14 | -1448.095098 | |
15 | -1415.69731 | |
16 | -1114.948278 | |
17 | -1088.606344 |
show_seqlets_motif_table(
os.path.join(multitask_profile_seqlets_path, "homer"),
os.path.join(multitask_count_seqlets_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 (profile) | PWM (profile) | Log enrichment (count) | PWM (count) |
---|---|---|---|---|
1 | -28465.925824 | -40243.331162 | ||
2 | -6446.546424 | -6470.162206 | ||
3 | -4667.6508 | -2874.149127 | ||
4 | -4143.277686 | -1420.52316 | ||
5 | -4104.235977 | -1281.627623 | ||
6 | -3494.864653 | -933.302096 | ||
7 | -2852.552531 | -843.550217 | ||
8 | -2434.609289 | -757.535337 | ||
9 | -2193.863831 | -610.22074 | ||
10 | -2115.597467 | -571.480735 | ||
11 | -2063.860127 | -156.781897 | ||
12 | -1367.404934 | -110.668042 | ||
13 | -1138.2927 | -52.314306 | ||
14 | -1111.613699 | -36.724315 | ||
15 | -924.747931 | -14.899709 | ||
16 | -875.422768 | |||
17 | -843.225306 | |||
18 | -628.878806 | |||
19 | -456.107752 | |||
20 | -435.319783 | |||
21 | -96.118514 | |||
22 | -52.821903 |
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 | -30109.216637 | -35859.573015 | ||
2 | -6839.468153 | -6595.216491 | ||
3 | -4478.224242 | -4197.25633 | ||
4 | -3157.637062 | -4122.619492 | ||
5 | -2884.012193 | -3602.471334 | ||
6 | -2005.136891 | -1690.873136 | ||
7 | -1504.764927 | -1554.289057 | ||
8 | -1336.068082 | -1082.438737 | ||
9 | -1164.263081 | -564.268161 | ||
10 | -972.261974 | -511.764253 | ||
11 | -772.412052 | -447.146651 | ||
12 | -696.780319 | -175.463769 | ||
13 | -622.412767 | -82.512563 | ||
14 | -512.075473 | -49.11947 | ||
15 | -506.894285 | -25.2809 | ||
16 | -412.237421 | |||
17 | -381.337869 | |||
18 | -75.348004 | |||
19 | -32.755835 |
show_peaks_motif_table(os.path.join(peaks_path, "memechip"), "memechip")
Motif | E-value | PWM |
---|---|---|
1 | 0.0 | |
2 | 0.0 | |
3 | 1e-252 | |
4 | 7.8e-202 | |
5 | 2.2e-74 | |
6 | 4.1e-54 | |
7 | 1.7e-53 | |
8 | 3.5e-28 | |
9 | 4.4e-21 | |
10 | 6.6e-13 |
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 | 0.0 | 0.0 | ||
2 | 2.9e-177 | 9.2e-92 | ||
3 | 5e-111 | 9.8e-77 | ||
4 | 1.5e-81 | 1.3e-38 | ||
5 | 1.3e-42 | 8.6e-18 | ||
6 | 1.4e-33 | 1.7e-15 | ||
7 | 2.5e-23 | 0.0066 | ||
8 | 2.9e-20 | 73.0 | ||
9 | 1.7e-16 | 180.0 | ||
10 | 8.8e-15 | 520.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 | 0.0 | 0.0 | ||
2 | 5.6e-171 | 2.1e-114 | ||
3 | 6.8e-102 | 7.6e-35 | ||
4 | 9e-38 | 2.8e-30 | ||
5 | 1.2e-30 | 1.2e-19 | ||
6 | 1.4e-14 | 4.9e-06 | ||
7 | 4.4e-12 | 0.05 | ||
8 | 2.4e-09 | 0.15 | ||
9 | 4.8e-08 | 890.0 | ||
10 | 2.4e-05 | 20000.0 |