In [1]:
%load_ext autoreload
%autoreload 2

import pickle
from collections import OrderedDict
import numpy as np
import pandas as pd
import os
import subprocess
import math
import copy
import pickle
import h5py
import glob

from matlas.genome_data import *
from matlas.pwms import shorten_tfname, get_motifDB_id_maps
from matlas.matches import fig2vdom, vdom_pssm
#from basepair.modisco.results import ModiscoResult
from matlas.modisco_results import ModiscoResult


project_root = "/mnt/lab_data/kundaje/msharmin/mouse_hem/with_tfd"
oak_root = "/oak/stanford/groups/akundaje/msharmin/mouse_hem/from_labcluster/with_tfd"
srv_root = "/srv/scratch/msharmin/mouse_hem/with_tfd"
data_name = "full_mouse50"
modisco_root = "{0}/{1}/Naive_modisco2019_msharmin".format(oak_root, data_name)
modisco_root = "{0}/{1}/Naive_modisco2019".format(srv_root, data_name)

homer_root = "{0}/{1}/Naive_scans".format(srv_root, data_name)
model_root = "{0}/{1}/fineFactorized".format(srv_root, data_name)
basset_root = "{0}/{1}/Naive_basset_motifs".format(srv_root, data_name)
reportfile= "/mnt/lab_data/kundaje/msharmin/mouse_hem/with_tfd/full_mouse50/filtering samples_MS2.xlsx"
sheetname = "filter23"
load data from labcluster
Using TensorFlow backend.
TF-MoDISco is using the TensorFlow backend.
In [31]:
from matlas.dlutils import load_deeplift_data
from matlas.fimo_hits import (dichotomize_chipseq_for_gold_standard, 
                              assign_significance_on_fimo_hits,
                              retain_fimo_hits_within_nb,
                              optimize_performance_info,
                              check_performance_competition,
                              collect_motif_df,
                              plot_various_instance_scores,
                              decide_optimum_threshold
                             )

def prepare_verification_data_per_cell(
    task_idx=273,
    tf_biosample = "MEL cell line",
    the_k=0.05627951420283896,
    atac_root="/mnt/lab_data2/msharmin/oc-atlas/mtf/atac_specific_hits",
    instance_root="/mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits",
    deeplift_root="/mnt/lab_data2/msharmin/oc-atlas/deeplift2019_h5",
    background_files_root="/mnt/lab_data2/msharmin/oc-atlas/mtf/t_stats"
):

    tf_targets = sorted(set(CHIP_PEAK_BEDS[tf_biosample].keys()).intersection(set(CHIP_TO_MOTIF.keys())))
    motifs = [CHIP_TO_MOTIF[tf] for tf in tf_targets]
    
    # divide chipseq peaks into gold_standard and nongold for each tf under a cell type
    fimodir = "{0}/task_{1}".format(atac_root, task_idx)
    atacpeaks = "{}/peaks.bed".format(fimodir)
    #print(fimodir)
    #print(atacpeaks)
    for tf, motif in zip(tf_targets, motifs):
        print(tf_biosample, tf, motif)
        chippeaks = "{0}/{1}".format(CHIP_PEAK_BED_ROOT, CHIP_PEAK_BEDS[tf_biosample][tf])
        instancedir="{}/task_{}/{}".format(instance_root, task_idx, motif)
        #print(chippeaks)
        #print(instancedir)
        #print()

        best_key = decide_optimum_threshold(instancedir)
        tmp = np.load("{}/cdf_cdf.npz".format(instancedir), allow_pickle=True)
        check_performance_competition(tmp.f.a.tolist(), tmp.f.b.tolist(), tmp.f.c.tolist(),
                                     info="{}, {}, {}".format(task_idx, tf_biosample, motif),
                                      selected_key=best_key
                                    )
        plot_various_instance_scores(instancedir, fimodir, motif, selected_key=best_key)

        # with decided threshold fix the distance plots, 
        #compute_joint_chip_matrix and plot_joint_chip_matrix
        
        
        
    return None
from ast import literal_eval

def prepare_verification_data():
    total_zeros = 0
    for key, tf_biosamples in OC_TO_TF_SAMPLES.items():
        task_idx, sample_id, oc_sample = literal_eval(key)
        
        print(task_idx, oc_sample, tf_biosamples, len(tf_biosamples))
        total_zeros = prepare_verification_data_per_cell(task_idx=task_idx, 
                                           tf_biosample=tf_biosamples[0],
                                           the_k=PER_BASE_BACKGROUND_IMPORTANCES[task_idx]
                                          )
        #break
    return None


prepare_verification_data()
140 Bone marrow derived pre-B cell ['bone marrow'] 1
bone marrow CTCF-mouse Ctcf
142 bone marrow-derived macrophages (Unstimulated) ['bone marrow macrophage'] 1
bone marrow macrophage CTCF-mouse Ctcf
143 bone marrow-derived macrophages(Lipid A stimulation 120min) ['bone marrow macrophage'] 1
bone marrow macrophage CTCF-mouse Ctcf
177 Cortical excitatory neurons ['cortical plate'] 1
cortical plate CTCF-mouse Ctcf
180 Thymus MECs (Aire+/+) ['thymus'] 1
thymus CTCF-mouse Ctcf
189 Megakaryocyte primary cell ['megakaryocyte'] 1
megakaryocyte FLI1-mouse Fli1
192 Erythroblast primary cell ['erythroblast'] 1
erythroblast GATA1-mouse Gata1
193 Megakaryocyte progenitor cell ['megakaryocyte'] 1
megakaryocyte FLI1-mouse Fli1
202 Liver (Adult 8 weeks) ['liver'] 1
liver CTCF-mouse Ctcf
liver EP300-mouse Ep300
liver GATA4-mouse Gata4
203 Lung (adult-8wks) ['lung'] 1
lung CTCF-mouse Ctcf
lung EP300-mouse Ep300
210 mouse spleen B cells, CD43-,CD11b-         (immature B cells1) ['spleen'] 1
220 Fibroblast (adult-8wks) ['embryonic fibroblast'] 1
embryonic fibroblast CTCF-mouse Ctcf
223 Kidney(adult-8wks) ['kidney'] 1
kidney CTCF-mouse Ctcf
224 Liver(adult-8wks) ['liver'] 1
liver CTCF-mouse Ctcf
liver EP300-mouse Ep300
liver GATA4-mouse Gata4
225 Liver(E14.5) ['liver'] 1
liver CTCF-mouse Ctcf
liver EP300-mouse Ep300
liver GATA4-mouse Gata4
227 Lung(adult-8wks) ['lung'] 1
lung CTCF-mouse Ctcf
lung EP300-mouse Ep300
229 Mouse lung (E14.5) ['lung'] 1
lung CTCF-mouse Ctcf
lung EP300-mouse Ep300
230 Heart (adult-8wks) ['heart'] 1
heart CTCF-mouse Ctcf
heart EP300-mouse Ep300
235 mixed embryonic mouse retina(E14.5) ['embryonic fibroblast'] 1
embryonic fibroblast CTCF-mouse Ctcf
236 Cerebellum ['cerebellum'] 1
cerebellum CTCF-mouse Ctcf
245 mixed embryonic mouse forebrain(E14.5) ['forebrain'] 1
forebrain CTCF-mouse Ctcf
248 mixed embryonic mouse hindbrain(E11.5) ['hindbrain'] 1
hindbrain CTCF-mouse Ctcf
249 hindbrain embryo(E14.5) ['hindbrain'] 1
hindbrain CTCF-mouse Ctcf
250 mixed embryonic mouse midbrain(E14.5) ['midbrain'] 1
midbrain CTCF-mouse Ctcf
251 midbrain embryo(E11.5) ['midbrain'] 1
midbrain CTCF-mouse Ctcf
263 Large Intestine (adult-8wks) ['intestine'] 1
intestine CTCF-mouse Ctcf
266 spleen(adult-8wks) ['spleen'] 1
271 CH12.LX cell line ['CH12.LX'] 1
CH12.LX BHLHE40-mouse Bhlhe40
CH12.LX CTCF-mouse Ctcf
CH12.LX E2F4-mouse E2f4
CH12.LX ELF1-mouse Elf1
CH12.LX EP300-mouse Ep300
CH12.LX ETS1-mouse Ets1
CH12.LX GABPA-mouse Gabpa
CH12.LX IRF4-mouse Irf4
CH12.LX JUN-mouse Jun
CH12.LX JUND-mouse Jund
CH12.LX MAFK-mouse Mafk
CH12.LX MAX-mouse Max
CH12.LX MAZ-mouse Maz
CH12.LX MEF2A-mouse Mef2a
CH12.LX MXI1-mouse Mxi1
CH12.LX MYC-mouse Myc
CH12.LX NRF1-mouse Nrf1
CH12.LX PAX5-mouse Pax5
CH12.LX TBP-mouse Tbp
CH12.LX TCF12-mouse Tcf12
CH12.LX USF1-mouse Usf1
CH12.LX USF2-mouse Usf2
CH12.LX ZKSCAN1-mouse Zkscan1
273 MEL cell line ['MEL cell line'] 1
MEL cell line BHLHE40-mouse Bhlhe40
MEL cell line CTCF-mouse Ctcf
MEL cell line E2F4-mouse E2f4
MEL cell line ELF1-mouse Elf1
MEL cell line EP300-mouse Ep300
MEL cell line ETS1-mouse Ets1
MEL cell line GABPA-mouse Gabpa
MEL cell line GATA1-mouse Gata1
MEL cell line JUND-mouse Jund
MEL cell line MAFK-mouse Mafk
MEL cell line MAX-mouse Max
MEL cell line MAZ-mouse Maz
MEL cell line MEF2A-mouse Mef2a
MEL cell line MXI1-mouse Mxi1
MEL cell line MYB-mouse Myb
MEL cell line MYC-mouse Myc
MEL cell line NRF1-mouse Nrf1
MEL cell line TAL1-mouse Tal1
MEL cell line TBP-mouse Tbp
MEL cell line TCF12-mouse Tcf12
MEL cell line USF1-mouse Usf1
MEL cell line USF2-mouse Usf2
MEL cell line ZKSCAN1-mouse Zkscan1
274 MEL cell line treated with 125 uM zinc dichloride for 24 hours ['MEL cell line'] 1
MEL cell line BHLHE40-mouse Bhlhe40
MEL cell line CTCF-mouse Ctcf
MEL cell line E2F4-mouse E2f4
MEL cell line ELF1-mouse Elf1
MEL cell line EP300-mouse Ep300
MEL cell line ETS1-mouse Ets1
MEL cell line GABPA-mouse Gabpa
MEL cell line GATA1-mouse Gata1
MEL cell line JUND-mouse Jund
MEL cell line MAFK-mouse Mafk
MEL cell line MAX-mouse Max
MEL cell line MAZ-mouse Maz
MEL cell line MEF2A-mouse Mef2a
MEL cell line MXI1-mouse Mxi1
MEL cell line MYB-mouse Myb
MEL cell line MYC-mouse Myc
MEL cell line NRF1-mouse Nrf1
MEL cell line TAL1-mouse Tal1
MEL cell line TBP-mouse Tbp
MEL cell line TCF12-mouse Tcf12
MEL cell line USF1-mouse Usf1
MEL cell line USF2-mouse Usf2
MEL cell line ZKSCAN1-mouse Zkscan1
44 macrophage  ['bone marrow macrophage'] 1
bone marrow macrophage CTCF-mouse Ctcf
52 Small Intestine ['small intestine'] 1
small intestine CTCF-mouse Ctcf
53 Large Intestine ['intestine'] 1
intestine CTCF-mouse Ctcf
54 Lung ['lung'] 1
lung CTCF-mouse Ctcf
lung EP300-mouse Ep300
56 Heart ['heart'] 1
heart CTCF-mouse Ctcf
heart EP300-mouse Ep300
60 testis ['testis'] 1
testis CTCF-mouse Ctcf
63 stomach ['stomach'] 1
stomach CTCF-mouse Ctcf
stomach EP300-mouse Ep300
67 Brain- Olfactory Bulb ['olfactory bulb'] 1
olfactory bulb CTCF-mouse Ctcf
72 Brain- Cerebellum ['cerebellum'] 1
cerebellum CTCF-mouse Ctcf
In [5]:
# determine the threshold and send it to both display as params

instancedir = "/mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_140/Ctcf"
tmp = np.load("{}/cdf_cdf.npz".format(instancedir), allow_pickle=True)
dl_performdict, nondl_performdict, performdict = tmp.f.a.tolist(), tmp.f.b.tolist(), tmp.f.c.tolist()
performdict
Out[5]:
OrderedDict([('Fimo',
                 Balanced Accuracy  F1-score  Precision    Recall  auPRC_labeled  \
              0            0.74047  0.424785   0.284553  0.837535       0.534617   
              
                 auPRC_scored  N_instance_passing_k  N_atacs_passing_k  Imbalance  
              0      0.523323                200814              73877   0.144816  ),
             ('Fimo50',
                 Balanced Accuracy  F1-score  Precision    Recall  auPRC_labeled  \
              0           0.713836  0.494412   0.460747  0.533384       0.485627   
              
                 auPRC_scored  N_instance_passing_k  N_atacs_passing_k  Imbalance  
              0      0.411968                 83013              31050   0.144816  )])
In [13]:
precisions = [(v)['Precision'].values[0] for v in dl_performdict.values()]
df = pd.DataFrame({'keys': list(dl_performdict.keys()),
              'Precision': [(v)['Precision'].values[0] for v in dl_performdict.values()],
              'Recall': [(v)['Recall'].values[0] for v in dl_performdict.values()],
                   'auPRC_scored': [(v)['auPRC_scored'].values[0] for v in dl_performdict.values()],
                   'F1-score': [(v)['F1-score'].values[0] for v in dl_performdict.values()],
                   'Balanced Accuracy': [(v)['Balanced Accuracy'].values[0] for v in dl_performdict.values()]
              
             })
nondf = pd.DataFrame({'keys': list(nondl_performdict.keys()),
              'Precision': [(v)['Precision'].values[0] for v in nondl_performdict.values()],
              'Recall': [(v)['Recall'].values[0] for v in nondl_performdict.values()],
                      'auPRC_scored': [(v)['auPRC_scored'].values[0] for v in nondl_performdict.values()],
                      'F1-score': [(v)['F1-score'].values[0] for v in nondl_performdict.values()],
                   'Balanced Accuracy': [(v)['Balanced Accuracy'].values[0] for v in nondl_performdict.values()]
              
             })
precision_cond = df['Precision']>=performdict['Fimo50']['Precision'].values[0]
df = df[precision_cond]
nondf = nondf[precision_cond]

recall_cond = df['Recall']>=nondf['Recall']
df = df[recall_cond]
nondf = nondf[recall_cond]
pd.concat([df, nondf], axis=1)
recall_cond
Out[13]:
0    True
1    True
2    True
3    True
4    True
5    True
Name: Recall, dtype: bool
In [36]:
from scipy.stats import *
from scipy import stats
from matlas.fimo_hits import collect_motif_df, PEAK_TYPES

from sklearn.metrics import precision_recall_curve
from sklearn.metrics import f1_score
from sklearn.metrics import auc
from matplotlib import pyplot as plt


from matlas.fimo_hits import compute_instance_calling_performance

perform_df, truth_df = compute_instance_calling_performance(
            bedname="Dl_k50.0.bed",
            key_to_optimize="deeplift_cdf",
            instancedir="/mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4",
            atac_bed="/mnt/lab_data2/msharmin/oc-atlas/mtf/atac_specific_hits/task_224/peaks.bed",
            verbose=True
        )

# fimo_df, truth_df = compute_peak_calling_performance(key_to_optimize='mean_deeplift_0')
# fimo_df.T
bedtools intersect -a /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/gold.bed -b /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/Dl_k50.0.bed -wb > /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/Dl_k50.0.tp.r.bed
bedtools intersect -a /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/nongold.bed -b /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/Dl_k50.0.bed -wb > /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/Dl_k50.0.fp.r.bed
bedtools intersect -a /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/gold.bed -b /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/Dl_k50.0.bed -v > /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/Dl_k50.0.fn.bed
bedtools intersect -a /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/nongold.bed -b /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/Dl_k50.0.bed -v > /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/Dl_k50.0.tn.bed
possible bug set()
bedtools intersect -a /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/Dl_k50.0.bed -b /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_specific_hits/task_224/peaks.bed -wb > /mnt/lab_data2/msharmin/oc-atlas/mtf/atac_various_hits/task_224/Gata4/Dl_k50.0.tp.atac.bed
sanity checks for atac overlap 8430 8430
sanity checks for area 0.1400144203157756 0.11710181851089989 0.1400144203157756
saniti checks for f1 0.08964103388672268 0.08964103388672268
saniti checks for recall 0.06303352365877099 [5.65323082e-05]
            true peaks  false peaks   total
pred_true         1115         6073    7188
pred_false       16574       142907  159481
total            17689       148980  166669
In [19]:
dlk = fimo_df[fimo_df['deeplift_cdf']>0.9]
nondlk = fimo_df[fimo_df['deeplift_cdf']<=0.9]

from matplotlib import pyplot as plt
fig, axes = plt.subplots(1, 2, figsize=(16,6))
ax_pdf = axes[0]
ax_cdf = axes[1]

key_to_show = 'sum_deeplift_0'
ax_pdf.hist(dlk[key_to_show].values, density=True, histtype='stepfilled',
        alpha=0.6, bins=60, label='high')
# plot the scores for an example sequence of a as well
ax_pdf.hist(nondlk[key_to_show].values, density=True, histtype='stepfilled',
        alpha=0.6, bins=60, label='low')
ax_pdf.legend(loc='best', frameon=False)
ax_pdf.legend(loc='best', frameon=False)

ax_cdf.hist(dlk[key_to_show].values,  cumulative=True, density=True, histtype='bar',
        alpha=0.6, bins=60, label='high')
# plot the scores for an example sequence of a as well
ax_cdf.hist(nondlk[key_to_show].values,  cumulative=True, density=True, histtype='bar',
        alpha=0.6, bins=60, label='low')
ax_cdf.legend(loc='best', frameon=False)
plt.show()
In [ ]:
 
In [ ]:
 
In [ ]:
# revise performance measurements with changing the probability metric

# revise fimo50
# revise positional distribution and cdfs for a bed


# zcat chippeaks.bed.gz | sort -k1,1 -k2,2n | bedtools intersect -a ../../../atac_specific_hits/task_140/peaks.bed -b stdin -wb -wa -v > nongold3.bed



# zcat chippeaks.bed.gz | sort -k1,1 -k2,2n | bedtools intersect -a stdin -b ../../../atac_specific_hits/task_140/peaks.bed -wb -wa > gold.bed
# zcat /mnt/lab_data2/msharmin/tf-mouse-atlas/chip_idrs/ENCFF806PDR.bed.gz | sort -k1,1 -k2,2n | bedtools intersect -a stdin -b atac_specific_hits/task_140/peaks.bed -wb > atac_various_hits/task_140/Ctcf/gold.bed
In [117]:
b = np.sum(null_scores, axis=2)
a = np.sum(deeplift_scores, axis=2)
a.shape, b.shape
Out[117]:
((174993, 1000), (174993, 200))
In [118]:
np.argmin(cdf_scores[:,5]), np.min(cdf_scores[:,5])
Out[118]:
(171195, 5.979713769975963e-05)
In [150]:
i = [0, 1]
c = b[0].flatten()
print(c.shape)
shape, mean, stdev = t.fit(c)
kstat, kval = stats.kstest(c, 't', args=[shape, mean, stdev])
# mean, stdev = norm.fit(c)
# kstat, kval = stats.kstest(c, 'norm', args=[ mean, stdev])
# shape, mean, stdev = gamma.fit(c)
# kstat, kval = stats.kstest(c, 'gamma', args=[shape,  mean, stdev])

print(kstat, kval)
(200,)
0.045556525408073756 0.8008351657723536
In [191]:
from matlas.fimo_hits import plot_fitted_dist_for_importance
plot_fitted_dist_for_importance(c, a[0], shape, mean, stdev)
In [11]:
# scores_ = [np.sum(j) for j in scores[0][300:700]]
# shape, mean, stdev = t.fit(scores_)
# kstat, kval = stats.kstest(scores_, 't', args=[shape, mean, stdev])
# print('kstat:', kstat, ' kval:', kval)

from scipy import stats

from scipy.stats import *
shape, mean, stdev = t.fit(b)
print(shape, mean, stdev)
kstat, kval = stats.kstest(b, 't', args=[shape, mean, stdev])
print('t sitribution', kstat, kval)
kstat, kval = stats.kstest(b, 'norm')
print('normal sitribution', kstat, kval)
1.5123294107168623 0.0008743328517088086 0.005880160282513114
t sitribution 0.06499847605991883 0.0
normal sitribution 0.48375382933815286 0.0
In [ ]:
 
In [28]:
#get the scores for all the windows, take per_base_imp distribution
# nonagnostic_out = "/mnt/lab_data/kundaje/msharmin/mouse_hem/mtf/specific_hits/task_224/Ctcf.bed.gz"
# df = pd.read_csv(nonagnostic_out, sep="\t")
# selected_peaks = np.sort(np.array(list(set(df['seqno'].values))))
# selected_null_scores = hyp_scores[selected_peaks,:,:]
# selected_null_scores.shape
# atacdf = pd.read_csv("/mnt/lab_data/kundaje/msharmin/mouse_hem/mtf/specific_hits/task_224/peaks.bed", header=None, sep="\t")
# #selected_atacs = atacdf.loc[selected_peaks,:]
# #selected_atacs.to_csv("/mnt/lab_data/kundaje/msharmin/mouse_hem/mtf/specific_hits/task_224/peaks_Ctcf.bed", 
#                       #header=None, index=None, sep="\t")
In [ ]:
 
In [42]:
# from matlas.render_report import render_cell_tf_reports_in_parallel

# render_cell_tf_reports_in_parallel()
In [2]:
# call dichotomize_chipseq_for_gold_standard for each tf under MEL
# call get_deeplift_passed_fimo_hits for each tf under MEL
# call get_peaks_within_nb for each tf under MEL
# for a tf: collect_distance_info, plot_distances_from_peaks
# for a tf: collect_performance_info, plot_performance_info
# for a tf: compute_joint_chip_matrix, plot_joint_chip_heatmap
# for a tf: load the png file
In [2]:
from matlas.fimo_hits import combine_motif_dfs

logdir = "/mnt/lab_data/kundaje/msharmin/mouse_hem/mtf"

outdir = "/mnt/lab_data/kundaje/msharmin/mouse_hem/mtf/specific_hits/task_{}".format(273)
nonagnostic_out = "{0}/{1}.bed.gz".format(outdir, "Adnp2")
df_dict = combine_motif_dfs(logdir, outdir, 
                      combine_func="collect_motif_df",
                      )
df = pd.concat([df_dict[key] for key in df_dict.keys()])

#nonz_dfs = combine_motif_dfs(logdir, outdir, zscored=False)
In [93]:
from matlas.fimo_hits import plot_motif_scores

motifs = ['Spi1', 'Ctcf', 'Gata1']
turn = 0
fig, axes = None, None
for key in motifs:
    fig, axes = plot_motif_scores(df_dict[key], title=key, turn=turn, axes=axes, fig=fig, kind='scatter')
    turn = (turn+1)%4
In [87]:
import seaborn as sns
combined_df = pd.concat([df_dict[key] for key in df_dict.keys()])
sns.jointplot(x="avg_deeplift", y="fimo", data=combined_df, s=1, marginal_kws=dict(bins=100));
In [19]:
df_dict['Spi1'][:5]
Out[19]:
motif fimo deeplift avg_deeplift
0 Spi1 13.9878 0.587939 0.053449
1 Spi1 15.0000 1.235800 0.065042
2 Spi1 14.7753 0.065585 0.003858
3 Spi1 14.2121 0.042971 0.002686
4 Spi1 15.8902 0.103061 0.009369
In [3]:
from matlas.render_report import render_test_plots
render_test_plots(nbname="FimoVsDeepliftReport")
In [71]:
gencode_file = '/mnt/data/annotations/by_release/mm10/GENCODE_ann/gencode.vM6.annotation.gtf'
gencode = pd.read_table(gencode_file, sep='\t', header=None, comment='#')
genes = gencode[(gencode[0]!='chrM') & (gencode[2]=='gene')&(np.array(['protein_coding' in i for i in gencode[8].values]))]
gene_df = genes.loc[:, [0,3,4,8,5,6]]
gene_df = gene_df.sort_values([0,3])
gene_df.to_csv("{0}/genecode.bed.gz".format(modisco_dir), header=False, index=False, compression='gzip', sep="\t")
genes[:5]
Out[71]:
0 1 2 3 4 5 6 7 8
6 chr1 HAVANA gene 3205901 3671498 . - . gene_id "ENSMUSG00000051951.5"; gene_type "pro...
74 chr1 HAVANA gene 4290846 4409241 . - . gene_id "ENSMUSG00000025900.8"; gene_type "pro...
104 chr1 HAVANA gene 4490931 4497354 . - . gene_id "ENSMUSG00000025902.11"; gene_type "pr...
227 chr1 HAVANA gene 4773206 4785739 . - . gene_id "ENSMUSG00000033845.11"; gene_type "pr...
298 chr1 HAVANA gene 4807788 4848410 . + . gene_id "ENSMUSG00000025903.12"; gene_type "pr...
In [ ]: