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: NR3C1-reddytime Multi-task fold: 5 Task index: 3 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 | 1442 | |
| 2 | 1148 | |
| 3 | 1269 | |
| 4 | 1347 | |
| 5 | 1179 | |
| 6 | 1098 | |
| 7 | 1967 | |
| 8 | 1987 | |
| 9 | 1943 | |
| 10 | 1437 |
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 | 8129 | 6159 | ||
| 2 | 1042 | 470 | ||
| 3 | 50 | |||
| 4 | 28 |
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 | 6760 | 6714 | ||
| 2 | 1356 | 575 | ||
| 3 | 1423 | 465 | ||
| 4 | 192 | 212 | ||
| 5 | 43 | 7 | ||
| 6 | 7 |
show_peaks_motif_table(os.path.join(peaks_path, "homer"), "homer")
| Motif | Log enrichment | PWM |
|---|---|---|
| 1 | -2861.71916 | |
| 2 | -2796.971807 | |
| 3 | -2401.025614 | |
| 4 | -2230.946872 | |
| 5 | -2088.672993 | |
| 6 | -1516.34557 | |
| 7 | -1193.383276 | |
| 8 | -1168.256924 | |
| 9 | -1066.277094 | |
| 10 | -792.778485 | |
| 11 | -499.234257 | |
| 12 | -324.590559 | |
| 13 | -290.07229 | |
| 14 | -142.606747 | |
| 15 | -100.169651 | |
| 16 | -96.0578 | |
| 17 | -67.720001 |
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 | -6021.413202 | -6683.941214 | ||
| 2 | -4206.204533 | -5516.434101 | ||
| 3 | -2297.133852 | -1405.154896 | ||
| 4 | -793.77273 | -808.313701 | ||
| 5 | -571.70039 | -679.640944 | ||
| 6 | -494.702143 | -319.962218 | ||
| 7 | -300.62203 | -143.549625 | ||
| 8 | -242.363684 | -73.849228 | ||
| 9 | -230.28972 | -66.350974 | ||
| 10 | -175.142675 | -62.594579 | ||
| 11 | -162.069745 | -55.217283 | ||
| 12 | -148.222873 | |||
| 13 | -143.295949 | |||
| 14 | -138.396496 | |||
| 15 | -109.623196 | |||
| 16 | -95.681637 | |||
| 17 | -86.574127 | |||
| 18 | -77.630229 | |||
| 19 | -28.480993 |
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 | -5617.538917 | -5757.305084 | ||
| 2 | -3609.559752 | -3548.327691 | ||
| 3 | -2803.534402 | -3248.988046 | ||
| 4 | -2128.035857 | -2207.340242 | ||
| 5 | -1522.660307 | -1335.076168 | ||
| 6 | -811.283565 | -770.083922 | ||
| 7 | -678.65499 | -644.567659 | ||
| 8 | -98.346317 | -197.321853 | ||
| 9 | -85.888266 | -187.074891 | ||
| 10 | -81.423968 | -94.831887 | ||
| 11 | -68.663202 | |||
| 12 | -34.481826 |
show_peaks_motif_table(os.path.join(peaks_path, "memechip"), "memechip")
| Motif | E-value | PWM |
|---|---|---|
| 1 | 9.8e-194 | |
| 2 | 3e-81 | |
| 3 | 3.3e-49 | |
| 4 | 3.4e-37 | |
| 5 | 6.7e-17 | |
| 6 | 7.3e-11 | |
| 7 | 8.8e-14 | |
| 8 | 5.5e-05 | |
| 9 | 0.031 | |
| 10 | 7.1 |
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.7e-147 | 8.3e-290 | ||
| 3 | 2.8e-47 | 7.3e-57 | ||
| 4 | 1.6e-10 | 2.4e-08 | ||
| 5 | 3.2e-11 | 170.0 | ||
| 6 | 3.2e-11 | 19000.0 | ||
| 7 | 3.2e-11 | 150000.0 | ||
| 8 | 3.2e-11 | 270000.0 | ||
| 9 | 1e-08 | 280000.0 | ||
| 10 | 1.8e-07 | 3200000.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 | 3.5e-114 | 2e-165 | ||
| 3 | 7.7e-101 | 2.6e-160 | ||
| 4 | 2.6e-70 | 3.4e-100 | ||
| 5 | 2.5e-46 | 1.1e-66 | ||
| 6 | 0.022 | 1.2e-25 | ||
| 7 | 200.0 | 1.2e-05 | ||
| 8 | 830.0 | 2800.0 | ||
| 9 | 1100000.0 | 5800000.0 | ||
| 10 | 3200000.0 | 5800000.0 |