In [1]:
# Filepaths and Hard-coded Defaults

proj_root = "/users/kcochran/projects/procap_models/"
sequence_path = proj_root + "genomes/GRCh38_no_alt_analysis_set_GCA_000001405.15.fasta"
chrom_sizes = proj_root + "genomes/hg38.chrom.sizes.withrRNA"

in_window = 2114
out_window = 1000
In [2]:
# stuff to get from config file

with open("2022-07-04_22-37-17_run1_modisco_config.txt") as config_f:
    config_dict = {line.split()[0] : line.strip().split()[1] for line in config_f}

modisco_out_path = config_dict["modisco_out_path"]
scoring_type = config_dict["scoring_type"]
score_center_size = int(config_dict["score_center_size"])
profile_display_center_size = int(config_dict["profile_display_center_size"])

# digest what's in config file

assay_type, model_type, cell, accession, modisco_dir_base = modisco_out_path.split("/")[-5:]
ts_part1, ts_part2, run_str, _ = modisco_dir_base.split("_")
timestamp = ts_part1 + "_" + ts_part2
run = int(run_str.replace("run", ""))
In [3]:
print(modisco_out_path)
print("cell_type:", cell, accession)
print("timestamp:", timestamp)
print("run:", run)
print("scoring_type:", scoring_type)
print("score_center_size:", score_center_size)
print("profile_display_center_size:", profile_display_center_size)
/users/kcochran//projects/procap_models/modisco_out/procap/bpnetlite_basic_v2/HUVEC/ENCSR098LLB/2022-07-04_22-37-17_run1_modisco
cell_type: HUVEC ENCSR098LLB
timestamp: 2022-07-04_22-37-17
run: 1
scoring_type: counts
score_center_size: 1000
profile_display_center_size: 400
In [4]:
data_dir = proj_root + "/data/procap/processed/" + cell + "/" + accession + "/"
plus_bw_path = data_dir + "final.5prime.pos.bigWig"
minus_bw_path = data_dir + "final.5prime.neg.bigWig"
val_peak_path = data_dir + "peaks_uni_and_bi_train_and_val.bed.gz"

val_save_dir = proj_root + "model_out/" + assay_type + "/" + model_type + "/" + cell + "/" + accession + "/"
val_save_path = val_save_dir + timestamp + "_run" + str(run) + "_train_and_val"

attr_save_path = val_save_dir.replace("model_out", "deepshap_out") + timestamp + "_run" + str(run) + "_deepshap"

if not modisco_out_path.endswith("/"):
    modisco_out_path = modisco_out_path + "/"
In [5]:
# task-specific filepaths

import os

assert scoring_type in ["profile", "counts"], scoring_type

if scoring_type == "profile":
    scores_path = attr_save_path + "_prof.npy"
    onehot_scores_path = attr_save_path + "_prof_onehot.npy"
    modisco_obj_path = modisco_out_path + "results_allChroms_prof_slice500.hdf5"
    seqlet_path = modisco_out_path + "seqlets_prof.txt"
else:
    scores_path = attr_save_path + "_count.npy"
    onehot_scores_path = attr_save_path + "_count_onehot.npy"
    modisco_obj_path = modisco_out_path + "results_allChroms_count_slice500.hdf5"
    seqlet_path = modisco_out_path + "seqlets_count.txt"
    
assert(os.path.exists(scores_path)), scores_path
assert(os.path.exists(onehot_scores_path)), onehot_scores_path
In [6]:
# Imports, Plotting Defaults

import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager

plot_params = {
    "figure.titlesize": 22,
    "axes.titlesize": 22,
    "axes.labelsize": 20,
    "legend.fontsize": 18,
    "xtick.labelsize": 16,
    "ytick.labelsize": 16,
    "font.weight": "bold"
}
plt.rcParams.update(plot_params)

from IPython.display import display
import tqdm
tqdm.tqdm_notebook()

import numpy as np

from view_modisco_results_utils import *
/users/kcochran/miniconda3/envs/procap/lib/python3.7/site-packages/ipykernel_launcher.py:19: TqdmDeprecationWarning: This function will be removed in tqdm==5.0.0
Please use `tqdm.notebook.tqdm` instead of `tqdm.tqdm_notebook`
In [7]:
# Load in True Profiles and Sequences

import sys
sys.path.append('../1_train_models')

from data_loading import extract_peaks

one_hot_seqs, true_profs = extract_peaks(sequence_path, 
    plus_bw_path, minus_bw_path, val_peak_path, in_window, out_window,
    max_jitter=0, verbose=True)

one_hot_seqs = one_hot_seqs.swapaxes(1,2)
one_hot_seqs = one_hot_seqs[:, (in_window // 2 - score_center_size // 2):(in_window // 2 + score_center_size // 2), :]
Reading FASTA: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 24/24 [00:17<00:00,  1.40it/s]
Loading Peaks: 25445it [00:43, 579.71it/s]
In [8]:
# Load in Coordinates of Examples
    
coords = load_coords(val_peak_path, in_window)
In [9]:
# Import SHAP scores, predicted profiles

hyp_scores = np.load(scores_path).swapaxes(1,2)
hyp_scores = hyp_scores[:, (in_window // 2 - score_center_size // 2):(in_window // 2 + score_center_size // 2), :]
pred_profs = np.exp(np.load(val_save_path + ".profs.npy"))
In [10]:
# Load modisco results object
    
tfm_obj = import_tfmodisco_results(modisco_obj_path, hyp_scores, one_hot_seqs)
In [11]:
motif_pfms, motif_hcwms, motif_cwms, \
    motif_pfms_short, num_seqlets, \
    motif_seqlets, num_metaclusters = plot_all_metaclusters(tfm_obj, one_hot_seqs, hyp_scores,
                                                            true_profs, pred_profs, coords,
                                                            in_window, out_window,
                                                            score_center_size,
                                                            profile_display_center_size)

Metacluster 1/2

Pattern 1/19

11184 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 2/19

7775 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 3/19

4902 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 4/19

4560 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 5/19

3609 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 6/19

2878 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 7/19

2132 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 8/19

991 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 9/19

937 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 10/19

820 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 11/19

601 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 12/19

555 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 13/19

446 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 14/19

353 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 15/19

257 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 16/19

233 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 17/19

82 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 18/19

54 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 19/19

20 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Metacluster 2/2

Pattern 1/6

349 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 2/6

231 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 3/6

90 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 4/6

84 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 5/6

77 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)

Pattern 6/6

59 seqlets

Sequence (PFM)
Hypothetical contributions (hCWM)
Actual contributions (CWM)
In [12]:
run_and_plot_tomtom(modisco_out_path, motif_pfms, motif_hcwms, motif_pfms_short, num_metaclusters)

Metacluster 1/2

The output directory '/users/kcochran//projects/procap_models/modisco_out/procap/bpnetlite_basic_v2/HUVEC/ENCSR098LLB/2022-07-04_22-37-17_run1_modisco/tomtom' already exists.
Its contents will be overwritten.
Processing query 1 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.984986
Processing query 2 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.969554
Processing query 3 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=1
Processing query 4 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.957943
Processing query 5 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.99435
Processing query 6 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.985243
Processing query 7 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.979675
Processing query 8 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=1
Processing query 9 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.955115
Processing query 10 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=1
Processing query 11 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.950134
Processing query 12 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.966045
Processing query 13 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.988412
Processing query 14 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.981903
Processing query 15 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.950868
Processing query 16 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=1
Processing query 17 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.945418
Processing query 18 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.955021
Processing query 19 out of 19 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.959405
Can't locate HtmlMonolithWr.pm:   /root/lib/perl/HtmlMonolithWr.pm: Permission denied at /software/meme/4.11.2/bin/tomtom_xml_to_html line 48.
Warning: tomtom_xml_to_html exited abnormally and may have failed to create HTML output.

Motif 1/19

Motif IDq-valPWM
MA0076.2-ELK41.7857e-07
MA0750.2-ZBTB7A1.01936e-05
MA0475.2-FLI11.13071e-05
MA0916.1-Ets21C1.13071e-05
MA0156.3-FEV1.68943e-05

Motif 2/19

Motif IDq-valPWM
MA1513.1-KLF155.65064e-05
MA0742.2-KLF128.64053e-05
MA0516.3-SP20.000122849
MA0685.2-SP40.000142343
MA1892.1-Klf5-like0.000142343

Motif 3/19

Motif IDq-valPWM
MA0316.1-HAP55.86726e-05
MA0060.3-NFYA7.64291e-05
MA1644.1-NFYC7.64291e-05
MA0314.2-HAP38.83181e-05
MA0502.2-NFYB0.0178259

Motif 4/19

Motif IDq-valPWM
MA1475.1-CREB3L40.000888715
MA1438.1-atf-70.00286329
MA0609.2-CREM0.00295286
MA1133.1-JUN::JUNB0.0033405
MA0656.1-JDP20.0033405

Motif 5/19

Motif IDq-valPWM
MA0506.2-Nrf10.000251211
MA1412.1-TSAR20.299908
MA1560.1-SOHLH20.325827
MA1826.1-bHLH1450.325827

Motif 6/19

Motif IDq-valPWM
MA1988.1-Atf31.21457e-05
MA0478.1-FOSL24.04053e-05
MA0099.3-FOS::JUN4.95373e-05
MA1141.1-FOS::JUND4.95373e-05
MA1928.1-BNC24.95373e-05

Motif 7/19

Motif IDq-valPWM
MA0748.2-YY26.7482e-05
MA1818.1-Zm00001d0522290.000118835
MA0998.1-ERF0960.000157267
MA0975.1-CRF20.000736098
MA0997.1-ERF0690.00083562

Motif 8/19

Motif IDq-valPWM
MA0527.1-ZBTB333.74447e-07

Motif 9/19

Motif IDq-valPWM
MA1832.1-Zm00001d0023641.32166e-07
MA1821.1-Zm00001d0205951.63262e-07
MA1819.1-Zm00001d0058921.63262e-07
MA1820.1-Zm00001d0243241.8367e-07
MA1818.1-Zm00001d0522295.28361e-07

Motif 10/19

Motif IDq-valPWM
MA1573.2-Thap111.04522e-07
MA0088.2-ZNF1430.0130015
MA1716.1-ZNF760.0208681
MA1625.1-Stat5b0.154017
MA0519.1-Stat5a::Stat5b0.166683

Motif 11/19

Motif IDq-valPWM
MA1817.1-Zm00001d0202674.17114e-05
MA1820.1-Zm00001d0243246.38324e-05
MA1833.1-Zm00001d0493640.000106007
MA1819.1-Zm00001d0058920.000112988
MA2022.1-LOB0.000112988

Motif 12/19

Motif IDq-valPWM
MA0139.1-CTCF1.47799e-07
MA1929.1-CTCF6.32899e-06
MA1930.1-CTCF4.1091e-05
MA1102.2-CTCFL4.7175e-05
MA0531.1-CTCF5.11583e-05

Motif 13/19

Motif IDq-valPWM
MA0375.1-RSC300.020898
MA0506.2-Nrf10.127474
MA0374.1-RSC30.127474
MA1650.1-ZBTB140.127474
MA0541.1-efl-10.127474

Motif 14/19

Motif IDq-valPWM
MA1069.2-TGA60.000352613
MA1951.1-FOS0.000352613
MA1070.2-TGA70.000352613
MA1047.2-TGA50.000352613
MA1632.1-ATF20.000352613

Motif 15/19

Motif IDq-valPWM
MA1819.1-Zm00001d0058921.30155e-05
MA1833.1-Zm00001d0493641.30155e-05
MA1820.1-Zm00001d0243241.30155e-05
MA1817.1-Zm00001d0202671.47764e-05
MA1832.1-Zm00001d0023642.79525e-05

Motif 16/19

Motif IDq-valPWM
MA1573.2-Thap116.16665e-05
MA1687.1-ARF140.19124

Motif 17/19

Motif IDq-valPWM
MA1833.1-Zm00001d0493640.000335276
MA1818.1-Zm00001d0522290.000335276
MA1819.1-Zm00001d0058920.000335276
MA1820.1-Zm00001d0243240.000506475
MA0975.1-CRF20.000506475

Motif 18/19

Motif IDq-valPWM
MA1833.1-Zm00001d0493644.16942e-07
MA1819.1-Zm00001d0058922.18877e-06
MA2022.1-LOB3.08322e-06
MA1817.1-Zm00001d0202673.08322e-06
MA1820.1-Zm00001d0243243.73654e-06

Motif 19/19

Motif IDq-valPWM
MA0139.1-CTCF1.82298e-05
MA1930.1-CTCF0.000925322
MA1929.1-CTCF0.00280574
MA1102.2-CTCFL0.00903296
MA0123.1-abi40.0323935

Metacluster 2/2

The output directory '/users/kcochran//projects/procap_models/modisco_out/procap/bpnetlite_basic_v2/HUVEC/ENCSR098LLB/2022-07-04_22-37-17_run1_modisco/tomtom' already exists.
Its contents will be overwritten.
Processing query 1 out of 6 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.954416
Processing query 2 out of 6 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.944628
Processing query 3 out of 6 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.935635
Processing query 4 out of 6 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.940069
Processing query 5 out of 6 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.937549
Processing query 6 out of 6 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.944628
Can't locate HtmlMonolithWr.pm:   /root/lib/perl/HtmlMonolithWr.pm: Permission denied at /software/meme/4.11.2/bin/tomtom_xml_to_html line 48.
Warning: tomtom_xml_to_html exited abnormally and may have failed to create HTML output.

Motif 1/6

Motif IDq-valPWM
MA1713.1-ZNF6100.00156149
MA1820.1-Zm00001d0243240.00254291
MA1817.1-Zm00001d0202670.00254291
MA1890.1-Klf150.00254291
MA1880.1-Hey0.00254291

Motif 2/6

Motif IDq-valPWM
MA1820.1-Zm00001d0243240.00149834
MA1832.1-Zm00001d0023640.00149834
MA1821.1-Zm00001d0205950.00149834
MA1817.1-Zm00001d0202670.00175702
MA1818.1-Zm00001d0522290.00190899

Motif 3/6

Motif IDq-valPWM
MA1819.1-Zm00001d0058929.00232e-06
MA1820.1-Zm00001d0243241.17346e-05
MA1817.1-Zm00001d0202676.79602e-05
MA1833.1-Zm00001d0493646.79602e-05
MA1410.1-StBRC18.52427e-05

Motif 4/6

Motif IDq-valPWM
MA1713.1-ZNF6100.00158906
MA1833.1-Zm00001d0493640.00158906
MA1976.1-ZNF3200.00171698
MA1817.1-Zm00001d0202670.00171698
MA1820.1-Zm00001d0243240.00171698

Motif 5/6

Motif IDq-valPWM
MA1833.1-Zm00001d0493640.000866506
MA1880.1-Hey0.000866506
MA1819.1-Zm00001d0058920.000866506
MA1410.1-StBRC10.000866506
MA1820.1-Zm00001d0243240.000866506

Motif 6/6

Motif IDq-valPWM
MA1833.1-Zm00001d0493640.0021638
MA1820.1-Zm00001d0243240.00534931
MA1817.1-Zm00001d0202670.00534931
MA1832.1-Zm00001d0023640.00534931
MA1713.1-ZNF6100.00534931