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: 5 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 | 2000 | |
| 2 | 2000 | |
| 3 | 2000 | |
| 4 | 1994 | |
| 5 | 1744 | |
| 6 | 848 | |
| 7 | 365 | |
| 8 | 142 | |
| 9 | 71 | |
| 10 | 59 |
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 | 7626 | 9410 | ||
| 2 | 3652 | 4010 | ||
| 3 | 1083 | 669 | ||
| 4 | 92 | |||
| 5 | 35 | |||
| 6 | 11 |
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 | 12893 | 14682 | ||
| 2 | 1025 | 536 | ||
| 3 | 333 | 8 | ||
| 4 | 18 |
show_peaks_motif_table(os.path.join(peaks_path, "homer"), "homer")
| Motif | Log enrichment | PWM |
|---|---|---|
| 1 | -5570.274023 | |
| 2 | -5196.928741 | |
| 3 | -4783.488304 | |
| 4 | -3864.754095 | |
| 5 | -3832.409025 | |
| 6 | -3415.244227 | |
| 7 | -3146.161065 | |
| 8 | -2831.26839 | |
| 9 | -2242.13685 | |
| 10 | -1990.271919 | |
| 11 | -1909.665453 | |
| 12 | -1582.984687 | |
| 13 | -907.938697 | |
| 14 | -770.090351 | |
| 15 | -710.516765 | |
| 16 | -585.258716 | |
| 17 | -555.0297 | |
| 18 | -392.145592 | |
| 19 | -192.531129 | |
| 20 | -162.166918 |
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 | -6946.16733 | -10338.909169 | ||
| 2 | -2058.961889 | -1719.599428 | ||
| 3 | -1016.284134 | -1646.290508 | ||
| 4 | -857.351907 | -1283.088839 | ||
| 5 | -767.55783 | -758.565123 | ||
| 6 | -602.133087 | -374.331995 | ||
| 7 | -592.382408 | -311.647136 | ||
| 8 | -450.911095 | -239.086825 | ||
| 9 | -397.961499 | -226.340904 | ||
| 10 | -337.310317 | -204.948567 | ||
| 11 | -238.18326 | -184.307007 | ||
| 12 | -213.68041 | -178.686921 | ||
| 13 | -183.515053 | -172.601175 | ||
| 14 | -157.138929 | -169.861508 | ||
| 15 | -126.761381 | -158.09939 | ||
| 16 | -121.377205 | -113.376948 | ||
| 17 | -88.297155 | -100.608755 | ||
| 18 | -81.753156 | -29.136129 | ||
| 19 | -72.339353 | -19.000448 | ||
| 20 | -64.481732 |
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 | -6496.264389 | -9172.80969 | ||
| 2 | -5644.470235 | -9151.539465 | ||
| 3 | -5114.645862 | -8026.6975 | ||
| 4 | -1904.829643 | -1646.293114 | ||
| 5 | -795.69855 | -708.575302 | ||
| 6 | -471.907712 | -450.313312 | ||
| 7 | -428.105488 | -342.71742 | ||
| 8 | -323.876493 | -245.032937 | ||
| 9 | -208.11183 | -216.34386 | ||
| 10 | -177.975373 | -183.883903 | ||
| 11 | -151.286337 | -163.169412 | ||
| 12 | -118.160092 | -143.08499 | ||
| 13 | -116.436504 | -107.036944 | ||
| 14 | -106.350845 | -79.845798 | ||
| 15 | -85.103831 | |||
| 16 | -65.667142 | |||
| 17 | -32.857372 | |||
| 18 | -29.062123 |
show_peaks_motif_table(os.path.join(peaks_path, "memechip"), "memechip")
| Motif | E-value | PWM |
|---|---|---|
| 1 | 9e-74 | |
| 2 | 2e-27 | |
| 3 | 4e-24 | |
| 4 | 2.8e-19 | |
| 5 | 3.1e-16 | |
| 6 | 2.7e-05 | |
| 7 | 4.1e-07 | |
| 8 | 0.00021 | |
| 9 | 0.5 | |
| 10 | 6.3e-06 |
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 | 1.4e-141 | 1e-240 | ||
| 2 | 2e-39 | 6.3e-51 | ||
| 3 | 8.4e-16 | 6.9e-47 | ||
| 4 | 1.5e-13 | 9.1e-41 | ||
| 5 | 4.3e-06 | 9.3e-06 | ||
| 6 | 0.0046 | 0.00038 | ||
| 7 | 0.0038 | 64.0 | ||
| 8 | 2.4 | 200000.0 | ||
| 9 | 45.0 | 600000.0 | ||
| 10 | 240.0 | 280000.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.3e-195 | 1.5e-253 | ||
| 2 | 1.2e-139 | 3.4e-217 | ||
| 3 | 7.3e-61 | 2.5e-130 | ||
| 4 | 2.8e-17 | 8.6e-17 | ||
| 5 | 5.5e-14 | 6.4e-10 | ||
| 6 | 0.018 | 0.017 | ||
| 7 | 1.3 | 4100.0 | ||
| 8 | 5.1 | 12000000.0 | ||
| 9 | 170.0 | 22000000.0 | ||
| 10 | 210.0 | 110000000.0 |