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_HUVEC_profile.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: profile
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_slice" + str(score_center_size) + ".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_slice" + str(score_center_size) + ".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:15<00:00,  1.52it/s]
Loading Peaks: 25445it [00:45, 556.49it/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/1

Pattern 1/29

9901 seqlets

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

Pattern 2/29

4479 seqlets

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

Pattern 3/29

3971 seqlets

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

Pattern 4/29

2831 seqlets

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

Pattern 5/29

2460 seqlets

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

Pattern 6/29

2191 seqlets

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

Pattern 7/29

2095 seqlets

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

Pattern 8/29

2093 seqlets

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

Pattern 9/29

2028 seqlets

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

Pattern 10/29

1227 seqlets

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

Pattern 11/29

1211 seqlets

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

Pattern 12/29

1113 seqlets

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

Pattern 13/29

918 seqlets

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

Pattern 14/29

689 seqlets

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

Pattern 15/29

433 seqlets

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

Pattern 16/29

401 seqlets

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

Pattern 17/29

375 seqlets

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

Pattern 18/29

367 seqlets

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

Pattern 19/29

360 seqlets

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

Pattern 20/29

335 seqlets

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

Pattern 21/29

333 seqlets

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

Pattern 22/29

314 seqlets

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

Pattern 23/29

309 seqlets

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

Pattern 24/29

241 seqlets

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

Pattern 25/29

198 seqlets

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

Pattern 26/29

125 seqlets

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

Pattern 27/29

96 seqlets

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

Pattern 28/29

86 seqlets

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

Pattern 29/29

69 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/1

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 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.973965
Processing query 2 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.989277
Processing query 3 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.972661
Processing query 4 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=1
Processing query 5 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.985243
Processing query 6 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.964915
Processing query 7 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.985243
Processing query 8 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.960784
Processing query 9 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.958011
Processing query 10 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.977567
Processing query 11 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=1
Processing query 12 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.999116
Processing query 13 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=1
Processing query 14 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.989611
Processing query 15 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.975501
Processing query 16 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.980407
Processing query 17 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=1
Processing query 18 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.956318
Processing query 19 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.960009
Processing query 20 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.970592
Processing query 21 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=1
Processing query 22 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.971892
Processing query 23 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.978896
Processing query 24 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.947774
Processing query 25 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.98139
Processing query 26 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.970343
Processing query 27 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.997575
Processing query 28 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.969506
Processing query 29 out of 29 
Estimating pi_0 from all 3912 observed p-values.
Estimating pi_0.
Estimated pi_0=0.955411
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/29

Motif IDq-valPWM
MA0079.5-SP10.0179999
MA1511.2-KLF100.0179999
MA0516.3-SP20.0179999
MA0742.2-KLF120.0179999
MA1818.1-Zm00001d0522290.0210718

Motif 2/29

Motif IDq-valPWM
MA1713.1-ZNF6100.165887
MA0597.2-THAP10.209282
MA1723.1-PRDM90.209282
MA1845.1-Atoh70.209282
MA0499.2-MYOD10.209282

Motif 3/29

Motif IDq-valPWM
MA1513.1-KLF155.504e-05
MA0742.2-KLF129.66045e-05
MA1511.2-KLF109.66045e-05
MA0079.5-SP10.000103169
MA0516.3-SP20.000103169

Motif 4/29

Motif IDq-valPWM
MA0316.1-HAP55.03169e-05
MA0060.3-NFYA5.03169e-05
MA1644.1-NFYC5.88697e-05
MA0314.2-HAP30.00014079
MA0502.2-NFYB0.0223246

Motif 5/29

Motif IDq-valPWM
MA1935.1-ERF::FOXI11.93011e-05
MA0098.3-ETS11.93011e-05
MA0760.1-ERF1.93011e-05
MA0764.3-ETV41.93011e-05
MA0026.1-Eip74EF2.59503e-05

Motif 6/29

Motif IDq-valPWM
MA1817.1-Zm00001d0202674.60988e-08
MA1257.1-ERF94.60988e-08
MA1833.1-Zm00001d0493645.88087e-08
MA2022.1-LOB1.0499e-07
MA1246.1-LEP1.58746e-07

Motif 7/29

Motif IDq-valPWM
MA1988.1-Atf33.14455e-05
MA1928.1-BNC20.000141686
MA0489.2-Jun0.000141686
MA0099.3-FOS::JUN0.000316703
MA1130.1-FOSL2::JUN0.000316703

Motif 8/29

Motif IDq-valPWM
MA1833.1-Zm00001d0493643.88998e-09
MA1817.1-Zm00001d0202672.28587e-08
MA2022.1-LOB6.67141e-08
MA1239.1-ERF1046.81281e-08
MA1832.1-Zm00001d0023649.00925e-08

Motif 9/29

Motif IDq-valPWM
MA1475.1-CREB3L40.000971961
MA1438.1-atf-70.00133897
MA0609.2-CREM0.00133897
MA1346.1-TGA100.00249747
MA1133.1-JUN::JUNB0.00249747

Motif 10/29

Motif IDq-valPWM
MA1513.1-KLF150.00624402
MA1818.1-Zm00001d0522290.0109094
MA0742.2-KLF120.0120087
MA0079.5-SP10.0120087
MA1511.2-KLF100.0120087

Motif 11/29

Motif IDq-valPWM
MA0506.2-Nrf10.00103333

Motif 12/29

No TOMTOM matches passing threshold

Motif 13/29

No TOMTOM matches passing threshold

Motif 14/29

Motif IDq-valPWM
MA1933.1-ELK1::SREBF20.00459049
MA0598.3-EHF0.00459049
MA1992.1-Ikzf30.00459049
MA0474.3-Erg0.00872299
MA0473.3-ELF10.00872299

Motif 15/29

Motif IDq-valPWM
MA1653.1-ZNF1480.00179359
MA1961.1-PATZ10.00183855
MA1513.1-KLF150.00256296
MA1522.1-MAZ0.00256296
MA1239.1-ERF1040.00278492

Motif 16/29

Motif IDq-valPWM
MA1890.1-Klf158.73517e-08
MA1892.1-Klf5-like5.32269e-06
MA1893.1-Klf6-7-like5.32269e-06
MA1713.1-ZNF6100.00036614
MA1833.1-Zm00001d0493640.000554715

Motif 17/29

Motif IDq-valPWM
MA0527.1-ZBTB330.000121674

Motif 18/29

Motif IDq-valPWM
MA1820.1-Zm00001d0243240.000234695
MA0076.2-ELK40.000234695
MA0098.3-ETS10.000234695
MA0475.2-FLI10.000234695
MA0760.1-ERF0.000234695

Motif 19/29

Motif IDq-valPWM
MA1892.1-Klf5-like0.00186518
MA1890.1-Klf150.00186518
MA1893.1-Klf6-7-like0.00186518
MA1961.1-PATZ10.00186518
MA1513.1-KLF150.00186518

Motif 20/29

Motif IDq-valPWM
MA1818.1-Zm00001d0522292.57449e-05
MA1817.1-Zm00001d0202670.000134501
MA1245.2-ERF1120.000134501
MA1832.1-Zm00001d0023640.000134501
MA1821.1-Zm00001d0205950.000134501

Motif 21/29

Motif IDq-valPWM
MA1573.2-Thap111.17082e-07
MA0088.2-ZNF1430.0393721
MA1716.1-ZNF760.0456636
MA1625.1-Stat5b0.275256
MA0525.2-TP630.385228

Motif 22/29

Motif IDq-valPWM
MA1053.1-ERF1090.000152033
MA0748.2-YY20.000202618
MA0997.1-ERF0690.000229399
MA1754.1-ERF0730.000247371
MA1264.1-ERF0950.000247371

Motif 23/29

Motif IDq-valPWM
MA1880.1-Hey0.000179673
MA0506.2-Nrf10.000276918
MA1826.1-bHLH1450.000469291
MA0375.1-RSC300.00064048
MA1650.1-ZBTB140.00259778

Motif 24/29

Motif IDq-valPWM
MA1102.2-CTCFL0.000209235
MA1513.1-KLF150.000209235
MA0742.2-KLF120.00108533
MA0746.2-SP30.00108533
MA0747.1-SP80.00108533

Motif 25/29

Motif IDq-valPWM
MA1069.2-TGA60.000227323
MA0492.1-JUND0.000227323
MA0018.4-CREB10.000227323
MA1632.1-ATF20.000227323
MA0605.2-ATF30.000227323

Motif 26/29

Motif IDq-valPWM
MA1821.1-Zm00001d0205950.000242533
MA1832.1-Zm00001d0023640.000242533
MA1890.1-Klf150.000313621
MA1818.1-Zm00001d0522290.00105092
MA1257.1-ERF90.00120743

Motif 27/29

Motif IDq-valPWM
MA1929.1-CTCF0.275864
MA1815.1-GRF40.275864
MA1713.1-ZNF6100.275864
MA1257.1-ERF90.420726

Motif 28/29

Motif IDq-valPWM
MA1880.1-Hey0.0245307
MA0814.2-TFAP2C0.0245307
MA1892.1-Klf5-like0.0245307
MA1833.1-Zm00001d0493640.0245307
MA1893.1-Klf6-7-like0.0245307

Motif 29/29

Motif IDq-valPWM
MA0139.1-CTCF1.24114e-07
MA1102.2-CTCFL5.88328e-06
MA0531.1-CTCF0.000170905
MA1929.1-CTCF0.00530384
MA1930.1-CTCF0.0138183