From 008a710078672a7abf9dc507aa793fb80b5a68b5 Mon Sep 17 00:00:00 2001 From: Tobias O Date: Wed, 3 Jan 2024 21:15:36 +0100 Subject: [PATCH] Improve data information display --- app/database.py | 8 ++------ streamlitapp.py | 2 +- utils/db.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/database.py b/app/database.py index fa1415d..a454cb7 100644 --- a/app/database.py +++ b/app/database.py @@ -34,7 +34,7 @@ def show_table(df: pd.DataFrame): def display_random_data(_db_conn, db_filter: DBFilter): with st.spinner("Loading random data..."): st.session_state.data = db.get_random_data(_db_conn, db_filter.num_sequences) - st.session_state.user_display = "The table below shows a random selection. You can generate a new selection every 20 min. Use the sidebar filters for a personalized selection." # noqa: E501 + st.session_state.user_display = "The table below shows a random selection. You can retrieve new random data every minute. Use the sidebar filters for a personalized selection." # noqa: E501 @st.cache_data(ttl=600, show_spinner=False) @@ -44,8 +44,4 @@ def display_filtered_data(_db_conn, db_filter: DBFilter): st.session_state.data = db.get_filtered_data( _db_conn, query_form, db_filter.num_sequences ) - st.session_state.user_display = ( - f"The table below shows your personalized selection: topology ({db_filter.topology})," # noqa: E501 - f"taxonomy (Organism ID: {db_filter.organism_id}, Domain: {db_filter.domain}, Kingdom: {db_filter.kingdom}), " # noqa: E501 - f"length {str(db_filter.sequence_lengths)}. For a random selection use the sidebar button." # noqa: E501 - ) + st.session_state.user_display = f"The table below shows your personalized selection: {str(db_filter)}. For a random selection use the sidebar button." # noqa: E501 diff --git a/streamlitapp.py b/streamlitapp.py index 060235f..544dc8f 100644 --- a/streamlitapp.py +++ b/streamlitapp.py @@ -151,7 +151,7 @@ def handle_database_tab(db_conn): else: database.display_filtered_data(db_conn, database_filter) - if not st.st.session_state.user_display.empty: + if not st.session_state.user_display == "": st.write(st.session_state.user_display) st.markdown("---") diff --git a/utils/db.py b/utils/db.py index 89e1c43..7784921 100644 --- a/utils/db.py +++ b/utils/db.py @@ -197,6 +197,38 @@ def construct_query(self): logging.debug(query_form) return query_form + def __str__(self): + parts = [] + + # Topology + if self.topology is not None: + parts.append( + f"topology: {self.topology.value} ({' not' if (not self.signal_peptide and self.topology is not Topology.ALL) else ''} including signal peptides )" # noqa: E501 + ) + + # Taxonomy + taxonomy_parts = [] + if self.organism_id is not None: + taxonomy_parts.append(f"Organism ID: {self.organism_id}") + if self.domain is not None: + taxonomy_parts.append(f"Domain: {self.domain.value}") + if self.kingdom is not None: + taxonomy_parts.append(f"Kingdom: {self.kingdom.value}") + + if taxonomy_parts: + parts.append(f"taxonomy ({', '.join(taxonomy_parts)})") + + # Sequence Lengths + if self.sequence_lengths != (16, 5500): + parts.append( + f"length range: {self.sequence_lengths[0]}-{self.sequence_lengths[1]}" + ) + else: + parts.append("all lengths") + + # Final String + return ", ".join(parts) + def init_connection(): host = os.environ.get("TMVIS_MONGO_HOST", "localhost")