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: 4 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 | 1264 | |
| 2 | 1272 | |
| 3 | 891 | |
| 4 | 1367 | |
| 5 | 1514 | |
| 6 | 1990 | |
| 7 | 1893 | |
| 8 | 1565 | |
| 9 | 1889 | |
| 10 | 1329 |
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 | 8082 | 5513 | ||
| 2 | 767 | 971 | ||
| 3 | 311 | 724 | ||
| 4 | 155 | 88 | ||
| 5 | 6 | 41 | ||
| 6 | 31 |
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 | 9091 | 8880 | ||
| 2 | 877 | 1052 | ||
| 3 | 507 | 364 | ||
| 4 | 47 | 132 | ||
| 5 | 42 |
show_peaks_motif_table(os.path.join(peaks_path, "homer"), "homer")
| Motif | Log enrichment | PWM |
|---|---|---|
| 1 | -7186.968291 | |
| 2 | -2398.668133 | |
| 3 | -2353.427297 | |
| 4 | -1833.186113 | |
| 5 | -1643.277133 | |
| 6 | -1570.310468 | |
| 7 | -1450.839965 | |
| 8 | -1378.396916 | |
| 9 | -717.711935 | |
| 10 | -542.471797 | |
| 11 | -366.508516 | |
| 12 | -229.934151 | |
| 13 | -172.526442 | |
| 14 | -116.097512 | |
| 15 | -111.793822 | |
| 16 | -108.635617 | |
| 17 | -92.599178 | |
| 18 | -88.55163 | |
| 19 | -58.860951 |
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 | -11772.220442 | -11680.191685 | ||
| 2 | -2526.359548 | -3735.089194 | ||
| 3 | -812.934863 | -770.63574 | ||
| 4 | -672.001693 | -686.481596 | ||
| 5 | -578.183541 | -611.396487 | ||
| 6 | -388.115507 | -354.739926 | ||
| 7 | -356.920432 | -332.308495 | ||
| 8 | -165.085189 | -147.341566 | ||
| 9 | -43.39613 | -130.381963 | ||
| 10 | -8.52474 | -80.905845 |
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"
)
/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 | -13510.695977 | -16048.52628 | ||
| 2 | -2372.917229 | -4535.240006 | ||
| 3 | -1039.026971 | -412.46003 | ||
| 4 | -231.994365 | -370.460236 | ||
| 5 | -212.709587 | -367.667854 | ||
| 6 | -151.650508 | -297.655494 | ||
| 7 | -146.737306 | -297.52983 | ||
| 8 | -85.840843 | -270.615772 | ||
| 9 | -83.562636 | -125.479269 | ||
| 10 | -70.087981 | -102.746592 | ||
| 11 | -61.769395 | -77.130064 | ||
| 12 | -61.769395 | -68.011113 | ||
| 13 | -37.583043 | -47.215361 | ||
| 14 | -32.780663 |
show_peaks_motif_table(os.path.join(peaks_path, "memechip"), "memechip")
| Motif | E-value | PWM |
|---|---|---|
| 1 | 0.0 | |
| 2 | 2.2e-123 | |
| 3 | 2.8e-38 | |
| 4 | 2.5e-29 | |
| 5 | 4.4e-11 | |
| 6 | 2.1e-12 | |
| 7 | 0.12 | |
| 8 | 0.044 | |
| 9 | 1.0 | |
| 10 | 0.01 |
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 | 7.4e-59 | 4.1e-185 | ||
| 3 | 5.4e-09 | 3.3e-30 | ||
| 4 | 0.0051 | 7e-13 | ||
| 5 | 79.0 | 2.5e-07 | ||
| 6 | 390.0 | 30.0 | ||
| 7 | 580000.0 | 11000.0 | ||
| 8 | 2800000.0 | 2600000.0 | ||
| 9 | 2800000.0 | 4100000.0 | ||
| 10 | 3400000.0 | 4300000.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.6e-54 | 5.8e-164 | ||
| 3 | 800000.0 | 9.9e-20 | ||
| 4 | 1900000.0 | 1700.0 | ||
| 5 | 6000000.0 | 8500.0 | ||
| 6 | 4500000.0 | 230000.0 | ||
| 7 | 8300000.0 | 290000.0 | ||
| 8 | 8700000.0 | 1800000.0 | ||
| 9 | 12000000.0 | 2100000.0 | ||
| 10 | 13000000.0 | 4000000.0 |