Skip to content

Commit

Permalink
Improved: Changed visualization download functionality from built-in …
Browse files Browse the repository at this point in the history
…to in-house method. Visualizations will now be downloaded using a button.
  • Loading branch information
AAnzel committed Dec 9, 2021
1 parent 3419c61 commit 96314ad
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 7 deletions.
Empty file.
Empty file.
Empty file.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ 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

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

Expand Down
25 changes: 19 additions & 6 deletions Source/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Source/example_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions Source/example_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions Source/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 96314ad

Please sign in to comment.