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: MAX Multi-task fold: 1 Task index: 6 Single-task fold: 7
# 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 | 1999 | |
2 | 2000 | |
3 | 2000 | |
4 | 1998 | |
5 | 1833 | |
6 | 1340 | |
7 | 541 | |
8 | 327 | |
9 | 207 | |
10 | 176 |
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 | 11850 | 10912 | ||
2 | 2710 | 3982 | ||
3 | 915 | 227 | ||
4 | 1 | 102 | ||
5 | 7 |
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 | 11049 | 10314 | ||
2 | 2065 | 2711 | ||
3 | 505 | 1097 | ||
4 | 445 | 877 | ||
5 | 1 | 422 | ||
6 | 3 |
show_peaks_motif_table(os.path.join(peaks_path, "homer"), "homer")
Motif | Log enrichment | PWM |
---|---|---|
1 | -5154.837915 | |
2 | -4749.223098 | |
3 | -4183.750532 | |
4 | -3681.138665 | |
5 | -3357.255639 | |
6 | -3179.144002 | |
7 | -2022.199043 | |
8 | -1999.159528 | |
9 | -1961.068019 | |
10 | -1951.301945 | |
11 | -1313.417805 | |
12 | -1166.675944 | |
13 | -1070.158705 | |
14 | -890.521715 | |
15 | -687.05498 | |
16 | -468.669203 | |
17 | -425.866002 | |
18 | -323.307054 | |
19 | -294.517965 | |
20 | -241.675324 |
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 | -12966.728977 | -16510.0749 | ||
2 | -3522.318751 | -3666.744597 | ||
3 | -1685.793163 | -1389.624588 | ||
4 | -665.638052 | -1157.387363 | ||
5 | -548.636963 | -609.659695 | ||
6 | -296.985965 | -392.30636 | ||
7 | -274.346522 | -294.775059 | ||
8 | -244.479911 | -177.07971 | ||
9 | -239.091051 | -174.45938 | ||
10 | -206.266232 | -102.756348 | ||
11 | -181.110288 | -92.405309 | ||
12 | -88.1301 | -89.680226 | ||
13 | -79.588061 | -60.814937 | ||
14 | -76.480896 | |||
15 | -50.743405 | |||
16 | -40.713468 |
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 | -10186.069867 | -13714.36285 | ||
2 | -3772.297886 | -5935.82599 | ||
3 | -2232.064242 | -3259.942859 | ||
4 | -1343.79196 | -1993.880269 | ||
5 | -1227.480542 | -1545.380375 | ||
6 | -901.082601 | -1430.675523 | ||
7 | -894.03948 | -904.748849 | ||
8 | -533.673255 | -875.330301 | ||
9 | -495.068362 | -366.362505 | ||
10 | -362.495081 | -357.840848 | ||
11 | -276.196189 | -287.593806 | ||
12 | -261.791184 | -133.942306 | ||
13 | -78.015358 | -57.022181 | ||
14 | -39.862965 | |||
15 | -6.069506 |
show_peaks_motif_table(os.path.join(peaks_path, "memechip"), "memechip")
Motif | E-value | PWM |
---|---|---|
1 | 2.2e-49 | |
2 | 6.9e-33 | |
3 | 1.2e-20 | |
4 | 1.4e-19 | |
5 | 2.5e-18 | |
6 | 1.2e-15 | |
7 | 9.1e-07 | |
8 | 9.3e-11 | |
9 | 1.1e-06 | |
10 | 0.021 |
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 | 8.9e-77 | 8.4e-113 | ||
3 | 3.8e-33 | 2e-20 | ||
4 | 8.3e-21 | 9.3e-13 | ||
5 | 6.9e-06 | 82.0 | ||
6 | 270.0 | 410.0 | ||
7 | 890.0 | 12000.0 | ||
8 | 24000.0 | 440000.0 | ||
9 | 31000.0 | 460000.0 | ||
10 | 31000.0 | 770000.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 | 4.9e-270 | 0.0 | ||
2 | 9e-89 | 1.3e-134 | ||
3 | 1.9e-62 | 3.1e-61 | ||
4 | 1.3e-20 | 7.3e-25 | ||
5 | 2.3e-11 | 2.1e-21 | ||
6 | 2.1e-09 | 8.5e-17 | ||
7 | 0.0084 | 2.2e-11 | ||
8 | 0.065 | 2.1e-11 | ||
9 | 0.31 | 1.2e-06 | ||
10 | 67.0 | 0.0015 |