Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import shutil
|
|
8 |
import os
|
9 |
import re
|
10 |
from SigProfilerExtractor import sigpro as sig
|
|
|
11 |
import sys
|
12 |
import numpy as np
|
13 |
import pandas as pd
|
@@ -34,6 +35,16 @@ def show_pdf(file_path):
|
|
34 |
pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="1500" height="1000" type="application/pdf"></iframe>'
|
35 |
st.markdown(pdf_display, unsafe_allow_html=True)
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
#@st.cache_data(experimental_allow_widgets=True)
|
38 |
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):
|
39 |
for j in np.arange(0,len(to_dl_sbs)):
|
@@ -98,7 +109,16 @@ def showdl(file_to_lookat,to_dl_sbs,to_dl_indel,to_dl_dbs,to_dl_sbs_text,to_dl_i
|
|
98 |
# mime='application/octet-stream')
|
99 |
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
|
|
102 |
def dl(valforkey):
|
103 |
#breakpoint()
|
104 |
seev=glob.glob('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/*pdf')
|
@@ -223,6 +243,8 @@ if file_to_lookat !=[] and sub:
|
|
223 |
to_dl_sbs_summary_text=[]
|
224 |
to_dl_id_summary_text=[]
|
225 |
to_dl_dbs_summary_text=[]
|
|
|
|
|
226 |
|
227 |
for j in np.arange(0,len(file_to_lookat)):
|
228 |
if not os.path.exists('input'):
|
@@ -267,31 +289,48 @@ if file_to_lookat !=[] and sub:
|
|
267 |
#vcfuse=glob.glob('file_to_lookat[0].name')[0]
|
268 |
#shutil.copy2(vcfuse,'input/'+vcfuse)
|
269 |
#pdb.set_trace()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
|
271 |
with st.spinner('computing signatures'):
|
272 |
sig.sigProfilerExtractor("vcf", "output", "input", minimum_signatures=1, maximum_signatures=3,nmf_test_conv= 1000,nmf_tolerance= 1e-10,max_nmf_iterations=100000,min_nmf_iterations= 1000)
|
273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
to_dl_sbs.append(sbs_result)
|
279 |
-
to_dl_sbs_text.append(sbs_text)
|
280 |
-
to_dl_indel.append(indel_result)
|
281 |
-
to_dl_indel_text.append(indel_text)
|
282 |
-
to_dl_dbs.append(dbs_result)
|
283 |
-
to_dl_dbs_text.append(dbs_text)
|
284 |
-
to_dl_sbs_summary_text.append(summary_sbs)
|
285 |
-
to_dl_id_summary_text.append(summary_id)
|
286 |
-
to_dl_dbs_summary_text.append(summary_dbs)
|
287 |
-
|
288 |
-
#show_pdf('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/SBS96_Decomposition_Plots.pdf')
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
remove_old_vcf()
|
293 |
|
294 |
-
|
|
|
|
|
|
|
295 |
components.iframe("https://cancer.sanger.ac.uk/signatures/sbs/", height=3000,width=800)
|
296 |
#show_pdf('output/ID83/Suggested_Solution/COSMIC_ID83_Decomposed_Solution/ID83_Decomposition_Plots.pdf')
|
297 |
#components.iframe("https://cancer.sanger.ac.uk/signatures/id/",height=1000,width=800)
|
|
|
8 |
import os
|
9 |
import re
|
10 |
from SigProfilerExtractor import sigpro as sig
|
11 |
+
from SigProfilerMatrixGenerator.scripts import SigProfilerMatrixGeneratorFunc as datadump
|
12 |
import sys
|
13 |
import numpy as np
|
14 |
import pandas as pd
|
|
|
35 |
pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="1500" height="1000" type="application/pdf"></iframe>'
|
36 |
st.markdown(pdf_display, unsafe_allow_html=True)
|
37 |
|
38 |
+
def showdl_counts(file_to_lookat,to_dl_sbs96,to_dl_sbs1536):
|
39 |
+
download_link1 = f'<a href="data:application/octet-stream;base64, \
|
40 |
+
{base64.b64encode(to_dl_sbs96[j]).decode()}" download=" \
|
41 |
+
{file_to_lookat[j].name}96SBS.txt">Download {file_to_lookat[j].name} Single Base Substition (96) table</a>'
|
42 |
+
|
43 |
+
download_link2 = f'<a href="data:application/octet-stream;base64, \
|
44 |
+
{base64.b64encode(to_dl_sbs1536[j]).decode()}" download=" \
|
45 |
+
{file_to_lookat[j].name}1536SBS.txt">Download {file_to_lookat[j].name} Single Base Substition (1536) table</a>'
|
46 |
+
st.markdown(download_link1, unsafe_allow_html=True)
|
47 |
+
st.markdown(download_link2, unsafe_allow_html=True)
|
48 |
#@st.cache_data(experimental_allow_widgets=True)
|
49 |
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):
|
50 |
for j in np.arange(0,len(to_dl_sbs)):
|
|
|
109 |
# mime='application/octet-stream')
|
110 |
|
111 |
|
112 |
+
def dl_counts(valforkey):
|
113 |
+
with open("SBS96.txt","rb") as txt_file:
|
114 |
+
sbs96_all_bytes = txt_file.read()
|
115 |
+
txt_file.close()
|
116 |
+
with open("SBS1536","rb") as txt_file:
|
117 |
+
sbs96_all_bytes = txt_file.read()
|
118 |
+
txt_file.close()
|
119 |
+
return sbs96_all_bytes, sbs1536_all_bytes
|
120 |
|
121 |
+
|
122 |
def dl(valforkey):
|
123 |
#breakpoint()
|
124 |
seev=glob.glob('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/*pdf')
|
|
|
243 |
to_dl_sbs_summary_text=[]
|
244 |
to_dl_id_summary_text=[]
|
245 |
to_dl_dbs_summary_text=[]
|
246 |
+
to_dl_sbs96=[]
|
247 |
+
to_dl_sbs1536=[]
|
248 |
|
249 |
for j in np.arange(0,len(file_to_lookat)):
|
250 |
if not os.path.exists('input'):
|
|
|
289 |
#vcfuse=glob.glob('file_to_lookat[0].name')[0]
|
290 |
#shutil.copy2(vcfuse,'input/'+vcfuse)
|
291 |
#pdb.set_trace()
|
292 |
+
if no_profiles_only_counts == True:
|
293 |
+
refgen="GRCh37"
|
294 |
+
project = "input"
|
295 |
+
project_name = project.split("/")[-1]
|
296 |
+
with st.spinner('computing counts only'):
|
297 |
+
data = datadump.SigProfilerMatrixGeneratorFunc(project_name, refgen, project, exome=False, bed_file=None, chrom_based=False, plot=False, gs=False)
|
298 |
+
data['96'].to_csv('sbs96.txt',sep='\t',header=False,index=True)
|
299 |
+
data['1536'].to_csv('sbs1536.txt',sep='\t',header=False,index=True)
|
300 |
+
sbs96_result,sbs1536_result=dl_counts(j)
|
301 |
+
to_dl_sbs96.append(sbs96_result)
|
302 |
+
to_dl_sbs1536.append(sbs1536_result)
|
303 |
+
remove_old_vcf()
|
304 |
+
|
305 |
+
else:
|
306 |
|
307 |
with st.spinner('computing signatures'):
|
308 |
sig.sigProfilerExtractor("vcf", "output", "input", minimum_signatures=1, maximum_signatures=3,nmf_test_conv= 1000,nmf_tolerance= 1e-10,max_nmf_iterations=100000,min_nmf_iterations= 1000)
|
309 |
+
|
310 |
+
|
311 |
+
if file_to_lookat !=[] and glob.glob('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/*pdf'):
|
312 |
+
sbs_result,indel_result,dbs_result,sbs_text,indel_text,dbs_text,summary_sbs,summary_id,summary_dbs=dl(j)
|
313 |
+
|
314 |
+
to_dl_sbs.append(sbs_result)
|
315 |
+
to_dl_sbs_text.append(sbs_text)
|
316 |
+
to_dl_indel.append(indel_result)
|
317 |
+
to_dl_indel_text.append(indel_text)
|
318 |
+
to_dl_dbs.append(dbs_result)
|
319 |
+
to_dl_dbs_text.append(dbs_text)
|
320 |
+
to_dl_sbs_summary_text.append(summary_sbs)
|
321 |
+
to_dl_id_summary_text.append(summary_id)
|
322 |
+
to_dl_dbs_summary_text.append(summary_dbs)
|
323 |
+
|
324 |
+
#show_pdf('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/SBS96_Decomposition_Plots.pdf')
|
325 |
|
326 |
+
|
327 |
+
|
328 |
+
remove_old_vcf()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
329 |
|
330 |
+
if no_profiles_only_counts == True:
|
331 |
+
showdl_counts(file_to_lookat,to_dl_sbs96,to_dl_sbs1536)
|
332 |
+
else:
|
333 |
+
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)
|
334 |
components.iframe("https://cancer.sanger.ac.uk/signatures/sbs/", height=3000,width=800)
|
335 |
#show_pdf('output/ID83/Suggested_Solution/COSMIC_ID83_Decomposed_Solution/ID83_Decomposition_Plots.pdf')
|
336 |
#components.iframe("https://cancer.sanger.ac.uk/signatures/id/",height=1000,width=800)
|