Eitan177 commited on
Commit
96cf3a4
·
1 Parent(s): a115539

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -8
app.py CHANGED
@@ -6,6 +6,7 @@ import SigProfilerMatrixGenerator
6
  from SigProfilerMatrixGenerator import install as genInstall
7
  import shutil
8
  import os
 
9
  from SigProfilerExtractor import sigpro as sig
10
  import sys
11
  import numpy as np
@@ -29,7 +30,7 @@ def show_pdf(file_path):
29
  st.markdown(pdf_display, unsafe_allow_html=True)
30
 
31
  #@st.cache_data(experimental_allow_widgets=True)
32
- def showdl(file_to_lookat,to_dl_sbs,to_dl_indel,to_dl_dbs,to_dl_sbs_text,to_dl_indel_text,to_dl_dbs_text):
33
  for j in np.arange(0,len(to_dl_sbs)):
34
  if to_dl_sbs[j] != []:
35
  download_link1 = f'<a href="data:application/octet-stream;base64, \
@@ -38,10 +39,14 @@ def showdl(file_to_lookat,to_dl_sbs,to_dl_indel,to_dl_dbs,to_dl_sbs_text,to_dl_i
38
 
39
  download_link2 = f'<a href="data:application/octet-stream;base64, \
40
  {base64.b64encode(to_dl_sbs_text[j]).decode()}" download=" \
41
- {file_to_lookat[j].name}SBS.txt">Download {file_to_lookat[j].name} Single Base Substition table</a>'
 
 
 
42
  st.markdown(download_link1, unsafe_allow_html=True)
43
 
44
- st.markdown(download_link2, unsafe_allow_html=True)
 
45
 
46
  for j in np.arange(0,len(to_dl_indel)):
47
  if to_dl_indel[j] != []:
@@ -90,6 +95,11 @@ def dl(valforkey):
90
  PDFbyte1 = pdf_file.read()
91
  with open("output/SBS96/Samples.txt","rb") as txt_file:
92
  Txtbyte1 = txt_file.read()
 
 
 
 
 
93
  #st.download_button(label="Download image with single base substitution profiles", key=valforkey,
94
  # data=PDFbyte1,
95
  # file_name="SBS.pdf",
@@ -100,17 +110,27 @@ def dl(valforkey):
100
  PDFbyte2 = pdf_file.read()
101
  with open("output/ID83/Samples.txt","rb") as txt_file:
102
  Txtbyte2 = txt_file.read()
 
 
 
 
103
  else:
104
  PDFbyte2 = []
105
- Txtbyte2 = []
 
106
  if glob.glob("output/DBS78/Suggested_Solution/COSMIC_DBS78_Decomposed_Solution/DBS78_Decomposition_Plots.pdf") != []:
107
  with open("output/DBS78/Suggested_Solution/COSMIC_DBS78_Decomposed_Solution/DBS78_Decomposition_Plots.pdf", "rb") as pdf_file:
108
  PDFbyte3 = pdf_file.read()
109
  with open("output/DBS78/Samples.txt","rb") as txt_file:
110
  Txtbyte3 = txt_file.read()
 
 
 
 
111
  else:
112
  PDFbyte3 = []
113
  Txtbyte3=[]
 
114
  os.system('rm -r output')
115
  os.system('rm -r input')
116
  #os.remove("output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/SBS96_Decomposition_Plots.pdf")
@@ -126,7 +146,7 @@ def dl(valforkey):
126
  # data=PDFbyte2,
127
  # file_name="idel.pdf",
128
  # mime='application/octet-stream')
129
- return PDFbyte1,PDFbyte2,PDFbyte3,Txtbyte1,Txtbyte2,Txtbyte3
130
 
131
 
132
 
@@ -172,7 +192,11 @@ if file_to_lookat !=[] and sub:
172
  to_dl_dbs=[]
173
  to_dl_sbs_text=[]
174
  to_dl_indel_text=[]
175
- to_dl_dbs_text=[]
 
 
 
 
176
  for j in np.arange(0,len(file_to_lookat)):
177
  if not os.path.exists('input'):
178
  os.mkdir('input')
@@ -196,7 +220,7 @@ if file_to_lookat !=[] and sub:
196
 
197
 
198
  if file_to_lookat !=[] and glob.glob('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/*pdf'):
199
- sbs_result,indel_result,dbs_result,sbs_text,indel_text,dbs_text=dl(j)
200
 
201
  to_dl_sbs.append(sbs_result)
202
  to_dl_sbs_text.append(sbs_text)
@@ -204,6 +228,9 @@ if file_to_lookat !=[] and sub:
204
  to_dl_indel_text.append(indel_text)
205
  to_dl_dbs.append(dbs_result)
206
  to_dl_dbs_text.append(dbs_text)
 
 
 
207
 
208
  #show_pdf('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/SBS96_Decomposition_Plots.pdf')
209
 
@@ -211,7 +238,7 @@ if file_to_lookat !=[] and sub:
211
 
212
  remove_old_vcf()
213
 
214
- showdl(file_to_lookat,to_dl_sbs,to_dl_indel,to_dl_dbs,to_dl_sbs_text,to_dl_indel_text,to_dl_dbs_text)
215
  components.iframe("https://cancer.sanger.ac.uk/signatures/sbs/", height=3000,width=800)
216
  #show_pdf('output/ID83/Suggested_Solution/COSMIC_ID83_Decomposed_Solution/ID83_Decomposition_Plots.pdf')
217
  #components.iframe("https://cancer.sanger.ac.uk/signatures/id/",height=1000,width=800)
 
6
  from SigProfilerMatrixGenerator import install as genInstall
7
  import shutil
8
  import os
9
+ import re
10
  from SigProfilerExtractor import sigpro as sig
11
  import sys
12
  import numpy as np
 
30
  st.markdown(pdf_display, unsafe_allow_html=True)
31
 
32
  #@st.cache_data(experimental_allow_widgets=True)
33
+ def showdl(file_to_lookat,to_dl_sbs,to_dl_indel,to_dl_dbs,to_dl_sbs_text,to_dl_indel_text,to_dl_dbs_text,to_dl_sbs_summary_text,to_dl_id_summary_text,to_dl_dbs_summary_text):
34
  for j in np.arange(0,len(to_dl_sbs)):
35
  if to_dl_sbs[j] != []:
36
  download_link1 = f'<a href="data:application/octet-stream;base64, \
 
39
 
40
  download_link2 = f'<a href="data:application/octet-stream;base64, \
41
  {base64.b64encode(to_dl_sbs_text[j]).decode()}" download=" \
42
+ {file_to_lookat[j].name}SBS.txt">Download {file_to_lookat[j].name} Single Base Substition table</a>'
43
+ download_link3 = f'<a href="data:application/octet-stream;base64, \
44
+ {base64.b64encode(to_dl_sbs_summary_text[j]).decode()}" download=" \
45
+ {file_to_lookat[j].name}SBS_summary.txt">Download {file_to_lookat[j].name} Single Base Substition table</a>'
46
  st.markdown(download_link1, unsafe_allow_html=True)
47
 
48
+ st.markdown(download_link2, unsafe_allow_html=True)
49
+ st.markdown(download_link3, unsafe_allow_html=True)
50
 
51
  for j in np.arange(0,len(to_dl_indel)):
52
  if to_dl_indel[j] != []:
 
95
  PDFbyte1 = pdf_file.read()
96
  with open("output/SBS96/Samples.txt","rb") as txt_file:
97
  Txtbyte1 = txt_file.read()
98
+ txt_file.close()
99
+ hh=pd.read_table('output/SBS96/Samples.txt')
100
+ hh['nums']=hh.iloc[:,1]
101
+ hh['mutation_simple']=hh['MutationType'].apply(lambda x: re.sub('].$','',re.sub('^.\[','',x)))
102
+ summary_table_sbs_all=hh.groupby('mutation_simple').apply(lambda x: x.sum())[['mutation_simple','nums']]
103
  #st.download_button(label="Download image with single base substitution profiles", key=valforkey,
104
  # data=PDFbyte1,
105
  # file_name="SBS.pdf",
 
110
  PDFbyte2 = pdf_file.read()
111
  with open("output/ID83/Samples.txt","rb") as txt_file:
112
  Txtbyte2 = txt_file.read()
113
+ hh2=pd.read_table('output/ID83/Samples.txt')
114
+ hh2['nums']=hh2.iloc[:,1]
115
+ hh2['mutation_simple']=hh2['MutationType'].apply(lambda x: re.sub('].$','',re.sub('^.\[','',x)))
116
+ summary_table_id_all=hh2.groupby('mutation_simple').apply(lambda x: x.sum())[['mutation_simple','nums']]
117
  else:
118
  PDFbyte2 = []
119
+ Txtbyte2 = []
120
+ summary_table_id_all=[]
121
  if glob.glob("output/DBS78/Suggested_Solution/COSMIC_DBS78_Decomposed_Solution/DBS78_Decomposition_Plots.pdf") != []:
122
  with open("output/DBS78/Suggested_Solution/COSMIC_DBS78_Decomposed_Solution/DBS78_Decomposition_Plots.pdf", "rb") as pdf_file:
123
  PDFbyte3 = pdf_file.read()
124
  with open("output/DBS78/Samples.txt","rb") as txt_file:
125
  Txtbyte3 = txt_file.read()
126
+ hh3=pd.read_table('output/DBS78/Samples.txt')
127
+ hh3['nums']=hh3.iloc[:,1]
128
+ hh3['mutation_simple']=hh3['MutationType'].apply(lambda x: re.sub('].$','',re.sub('^.\[','',x)))
129
+ summary_table_dbs_all=hh3.groupby('mutation_simple').apply(lambda x: x.sum())[['mutation_simple','nums']]
130
  else:
131
  PDFbyte3 = []
132
  Txtbyte3=[]
133
+ summary_table_dbs_all=[]
134
  os.system('rm -r output')
135
  os.system('rm -r input')
136
  #os.remove("output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/SBS96_Decomposition_Plots.pdf")
 
146
  # data=PDFbyte2,
147
  # file_name="idel.pdf",
148
  # mime='application/octet-stream')
149
+ return PDFbyte1,PDFbyte2,PDFbyte3,Txtbyte1,Txtbyte2,Txtbyte3, summary_table_sbs_all, summary_table_id_all,summary_table_dbs_all
150
 
151
 
152
 
 
192
  to_dl_dbs=[]
193
  to_dl_sbs_text=[]
194
  to_dl_indel_text=[]
195
+ to_dl_dbs_text=[]
196
+ to_dl_sbs_summary_text=[]
197
+ to_dl_id_summary_text=[]
198
+ to_dl_dbs_summary_text=[]
199
+
200
  for j in np.arange(0,len(file_to_lookat)):
201
  if not os.path.exists('input'):
202
  os.mkdir('input')
 
220
 
221
 
222
  if file_to_lookat !=[] and glob.glob('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/*pdf'):
223
+ sbs_result,indel_result,dbs_result,sbs_text,indel_text,dbs_text,summary_sbs,dummary_id,summary_dbs=dl(j)
224
 
225
  to_dl_sbs.append(sbs_result)
226
  to_dl_sbs_text.append(sbs_text)
 
228
  to_dl_indel_text.append(indel_text)
229
  to_dl_dbs.append(dbs_result)
230
  to_dl_dbs_text.append(dbs_text)
231
+ to_dl_sbs_summary_text.append(summary_sbs)
232
+ to_dl_id_summary_text.append(summary_id)
233
+ to_dl_dbs_summary_text.append(summary_dbs)
234
 
235
  #show_pdf('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/SBS96_Decomposition_Plots.pdf')
236
 
 
238
 
239
  remove_old_vcf()
240
 
241
+ showdl(file_to_lookat,to_dl_sbs,to_dl_indel,to_dl_dbs,to_dl_sbs_text,to_dl_indel_text,to_dl_dbs_text,to_dl_sbs_summary_text,to_dl_id_summary_text,to_dl_dbs_summary_text)
242
  components.iframe("https://cancer.sanger.ac.uk/signatures/sbs/", height=3000,width=800)
243
  #show_pdf('output/ID83/Suggested_Solution/COSMIC_ID83_Decomposed_Solution/ID83_Decomposition_Plots.pdf')
244
  #components.iframe("https://cancer.sanger.ac.uk/signatures/id/",height=1000,width=800)