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: REST Multi-task fold: 7 Task index: 4 Single-task fold: 10
# 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 | 1992 | |
2 | 2000 | |
3 | 2000 | |
4 | 1977 | |
5 | 1429 | |
6 | 943 | |
7 | 456 | |
8 | 293 | |
9 | 221 | |
10 | 139 |
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 | 4984 | 3066 | ||
2 | 982 | 549 | ||
3 | 191 | 187 | ||
4 | 150 | 122 | ||
5 | 15 | 15 |
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 | 6268 | 2994 | ||
2 | 786 | 637 | ||
3 | 219 | 152 | ||
4 | 76 | 55 | ||
5 | 2 |
show_peaks_motif_table(os.path.join(peaks_path, "homer"), "homer")
Motif | Log enrichment | PWM |
---|---|---|
1 | -5361.01426 | |
2 | -2774.701568 | |
3 | -1126.126432 | |
4 | -826.942061 | |
5 | -609.125961 | |
6 | -540.727077 | |
7 | -501.320098 | |
8 | -408.165611 | |
9 | -345.509108 | |
10 | -334.558132 | |
11 | -332.167286 | |
12 | -271.069279 | |
13 | -225.836819 | |
14 | -177.62895 | |
15 | -137.421893 | |
16 | -127.892157 |
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 | -7533.389989 | -11499.881527 | ||
2 | -6625.81213 | -7280.886325 | ||
3 | -4014.888029 | -1536.993912 | ||
4 | -2067.217271 | -1466.216651 | ||
5 | -208.53995 | -136.099415 | ||
6 | -126.113845 | -64.891885 | ||
7 | -113.881885 | -59.101692 | ||
8 | -81.736287 | -55.840619 | ||
9 | -68.564257 | -11.199178 | ||
10 | -55.674893 | |||
11 | -49.093079 |
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 | -7302.098357 | -10216.619936 | ||
2 | -7268.719385 | -7129.98307 | ||
3 | -208.347558 | -357.112504 | ||
4 | -171.445359 | -113.016833 | ||
5 | -167.428205 | -72.343132 | ||
6 | -147.573009 | -67.491514 | ||
7 | -99.827644 | -67.491514 | ||
8 | -97.287368 | -50.201372 | ||
9 | -51.641027 | |||
10 | -5.877331 |
show_peaks_motif_table(os.path.join(peaks_path, "memechip"), "memechip")
Motif | E-value | PWM |
---|---|---|
1 | 0.0 | |
2 | 5.7e-147 | |
3 | 5.2e-68 | |
4 | 3.2e-16 | |
5 | 9.2e-14 | |
6 | 2.3e-06 | |
7 | 5.3e-06 | |
8 | 1.7e-05 | |
9 | 630.0 | |
10 | 1100.0 |
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 | 0.0 | 0.0 | ||
3 | 6.1e-117 | 5.4e-186 | ||
4 | 2.3e-27 | 15000.0 | ||
5 | 7.3 | 150000.0 | ||
6 | 20.0 | 830000.0 | ||
7 | 2400.0 | 2500000.0 | ||
8 | 13000.0 | 3000000.0 | ||
9 | 46000.0 | 3000000.0 | ||
10 | 240000.0 | 1100000.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 | 7.1e-280 | 0.0 | ||
3 | 18.0 | 3.2e-65 | ||
4 | 0.14 | 8100.0 | ||
5 | 7200.0 | 59000.0 | ||
6 | 420000.0 | 760000.0 | ||
7 | 420000.0 | 1800000.0 | ||
8 | 410000.0 | 2000000.0 | ||
9 | 420000.0 | 3500000.0 | ||
10 | 690000.0 | 3600000.0 |