<jupyter_start><jupyter_text>DE genes<jupyter_code>cm = pd.read_csv('/Users/minjunpark/Documents/hali/syntax_analysis/DE_genes/DEG_whole_heart_P1_vs_P8_MI_RNA_Cardiomyocytes.csv', index_col=0)
fb = pd.read_csv('/Users/minjunpark/Documents/hali/syntax_analysis/DE_genes/DEG_whole_heart_P1_vs_P8_MI_RNA_Fibroblasts.csv', index_col=0)
endo = pd.read_csv('/Users/minjunpark/Documents/hali/syntax_analysis/DE_genes/DEG_whole_heart_P1_vs_P8_MI_RNA_Endothelial_1.csv', index_col=0)
cm
## Filter df (adj p-val < 0.01 & abs(log2FC) > 1.25)
p_val_thres = 0.01
log2FC_thres = 1.25

cm = cm[cm.p_val_adj < p_val_thres]
cm_up = cm[cm.avg_log2FC > log2FC_thres]
cm_down = cm[cm.avg_log2FC < -log2FC_thres]

fb = fb[fb.p_val_adj < p_val_thres]
fb_up = fb[fb.avg_log2FC > log2FC_thres]
fb_down = fb[fb.avg_log2FC < -log2FC_thres]

endo = endo[endo.p_val_adj < p_val_thres]
endo_up = endo[endo.avg_log2FC > log2FC_thres]
endo_down = endo[endo.avg_log2FC < -log2FC_thres]

cm_up
# Take an example TF bedfile (contains all the peaks --> now need to split into up & down regulated genes)
TF_bedfile = '/Users/minjunpark/Documents/hali/syntax_analysis/tiled_heatmap/ETS1_outs/A1JVI6.bed'
df = pd.read_csv(bedfile, header=None, sep='\t')
df
## What I need to do is find the interaction with the DE genes in CM, FB, or endotheliel...
## --> I don't really need to go over these steps?
genes_bed = '/Users/minjunpark/Documents/hali/syntax_analysis/influence_score/AllGenes_100kb_flanking_regions_dropped_duplicates.bed'
genes = pd.read_csv(genes_bed, sep='\t', header=None)
#subs = genes[genes.iloc[:,0].isin(cm_up.index.tolist())].iloc[:,0].reset_index(0, drop=True)
cm_up_bed = genes[genes.iloc[:,0].isin(cm_up.index.tolist())].reset_index(0, drop=True)
cm_up_bed = cm_up_bed.drop(columns=[0])
cm_up_bed.to_csv('cm_up.bed', sep='\t', index=False, header=None)

cm_down_bed = genes[genes.iloc[:,0].isin(cm_down.index.tolist())].reset_index(0, drop=True)
cm_down_bed = cm_down_bed.drop(columns=[0])
cm_down_bed.to_csv('cm_down.bed', sep='\t', index=False, header=None)
TF_bed = BedTool(TF_bedfile)
cm_up_bed = BedTool('cm_up.bed')
cm_down_bed = BedTool('cm_down.bed')
intersected_up = TF_bed.intersect(cm_up_bed)
df_cm_up = pd.read_table(intersected_up.fn, names=['chrom', 'start', 'stop', 'name', 'score', 'strand'])
df_cm_up = df_cm_up.drop(columns=['name', 'score', 'strand'])

intersected_down = TF_bed.intersect(cm_down_bed)
df_cm_down = pd.read_table(intersected_down.fn, names=['chrom', 'start', 'stop', 'name', 'score', 'strand'])
df_cm_down = df_cm_down.drop(columns=['name', 'score', 'strand'])

df_cm_up
df_cm_down<jupyter_output><empty_output><jupyter_text>Loop over DE genes<jupyter_code>cm_up_genes = genes[genes.iloc[:,0].isin(cm_up.index.tolist())].reset_index(0, drop=True)
cm_down_genes = genes[genes.iloc[:,0].isin(cm_down.index.tolist())].reset_index(0, drop=True)
cm_up_genes
# CM1 down-regulated in P1
! mkdir -p cm_down
for i in range(len(cm_up_genes)):
    num = 0
    gene = cm_up_genes.iloc[i,0]
    chromosome = cm_up_genes.iloc[i,1]
    start = cm_up_genes.iloc[i,2]
    end = cm_up_genes.iloc[i,3]
    r1 = set(range(start, end))
    with open('./cm_down/{}.bed'.format(gene), 'w') as f:
    
        for j in range(len(df_cm_down)):
            chromosome2 = df_cm_down.iloc[j,0]
            start2 = df_cm_down.iloc[j,1]
            end2 = df_cm_down.iloc[j,2] 
            r2 = set(range(start2, end2))

            if chromosome == chromosome2 and len(r1.intersection(r2)) > 0:
                f.write('{}\t{}\t{}\n'.format(chromosome2, start2, end2))
                num += 1
                
    if num > 0:
        df = pd.read_csv('./cm_down/{}.bed'.format(gene), sep='\t', header=None)
        df = df.drop_duplicates() # remove duplicate rows
        df.to_csv('./cm_down/{}.bed'.format(gene), sep='\t', header=None, index=None)<jupyter_output><empty_output><jupyter_text>LA down CM1<jupyter_code>#sns.set_theme(color_codes=True)
df_down = pd.read_csv('/Users/minjunpark/Documents/Pitx2/manuscript/fig3/data/LAdown_bicluster_outs/A1JVI6.bed', header=None, sep='\t')
df_down
#LAdown_gene_list = ['Myoz2', 'Jph2', 'Actn2', 'Stat3', 'Atp1a1', 'Pdlim5', 'Asb2']
LA_gene_list = list(LAcm.index)
LA_genes = pd.read_csv('/Users/minjunpark/Documents/Pitx2/manuscript/fig3/jeff/LA_genes_100Kb_expressed_adjp(0.01).bed', sep='\t', header=None)
#LAdown_genes = LAdown_genes[LAdown_genes[0].isin(LAdown_gene_list)]
LA_genes
! mkdir -p LA_all
for i in range(len(LA_genes)):
    num = 0
    gene = LA_genes.iloc[i,0]
    chromosome = LA_genes.iloc[i,1]
    start = LA_genes.iloc[i,2]
    end = LA_genes.iloc[i,3]
    r1 = set(range(start, end))
    with open('./LA_all/{}.bed'.format(gene), 'w') as f:
    
        for j in range(len(df_down)):
            chromosome2 = df_down.iloc[j,0]
            start2 = df_down.iloc[j,1]
            end2 = df_down.iloc[j,2] 
            r2 = set(range(start2, end2))

            if chromosome == chromosome2 and len(r1.intersection(r2)) > 0:
                f.write('{}\t{}\t{}\n'.format(chromosome2, start2, end2))
                num += 1
                
    if num > 0:
        df = pd.read_csv('./LA_all/{}.bed'.format(gene), sep='\t', header=None)
        df = df.drop_duplicates() # remove duplicate rows
        df.to_csv('./LA_all/{}.bed'.format(gene), sep='\t', header=None, index=None)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1618550940584839, 'fraction_numerical': 0.02365431178990501, 'mean_word_length': 4.337972166998012, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '392348', 'license': 'MIT', 'n_tokens_mistral': 2345, 'n_tokens_neox': 2202, 'n_words': 332, 'path': 'syntax_analysis/tiled_heatmap/step1(DE_0.01).ipynb', 'repo_name': 'minjunp/scATAC-seq', 'size': '5369'}