Eitan177 commited on
Commit
45ecc7a
·
1 Parent(s): 16548e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +133 -47
app.py CHANGED
@@ -8,6 +8,7 @@ import shutil
8
  import os
9
  from SigProfilerExtractor import sigpro as sig
10
  import sys
 
11
  import base64
12
  import streamlit.components.v1 as components
13
 
@@ -19,34 +20,101 @@ def remove_old_vcf():
19
  os.remove(filepath)
20
  vcfrem=glob.glob('input/input/*.vcf')
21
  for filepath in vcfrem:
22
- os.remove(filepath)
23
-
24
  def show_pdf(file_path):
25
  with open(file_path,"rb") as f:
26
  base64_pdf = base64.b64encode(f.read()).decode('utf-8')
27
  pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="1500" height="1000" type="application/pdf"></iframe>'
28
  st.markdown(pdf_display, unsafe_allow_html=True)
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- def dl(file_vcf):
 
 
 
32
  seev=glob.glob('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/*pdf')
33
  for i in seev:
34
  st.write('pdf file with sbs96 output is here: '+i)
35
  with open("output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/SBS96_Decomposition_Plots.pdf", "rb") as pdf_file:
36
- PDFbyte1 = pdf_file.read()
37
- st.download_button(label="Download image with single base substitution profiles", key='1',
38
- data=PDFbyte1,
39
- file_name="SBS.pdf",
40
- mime='application/octet-stream')
 
 
41
 
42
-
43
- with open("output/ID83/Suggested_Solution/COSMIC_ID83_Decomposed_Solution/ID83_Decomposition_Plots.pdf", "rb") as pdf_file:
44
- PDFbyte2 = pdf_file.read()
45
- st.download_button(label="Download image with indel profiles", key='2',
46
- data=PDFbyte2,
47
- file_name="idel.pdf",
48
- mime='application/octet-stream')
49
- return file_vcf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
 
52
 
@@ -64,7 +132,7 @@ with st.form('get signature'):
64
 
65
  if file_to_lookat !=[] and sub:
66
  #if st.button('get reference genome'):
67
- st.write(os.path.dirname(SigProfilerMatrixGenerator.__file__))
68
  dirtest=os.path.dirname(SigProfilerMatrixGenerator.__file__)
69
 
70
  #st.write(sys.path)
@@ -78,36 +146,54 @@ if file_to_lookat !=[] and sub:
78
  # st.write(i)
79
  ##genInstall.install('GRCh37')
80
 
81
- if not os.path.exists('input'):
82
- os.mkdir('input')
83
-
84
- if not os.path.exists('input/input'):
85
- os.mkdir('input/input')
86
-
87
- remove_old_vcf()
88
-
89
-
90
- bytes_data=file_to_lookat[0].read()
91
- with open(os.path.join("input",file_to_lookat[0].name),"wb") as f:
92
- f.write(bytes_data)
93
- f.close()
94
- seev=glob.glob('input/*')
95
- for i in seev:
96
- st.write(i)
97
- #vcfuse=glob.glob('file_to_lookat[0].name')[0]
98
- #shutil.copy2(vcfuse,'input/'+vcfuse)
99
- #pdb.set_trace()
100
- with st.spinner('computing signatures'):
101
- 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)
102
-
103
-
104
- if file_to_lookat !=[] and glob.glob('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/*pdf'):
105
- dl(file_to_lookat)
106
-
107
- #show_pdf('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/SBS96_Decomposition_Plots.pdf')
108
 
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  components.iframe("https://cancer.sanger.ac.uk/signatures/sbs/", height=3000,width=800)
111
- #show_pdf('output/ID83/Suggested_Solution/COSMIC_ID83_Decomposed_Solution/ID83_Decomposition_Plots.pdf')
112
- components.iframe("https://cancer.sanger.ac.uk/signatures/id/",height=3000,width=800)
113
- remove_old_vcf()
 
8
  import os
9
  from SigProfilerExtractor import sigpro as sig
10
  import sys
11
+ import numpy as np
12
  import base64
13
  import streamlit.components.v1 as components
14
 
 
20
  os.remove(filepath)
21
  vcfrem=glob.glob('input/input/*.vcf')
22
  for filepath in vcfrem:
23
+ os.remove(filepath)
24
+
25
  def show_pdf(file_path):
26
  with open(file_path,"rb") as f:
27
  base64_pdf = base64.b64encode(f.read()).decode('utf-8')
28
  pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="1500" height="1000" type="application/pdf"></iframe>'
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
+ download_link1 = f'<a href="data:application/octet-stream;base64, \
35
+ {base64.b64encode(to_dl_sbs[j]).decode()}" download=" \
36
+ {file_to_lookat[j].name}SBS.pdf">Download {file_to_lookat[j].name} Single Base Substition pdf</a>'
37
+ download_link2 = f'<a href="data:application/octet-stream;base64, \
38
+ {base64.b64encode(to_dl_sbs_text[j]).decode()}" download=" \
39
+ {file_to_lookat[j].name}SBS.txt">Download {file_to_lookat[j].name} Single Base Substition table</a>'
40
+ #download_link3 = f'<a href="data:application/octet-stream;base64, \
41
+ # {base64.b64encode(to_dl_indel[j]).decode()}" download=" \
42
+ # {file_to_lookat[j].name}Indel.pdf">Download {file_to_lookat[j].name} indel pdf</a>'
43
+ #download_link4 = f'<a href="data:application/octet-stream;base64, \
44
+ # {base64.b64encode(to_dl_indel_text[j]).decode()}" download=" \
45
+ # {file_to_lookat[j].name}Indel.txt">Download {file_to_lookat[j].name} indel table</a>'
46
+ #download_link5 = f'<a href="data:application/octet-stream;base64, \
47
+ # {base64.b64encode(to_dl_dbs[j]).decode()}" download=" \
48
+ # {file_to_lookat[j].name}DBS.pdf">Download {file_to_lookat[j].name} Double Base Substitution pdf</a>'
49
+ #download_link6 = f'<a href="data:application/octet-stream;base64, \
50
+ # {base64.b64encode(to_dl_dbs_text[j]).decode()}" download=" \
51
+ # {file_to_lookat[j].name}DBS.txt">Download {file_to_lookat[j].name} Double Base Substitution table</a>'
52
+
53
+ st.markdown(download_link1, unsafe_allow_html=True)
54
+
55
+ st.markdown(download_link2, unsafe_allow_html=True)
56
+
57
+ #st.markdown(download_link3, unsafe_allow_html=True)
58
+
59
+ #st.markdown(download_link4, unsafe_allow_html=True)
60
+
61
+ #st.markdown(download_link5, unsafe_allow_html=True)
62
+
63
+ #st.markdown(download_link6, unsafe_allow_html=True)
64
+ #st.download_button(label="Download image with single base substitution profiles", key=j,
65
+ # data=to_dl_sbs[j],
66
+ # file_name="SBS.pdf",
67
+ # mime='application/octet-stream')
68
+ #st.download_button(label="Download image with indel profiles", key=0.5+j,
69
+ # data=to_dl_indel[j],
70
+ # file_name="idel.pdf",
71
+ # mime='application/octet-stream')
72
 
73
+
74
+
75
+ def dl(valforkey):
76
+ #breakpoint()
77
  seev=glob.glob('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/*pdf')
78
  for i in seev:
79
  st.write('pdf file with sbs96 output is here: '+i)
80
  with open("output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/SBS96_Decomposition_Plots.pdf", "rb") as pdf_file:
81
+ PDFbyte1 = pdf_file.read()
82
+ with open("output/SBS96/Samples.txt","rb") as txt_file:
83
+ Txtbyte1 = txt_file.read()
84
+ #st.download_button(label="Download image with single base substitution profiles", key=valforkey,
85
+ # data=PDFbyte1,
86
+ # file_name="SBS.pdf",
87
+ # mime='application/octet-stream')
88
 
89
+
90
+ #with open("output/ID83/Suggested_Solution/COSMIC_ID83_Decomposed_Solution/ID83_Decomposition_Plots.pdf", "rb") as pdf_file:
91
+ # PDFbyte2 = pdf_file.read()
92
+ PDFbyte2=[]
93
+ #with open("output/ID83/Samples.txt","rb") as txt_file:
94
+ # Txtbyte2 = txt_file.read()
95
+ Txtbyte2=[]
96
+ #with open("output/DBS78/Suggested_Solution/COSMIC_DBS78_Decomposed_Solution/DBS78_Decomposition_Plots.pdf", "rb") as pdf_file:
97
+ # PDFbyte3 = pdf_file.read()
98
+ PDFbyte3 =[]
99
+ #with open("output/DBS78/Samples.txt","rb") as txt_file:
100
+ # Txtbyte3 = txt_file.read()
101
+ Txtbyte3=[]
102
+ os.system('rm -r output')
103
+ os.system('rm -r input')
104
+ #os.remove("output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/SBS96_Decomposition_Plots.pdf")
105
+ #os.remove("output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/*")
106
+ #os.remove("output/SBS96/Samples.txt")
107
+ #os.remove("output/ID83/Suggested_Solution/COSMIC_ID83_Decomposed_Solution/ID83_Decomposition_Plots.pdf")
108
+ #os.remove("output/ID83/Samples.txt")
109
+ #os.remove("output/DBS78/Suggested_Solution/COSMIC_DBS78_Decomposed_Solution/DBS78_Decomposition_Plots.pdf")
110
+ #os.remove("output/DBS78/Samples.txt")
111
+
112
+
113
+ #st.download_button(label="Download image with indel profiles", key=0.5+valforkey,
114
+ # data=PDFbyte2,
115
+ # file_name="idel.pdf",
116
+ # mime='application/octet-stream')
117
+ return PDFbyte1,PDFbyte2,PDFbyte3,Txtbyte1,Txtbyte2,Txtbyte3
118
 
119
 
120
 
 
132
 
133
  if file_to_lookat !=[] and sub:
134
  #if st.button('get reference genome'):
135
+ #st.write(os.path.dirname(SigProfilerMatrixGenerator.__file__))
136
  dirtest=os.path.dirname(SigProfilerMatrixGenerator.__file__)
137
 
138
  #st.write(sys.path)
 
146
  # st.write(i)
147
  ##genInstall.install('GRCh37')
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
 
151
+
152
+ to_dl_sbs=[]
153
+ to_dl_indel=[]
154
+ to_dl_dbs=[]
155
+ to_dl_sbs_text=[]
156
+ to_dl_indel_text=[]
157
+ to_dl_dbs_text=[]
158
+ for j in np.arange(0,len(file_to_lookat)):
159
+ if not os.path.exists('input'):
160
+ os.mkdir('input')
161
+
162
+ if not os.path.exists('input/input'):
163
+ os.mkdir('input/input')
164
+ remove_old_vcf()
165
+ bytes_data=file_to_lookat[j].read()
166
+ with open(os.path.join("input",file_to_lookat[j].name),"wb") as f:
167
+ f.write(bytes_data)
168
+ f.close()
169
+ seev=glob.glob('input/*')
170
+ #for i in seev:
171
+ # st.write(i)
172
+ #vcfuse=glob.glob('file_to_lookat[0].name')[0]
173
+ #shutil.copy2(vcfuse,'input/'+vcfuse)
174
+ #pdb.set_trace()
175
+
176
+ with st.spinner('computing signatures'):
177
+ 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)
178
+
179
+
180
+ if file_to_lookat !=[] and glob.glob('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/*pdf'):
181
+ sbs_result,indel_result,dbs_result,sbs_text,indel_text,dbs_text=dl(j)
182
+
183
+ to_dl_sbs.append(sbs_result)
184
+ to_dl_sbs_text.append(sbs_text)
185
+ to_dl_indel.append(indel_result)
186
+ to_dl_indel_text.append(indel_text)
187
+ to_dl_dbs.append(dbs_result)
188
+ to_dl_dbs_text.append(dbs_text)
189
+
190
+ #show_pdf('output/SBS96/Suggested_Solution/COSMIC_SBS96_Decomposed_Solution/SBS96_Decomposition_Plots.pdf')
191
+
192
+
193
+
194
+ remove_old_vcf()
195
+
196
+ 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)
197
  components.iframe("https://cancer.sanger.ac.uk/signatures/sbs/", height=3000,width=800)
198
+ #show_pdf('output/ID83/Suggested_Solution/COSMIC_ID83_Decomposed_Solution/ID83_Decomposition_Plots.pdf')
199
+ #components.iframe("https://cancer.sanger.ac.uk/signatures/id/",height=1000,width=800)