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: JUND Multi-task fold: 7 Task index: 12 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 | 1412 | |
| 2 | 2000 | |
| 3 | 2000 | |
| 4 | 2000 | |
| 5 | 1990 | |
| 6 | 1392 | |
| 7 | 833 | |
| 8 | 374 | |
| 9 | 149 | |
| 10 | 126 |
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 | 9118 | 6396 | ||
| 2 | 2986 | 3538 | ||
| 3 | 820 | 1022 | ||
| 4 | 20 | 118 |
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 | 9322 | 5366 | ||
| 2 | 4576 | 6031 | ||
| 3 | 496 | 290 | ||
| 4 | 87 | 45 | ||
| 5 | 4 | 3 |
show_peaks_motif_table(os.path.join(peaks_path, "homer"), "homer")
| Motif | Log enrichment | PWM |
|---|---|---|
| 1 | -8472.99567 | |
| 2 | -4799.539847 | |
| 3 | -3636.141527 | |
| 4 | -3214.97813 | |
| 5 | -3191.74423 | |
| 6 | -2267.552725 | |
| 7 | -2158.961656 | |
| 8 | -1890.698981 | |
| 9 | -1633.683107 | |
| 10 | -1616.055545 | |
| 11 | -1518.333571 | |
| 12 | -1450.704164 | |
| 13 | -1106.324977 | |
| 14 | -1068.682078 | |
| 15 | -710.041666 | |
| 16 | -440.411504 | |
| 17 | -425.408653 | |
| 18 | -395.783864 | |
| 19 | -274.840123 |
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 | -18536.476902 | -19875.059763 | ||
| 2 | -4784.089873 | -5454.629907 | ||
| 3 | -590.602854 | -381.215219 | ||
| 4 | -525.620228 | -234.624811 | ||
| 5 | -362.291941 | -218.817246 | ||
| 6 | -295.234294 | -156.814828 | ||
| 7 | -294.879317 | -130.582696 | ||
| 8 | -235.703163 | -113.77583 | ||
| 9 | -209.35613 | -100.614978 | ||
| 10 | -178.414016 | -95.218396 | ||
| 11 | -178.414016 | -77.459674 | ||
| 12 | -153.476473 | -43.582659 | ||
| 13 | -153.279506 | |||
| 14 | -133.600985 | |||
| 15 | -95.741961 | |||
| 16 | -89.64448 | |||
| 17 | -68.912209 | |||
| 18 | -28.5058 |
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 | -12870.749928 | -17585.941443 | ||
| 2 | -8109.957362 | -8050.852897 | ||
| 3 | -6070.026449 | -5929.515381 | ||
| 4 | -1590.754412 | -541.417951 | ||
| 5 | -314.422727 | -520.043254 | ||
| 6 | -241.465549 | -198.417388 | ||
| 7 | -218.625553 | -195.682382 | ||
| 8 | -182.112992 | -172.64996 | ||
| 9 | -163.637613 | -105.608405 | ||
| 10 | -140.518541 | -104.547365 | ||
| 11 | -109.30613 | -35.755825 | ||
| 12 | -73.781512 | |||
| 13 | -70.539012 | |||
| 14 | -52.135316 | |||
| 15 | -6.128815 |
show_peaks_motif_table(os.path.join(peaks_path, "memechip"), "memechip")
| Motif | E-value | PWM |
|---|---|---|
| 1 | 4.6e-130 | |
| 2 | 2.4e-56 | |
| 3 | 1.7e-51 | |
| 4 | 1e-45 | |
| 5 | 4.5e-38 | |
| 6 | 5.1e-26 | |
| 7 | 3.9e-15 | |
| 8 | 1.2e-11 | |
| 9 | 3.9e-07 | |
| 10 | 4.4e-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 | 0.0 | 0.0 | ||
| 2 | 1.3e-95 | 2e-255 | ||
| 3 | 3e-17 | 5.7e-149 | ||
| 4 | 8.1e-10 | 0.00021 | ||
| 5 | 0.15 | 25.0 | ||
| 6 | 13000.0 | 93000.0 | ||
| 7 | 9600.0 | 530000.0 | ||
| 8 | 140000.0 | 580000.0 | ||
| 9 | 820000.0 | 2800000.0 | ||
| 10 | 1900000.0 | 2800000.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 | 2.8e-111 | 8.3e-321 | ||
| 3 | 4.7e-88 | 3.2e-169 | ||
| 4 | 4.9e-55 | 650.0 | ||
| 5 | 1.8e-08 | 4000.0 | ||
| 6 | 0.0071 | 42000.0 | ||
| 7 | 5900.0 | 1700000.0 | ||
| 8 | 54000.0 | 2100000.0 | ||
| 9 | 56000.0 | 2200000.0 | ||
| 10 | 28000.0 | 2500000.0 |