Skip to content

Commit

Permalink
Merge pull request #78 from singjc/plotting/pyopenms_viz
Browse files Browse the repository at this point in the history
Plotting/pyopenms viz
  • Loading branch information
axelwalter authored Oct 10, 2024
2 parents a540f6b + 81a8c74 commit 36d93ae
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 406 deletions.
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ dependencies:
# streamlit dependencies
- streamlit>=1.38.0
- captcha==0.5.0
- pyopenms_viz>=0.1.2
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# note that it is much more restricted in terms of installing third-parties / etc.
# preferably use the batteries included or simple docker file for local hosting
streamlit>=1.38.0
pyopenms==3.1.0
pyopenms==3.2.0
numpy==1.26.4 # pandas and numpy are dependencies of pyopenms, however, pyopenms needs numpy<=1.26.4
plotly==5.22.0
captcha==0.5.0
captcha==0.5.0
pyopenms_viz>=0.1.2
50 changes: 23 additions & 27 deletions src/common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ def change_workspace():
img_formats.index(params["image-format"]),
key="image-format",
)
st.markdown("## Spectrum Plotting")
st.selectbox("Bin Peaks", ["auto", True, False], key="spectrum_bin_peaks")
if st.session_state["spectrum_bin_peaks"] == True:
st.number_input(
"Number of Bins (m/z)", 1, 10000, 50, key="spectrum_num_bins"
)
else:
st.session_state["spectrum_num_bins"] = 50
return params


Expand All @@ -321,7 +329,7 @@ def v_space(n: int, col=None) -> None:


def display_large_dataframe(
df, chunk_sizes: list[int] = [100, 1_000, 10_000], **kwargs
df, chunk_sizes: list[int] = [10, 100, 1_000, 10_000], **kwargs
):
"""
Displays a large DataFrame in chunks with pagination controls and row selection.
Expand All @@ -332,23 +340,20 @@ def display_large_dataframe(
...: Additional keyword arguments to pass to the `st.dataframe` function. See: https://docs.streamlit.io/develop/api-reference/data/st.dataframe
Returns:
Selected rows from the current chunk.
Index of selected row.
"""

def update_on_change():
# Initialize session state for pagination
if "current_chunk" not in st.session_state:
st.session_state.current_chunk = 0
st.session_state.current_chunk = 0

# Dropdown for selecting chunk size
chunk_size = st.selectbox(
"Select Number of Rows to Display", chunk_sizes, on_change=update_on_change
)
chunk_size = st.selectbox("Select Number of Rows to Display", chunk_sizes)

# Calculate total number of chunks
total_chunks = (len(df) + chunk_size - 1) // chunk_size

if total_chunks > 1:
page = int(st.number_input("Select Page", 1, total_chunks, 1, step=1))
else:
page = 1

# Function to get the current chunk of the DataFrame
def get_current_chunk(df, chunk_size, chunk_index):
start = chunk_index * chunk_size
Expand All @@ -358,30 +363,21 @@ def get_current_chunk(df, chunk_size, chunk_index):
return df.iloc[start:end], start, end

# Display the current chunk
current_chunk_df, start_row, end_row = get_current_chunk(
df, chunk_size, st.session_state.current_chunk
)
current_chunk_df, start_row, end_row = get_current_chunk(df, chunk_size, page - 1)

event = st.dataframe(current_chunk_df, **kwargs)

st.write(
f"Showing rows {start_row + 1} to {end_row} of {len(df)} ({get_dataframe_mem_useage(current_chunk_df):.2f} MB)"
)

# Pagination buttons
col1, col2, col3 = st.columns([1, 2, 1])

with col1:
if st.button("Previous") and st.session_state.current_chunk > 0:
st.session_state.current_chunk -= 1

with col3:
if st.button("Next") and st.session_state.current_chunk < total_chunks - 1:
st.session_state.current_chunk += 1
rows = event["selection"]["rows"]
if not rows:
return None
# Calculate the index based on the current page and chunk size
base_index = (page - 1) * chunk_size
return base_index + rows[0]

if event is not None:
return event
return None


def show_table(df: pd.DataFrame, download_name: str = "") -> None:
Expand Down
58 changes: 0 additions & 58 deletions src/plotting/BasePlotter.py

This file was deleted.

221 changes: 0 additions & 221 deletions src/plotting/MSExperimentPlotter.py

This file was deleted.

Loading

0 comments on commit 36d93ae

Please sign in to comment.