Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Improve data information display
Browse files Browse the repository at this point in the history
  • Loading branch information
t03i committed Jan 3, 2024
1 parent 03e5de0 commit 008a710
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
8 changes: 2 additions & 6 deletions app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion streamlitapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("---")

Expand Down
32 changes: 32 additions & 0 deletions utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 008a710

Please sign in to comment.