diff --git a/Data/cached/example_1/visualizations/.gitkeep b/Data/cached/example_1/visualizations/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Data/cached/example_2/visualizations/.gitkeep b/Data/cached/example_2/visualizations/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Data/uploaded/visualizations/.gitkeep b/Data/uploaded/visualizations/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile index e474da0..bb6df21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,7 @@ RUN /opt/conda/bin/conda install --yes \ scipy==1.6.2 \ protobuf==3.14.0 \ python-Levenshtein==0.12.2 \ + reportlab==3.5.67 \ nomkl RUN /opt/conda/bin/conda config --add channels conda-forge @@ -18,7 +19,8 @@ RUN /opt/conda/bin/conda config --add channels conda-forge RUN /opt/conda/bin/conda install --yes \ altair==4.1.0 \ biopython==1.78 \ - gensim==4.0.1 + gensim==4.0.1 \ + svglib==1.1.0 RUN /opt/conda/bin/conda clean --all --yes diff --git a/Source/common.py b/Source/common.py index 5ac9767..d2b5937 100644 --- a/Source/common.py +++ b/Source/common.py @@ -16,6 +16,8 @@ from Bio import SeqIO from Bio.SeqUtils.ProtParam import ProteinAnalysis from scipy.spatial.distance import jaccard, pdist, squareform +from svglib.svglib import svg2rlg +from reportlab.graphics import renderPDF __author__ = 'Aleksandar Anžel' @@ -42,13 +44,24 @@ alt.data_transformers.enable("default", max_rows=MAX_ROWS) -# Functions below are shared among different omics Function that saves charts -# from list_of_charts with names from list_of_names -def save_charts(list_of_chart, list_of_names, folder_path): - for chart, name in zip(list_of_chart, list_of_names): - # altair_saver.save(chart, os.path.join (folder_path, name)) - chart.save(os.path.join(folder_path, name)) +# Functions below are shared among different omics. +def save_chart(chart, folder_path): + + file_path = os.path.join(folder_path, 'result') + chart.save(file_path + '.png') + chart.save(file_path + '.svg') + drawing = svg2rlg(file_path + '.svg') + renderPDF.drawToFile(drawing, file_path + '.pdf') + + # TODO: Create an archive, get the archive path and use it below + + with open(zipped_file_path, 'rb') as zipped_file: + st.download_button(label='Download visualization', data=zipped_file, + file_name='movis_visualization.zip', + mime='application/zip') + + return None # This function creates new dataframe with column that represent season diff --git a/Source/example_1.py b/Source/example_1.py index d327307..43cc315 100644 --- a/Source/example_1.py +++ b/Source/example_1.py @@ -24,6 +24,8 @@ path_example_1_root_data, 'metabolomics') path_example_1_phy_che = os.path.join( path_example_1_root_data, 'phy_che') +path_example_1_viz = os.path.join( + path_example_1_root_data, 'visualizations') path_example_1_genomics_fasta = os.path.join( path_example_1_genomics, 'rmags_filtered') @@ -214,6 +216,7 @@ def create_main_example_1(): with st.spinner('Visualizing...'): if 'altair' in str(type_of_chart): st.altair_chart(i[0], use_container_width=True) + common.save_chart(i[0], path_example_1_viz) else: pass diff --git a/Source/example_2.py b/Source/example_2.py index dfd07e1..486047b 100644 --- a/Source/example_2.py +++ b/Source/example_2.py @@ -48,6 +48,8 @@ path_example_2_transcriptomics_final = os.path.join( path_example_2_transcriptomics, 'Final.csv') +path_example_2_viz = os.path.join( + path_example_2_root_data, 'visualizations') def upload_intro(folder_path, key_suffix): df = None @@ -114,6 +116,7 @@ def create_main_example_2(): with st.spinner('Visualizing...'): if 'altair' in str(type_of_chart): st.altair_chart(i[0], use_container_width=True) + common.save_chart(i[0], path_example_2_viz) else: pass diff --git a/Source/upload.py b/Source/upload.py index d853bb3..75e9994 100644 --- a/Source/upload.py +++ b/Source/upload.py @@ -27,6 +27,7 @@ path_uploaded_transcriptomics = os.path.join(path_uploaded, 'transcriptomics') path_uploaded_metabolomics = os.path.join(path_uploaded, 'metabolomics') path_uploaded_phy_che = os.path.join(path_uploaded, 'phy_che') +path_uploaded_viz = os.path.join(path_uploaded, 'visualizations') path_uploaded_dict = { 'Genomics': path_uploaded_genomics, @@ -464,6 +465,7 @@ def create_main_upload(): with st.spinner('Visualizing...'): if 'altair' in str(type_of_chart): st.altair_chart(i[0], use_container_width=True) + common.save_chart(i[0], path_uploaded_viz) else: pass