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: 3 Single-task fold: 1
# 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 | 1314 | |
| 2 | 2000 | |
| 3 | 2000 | |
| 4 | 1999 | |
| 5 | 1928 | |
| 6 | 1320 | |
| 7 | 662 | |
| 8 | 539 | |
| 9 | 78 | |
| 10 | 66 |
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 | 12206 | 11974 | ||
| 2 | 2776 | 2256 | ||
| 3 | 830 | 1258 | ||
| 4 | 306 | |||
| 5 | 43 |
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 | 11269 | 12094 | ||
| 2 | 2343 | 2519 | ||
| 3 | 1059 | 534 | ||
| 4 | 230 | 429 | ||
| 5 | 4 | 127 | ||
| 6 | 64 | |||
| 7 | 4 |
show_peaks_motif_table(os.path.join(peaks_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 | PWM |
|---|---|---|
| 1 | -8119.584014 | |
| 2 | -4712.995136 | |
| 3 | -3927.495442 | |
| 4 | -3867.897114 | |
| 5 | -3540.849902 | |
| 6 | -3509.810373 | |
| 7 | -3347.269264 | |
| 8 | -3137.07037 | |
| 9 | -2828.896338 | |
| 10 | -2796.657344 | |
| 11 | -1891.154573 | |
| 12 | -1780.876243 | |
| 13 | -1529.680489 | |
| 14 | -1481.216324 | |
| 15 | -1477.490408 | |
| 16 | -1252.51596 | |
| 17 | -1243.740012 | |
| 18 | -1201.734693 | |
| 19 | -1198.303256 | |
| 20 | -713.693888 | |
| 21 | -472.729384 | |
| 22 | -415.831578 |
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 | -13155.444422 | -16631.807082 | ||
| 2 | -3354.935842 | -5506.644945 | ||
| 3 | -919.222734 | -1227.949279 | ||
| 4 | -874.695752 | -871.950571 | ||
| 5 | -481.984705 | -491.696729 | ||
| 6 | -457.583099 | -438.204186 | ||
| 7 | -350.902232 | -418.099207 | ||
| 8 | -334.983157 | -357.491228 | ||
| 9 | -219.150022 | -126.056227 | ||
| 10 | -218.82175 | -112.93305 | ||
| 11 | -210.219818 | -90.734819 | ||
| 12 | -176.465002 | -16.134697 | ||
| 13 | -152.855958 | |||
| 14 | -152.855958 | |||
| 15 | -142.684621 | |||
| 16 | -121.662801 | |||
| 17 | -74.99812 | |||
| 18 | -61.288917 |
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 | -12277.701588 | -19823.825097 | ||
| 2 | -4483.880925 | -6988.50427 | ||
| 3 | -1568.084186 | -2451.720981 | ||
| 4 | -703.458734 | -1247.96698 | ||
| 5 | -676.273043 | -550.514286 | ||
| 6 | -567.881314 | -475.905743 | ||
| 7 | -468.445038 | -436.358993 | ||
| 8 | -465.352945 | -259.360087 | ||
| 9 | -396.96147 | -220.264838 | ||
| 10 | -323.284811 | -134.368845 | ||
| 11 | -303.167855 | -125.180508 | ||
| 12 | -278.322245 | -86.92743 | ||
| 13 | -181.676239 | |||
| 14 | -166.467041 | |||
| 15 | -140.304197 | |||
| 16 | -125.615454 | |||
| 17 | -81.915139 | |||
| 18 | -58.517482 |
show_peaks_motif_table(os.path.join(peaks_path, "memechip"), "memechip")
| Motif | E-value | PWM |
|---|---|---|
| 1 | 3.8e-115 | |
| 2 | 4.3e-53 | |
| 3 | 3.4e-45 | |
| 4 | 1.8e-39 | |
| 5 | 3.6e-19 | |
| 6 | 4.5e-16 | |
| 7 | 8.4e-13 | |
| 8 | 6.5e-11 | |
| 9 | 7.2e-08 | |
| 10 | 1.1e-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.2e-142 | 1.5e-170 | ||
| 3 | 1.3e-16 | 2.3e-20 | ||
| 4 | 2.7e-10 | 4.3 | ||
| 5 | 0.013 | 4.4 | ||
| 6 | 0.094 | 47.0 | ||
| 7 | 26.0 | 9500.0 | ||
| 8 | 11.0 | 120000.0 | ||
| 9 | 480.0 | 180000.0 | ||
| 10 | 41000.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-315 | 0.0 | ||
| 2 | 2e-124 | 4.1e-168 | ||
| 3 | 1.2e-15 | 1.4e-75 | ||
| 4 | 1.5e-10 | 7.2e-20 | ||
| 5 | 0.0027 | 1.3e-05 | ||
| 6 | 0.0044 | 140.0 | ||
| 7 | 2.2 | 3100.0 | ||
| 8 | 660.0 | 66000.0 | ||
| 9 | 18000.0 | 570000.0 | ||
| 10 | 100000.0 | 910000.0 |