-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTLX3_peaks_annot.py
203 lines (135 loc) · 5.69 KB
/
TLX3_peaks_annot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env python3
#~ import os
import subprocess
import pybedtools as pb
import numpy as np
import yaml
from os.path import join
import pandas as pd
import gseapy as gp
import seaborn as sns
import matplotlib.pyplot as plt
from metaseq.results_table import ResultsTable, DESeq2Results
def log2p1(x):
return np.log2(x + 1)
# ===== Figures
# Tweak some font settings so the results look nicer
plt.rcParams['font.family'] = 'Arial'
plt.rcParams['font.size'] = 14
# Read annotated peaks
df = pd.read_csv('tracks/TLX3_TLX3_peaks_100_annot.csv',index_col=0)
intr = df[df['annotation'].str.contains("Intron")]
promot=df[df['annotation'].str.contains("Promoter")]
distal=df[df['annotation'].str.contains("Distal Intergenic")]
exon =df[df['annotation'].str.contains("Exon")]
rst = len(df) - len(intr) - len(promot) - len(distal) - len(exon)
print len(intr), len(promot), len(distal), len(exon), rst
# ===== Figures
# Tweak some font settings so the results look nicer
plt.rcParams['font.family'] = 'Arial'
plt.rcParams['font.size'] = 14
lab = ['Intron', 'Promoter', 'Distal Intergenic', 'Exons', 'Others']
colors = ['gold', 'lightcoral', 'yellowgreen', 'orange', 'lightskyblue']
explode = (0, 0.1, 0, 0, 0)
fig, ax = plt.subplots()
patches, texts, autotexts = ax.pie([len(intr), len(promot), len(distal), len(exon), rst],
labels=lab,
colors=colors,
explode=explode,
shadow=True,
autopct='%1.1f%%')
plt.axis('equal')
# Make the labels easier to read.
for t in texts:
t.set_size('large')
font = {'family': 'arial',
'color': 'darkblue',
'weight': 'normal',
'size': 16,
}
ax.set_title('Peaks statistics, Total =' +str(len(df)), fontdict=font)
# ==== Genes expression
# ==============================
gn_l = list(promot['SYMBOL'].str.upper().unique())
# === Load expression table
tbl = pd.read_table(join('tracks', 'TLX3vsRAG-results_genes.txt'), index_col=0)
# Filter genes (Note: this filter remove microRNA expression)
tbl = tbl[(tbl.padj < 0.05)].dropna()
# === Load gene names
names = pd.read_table("tracks/annot_tracks/references/mm9/mm9_EnsemblTransc_GeneNames.txt",
index_col=0,
header=0,
names=['GeneID', 'TransID', 'Gene_name'])
names = names.drop('TransID', axis=1).drop_duplicates()
names = names.loc[tbl.index]
assert names.shape[0] == tbl.shape[0]
tbl=names.join(tbl, how ='right')
## === Expresion analysis
import RNA_expression_processing as rn
tbn = tbl[['Gene_name', 'R2.RAG1W.RAG1','RAGS.RAGZ','RAGZ','TLX3.1_1','TLX3.1_5','TLX3.1_P', 'padj']]
classes = ['RAG','RAG','RAG','TLX3','TLX3','TLX3']
topN, up, dn, ttl =rn.express(tbn,'TLX3', 'RAG',
classes=classes,
n_top=100,
geneList=gn_l,
ttl='Genes of TLX3-tlx peaks in promoters')
# Figures
unch = ttl - up - dn
nexp = len(gn_l)-ttl
lab = ['Up-regulated', 'Down-regulated', 'Unchanged', 'Not-expressed']
colors = ['gold', 'lightcoral', 'lightskyblue','grey' ]
explode = (0.07, 0.04, 0, 0)
print 'Promoters = ', up, dn, unch, nexp
fig2, ax2 = plt.subplots()
patches, texts, autotexts = ax2.pie([up, dn, unch, nexp],
labels=lab,
colors=colors,
explode=explode,
shadow=True,
autopct='%1.1f%%')
plt.axis('equal')
# Make the labels easier to read.
for t in texts:
t.set_size('large')
ax2.set_title('Peaks in promoter, Total =' +str(len(gn_l)), fontdict=font)
plt.show()
## === Save to .bed file
#~ promot[['seqnames','start','end']].to_csv('tracks/Tlx3_peaks_100_promoter.bed',
#~ sep='\t',
#~ index=False,
#~ header=False)
#~ distal[['seqnames','start','end']].to_csv('tracks/Tlx3_peaks_100_distal.bed',
#~ sep='\t',
#~ index=False,
#~ header=False)
#~ intr[['seqnames','start','end']].to_csv('tracks/Tlx3_peaks_100_intron.bed',
#~ sep='\t',
#~ index=False,
#~ header=False)
#~ exon[['seqnames','start','end']].to_csv('tracks/Tlx3_peaks_100_exon.bed',
#~ sep='\t',
#~ index=False,
#~ header=False)
## === get DAN seqs from bed coordinates
#~ mm9 = "/home/sergio/media/NAS4/PFlab/TLX3_project/ChiP-Seq/references/mm9/chromFa/mm9.fa"
#~ # --- distal
#~ bd = "tracks/Tlx3_peaks_100_distal.bed"
#~ fa = "tracks/Tlx3_peaks_100_distal.fa"
#~ bd2fa = "bedtools getfasta -fi {} -bed {} -fo {}".format(mm9,bd,fa)
#~ print('Running process ........ \n')
#~ print(bd2fa)
#~ subprocess.call(['bash','-c', bd2fa])
#~ # ---- promoter
#~ bd = "tracks/Tlx3_peaks_100_promoter.bed"
#~ fa = "tracks/Tlx3_peaks_100_promoter.fa"
#~ bd2fa = "bedtools getfasta -fi {} -bed {} -fo {}".format(mm9,bd,fa)
#~ print('Running process ........ \n')
#~ print(bd2fa)
#~ subprocess.call(['bash','-c', bd2fa])
#~ # ---- intron
#~ bd = "tracks/Tlx3_peaks_100_intron.bed"
#~ fa = "tracks/Tlx3_peaks_100_intron.fa"
#~ bd2fa = "bedtools getfasta -fi {} -bed {} -fo {}".format(mm9,bd,fa)
#~ print('Running process ........ \n')
#~ print(bd2fa)
#~ subprocess.call(['bash','-c', bd2fa])