From afa1e0f18a6ff0f1e6a8bb5acdf0893eea0b261e Mon Sep 17 00:00:00 2001 From: ivanwilliammd Date: Wed, 10 Apr 2024 10:17:36 +0700 Subject: [PATCH] Bump version to v0.5.0 for release --- CHANGELOG.md | 3 +++ iderare_pheno/simrec.py | 1 + iderare_pheno/streamlit_utils.py | 29 ++++++++++++++++++++--------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78d7e78..50c4e03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## [v0.5.0](https://github.com/ivanwilliammd/iderare-pheno/releases/tag/v0.5.0) - 2024-04-10 +- Added ```omim2name``` function and ```streamlit_utils.py``` to accomodate Streamlit app + ## [v0.4.0](https://github.com/ivanwilliammd/iderare-pheno/releases/tag/v0.4.0) - 2024-04-07 - Added export iderare.yml function diff --git a/iderare_pheno/simrec.py b/iderare_pheno/simrec.py index 1d5be4b..fc9030d 100644 --- a/iderare_pheno/simrec.py +++ b/iderare_pheno/simrec.py @@ -30,6 +30,7 @@ def hpo2name(hpo_set): hpo_name = [Ontology.hpo(int(d.strip("HP:"))).name for d in hpo_set] return hpo_name + # Get OMIM Name from HPO Code def omim2name(diagnosis_sets): omim_name = [Omim.get(int(d.strip("OMIM:"))).name for d in diagnosis_sets] diff --git a/iderare_pheno/streamlit_utils.py b/iderare_pheno/streamlit_utils.py index ae324d5..7b02e15 100644 --- a/iderare_pheno/streamlit_utils.py +++ b/iderare_pheno/streamlit_utils.py @@ -1,8 +1,10 @@ +import io import os from datetime import datetime import pandas as pd import scipy.cluster +import streamlit as st import yaml from matplotlib import pyplot as plt @@ -37,11 +39,13 @@ def list2tsv( # Print the dendrogram tree def linkage_dendrogram(linkage, labels, title="Similarity", threshold=0.3, path_to_save=None): if len(linkage) == 0: - print("Linkage is empty. The data not possible due to blank linkage information.") + st.write("Linkage is empty. The data not possible due to blank linkage information.") return + plt.figure(figsize=(20, len(linkage))) scipy.cluster.hierarchy.dendrogram( linkage, + distance_sort="ascending", labels=labels, show_contracted=True, leaf_font_size=plt.rcParams["font.size"] * 1.5, @@ -65,14 +69,21 @@ def linkage_dendrogram(linkage, labels, title="Similarity", threshold=0.3, path_ plt.ylabel("Disease", fontsize=plt.rcParams["font.size"] * 2) plt.tight_layout() - if not os.path.exists("output"): - os.makedirs("output") - print("Folder output created.") - else: - print("Folder output already exists.") + col1, col2 = st.columns([3, 1]) + with col1: + st.success("Dendrogram tree plotted successfully") - if path_to_save is None: - path_to_save = "output/{date_time}_{title}.png".format( + path_to_save = os.path.join( + "{date_time}_{title}.png".format( date_time=datetime.now().strftime("%Y%m%d_%H%M%S"), title=title[0:30] ) - plt.savefig(path_to_save) + ) + img = io.BytesIO() + + plt.savefig(img, format="png") + with col2: + st.download_button( + label="📷 Download graph", data=img, file_name=path_to_save, mime="image/png" + ) + + st.pyplot(plt, use_container_width=True)