Skip to content

Commit

Permalink
Added initial streamlit app for dashboard editor
Browse files Browse the repository at this point in the history
  • Loading branch information
nilshoffmann committed Oct 31, 2023
1 parent 49312cf commit 4a8c4f1
Show file tree
Hide file tree
Showing 10 changed files with 1,032 additions and 0 deletions.
161 changes: 161 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

72 changes: 72 additions & 0 deletions streamlit_app/FAIR_MS_Library_Editor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import json
import os
import tempfile
import streamlit as st

st.set_page_config(
layout="wide",
page_title="FAIR MS Library Curation Editor",
#page_icon="assets/favicon.ico",
menu_items={
'Get Help': 'https://github.com/mzmine/biohack23_p15',
'Report a bug': "https://github.com/mzmine/biohack23_p15/issues/new/choose",
'About': "# This is the creation and curation wizard for FAIR MS Libraries."
}
)

from streamlit.runtime.scriptrunner.script_run_context import get_script_run_ctx
ctx = get_script_run_ctx()
if 'session_id' not in st.session_state:
print("Setting session ID:", ctx.session_id)
st.session_state.session_id = ctx.session_id
else:
print("Retrieving session ID:", st.session_state.session_id)

if 'submission_id' not in st.session_state:
submission_id = "FMSL-"+st.session_state.session_id
print(f"Setting submission id {submission_id}")
st.session_state.submission_id = submission_id

submission_id = st.session_state.submission_id

if 'cv_config' not in st.session_state:
# reading the data from the file
with open('config.json') as f:
data = f.read()
config = json.loads(data)
st.session_state.cv_config = config

tmp_dir = tempfile.gettempdir()
working_dir = os.path.join(tmp_dir, "fairmslib", submission_id)
os.makedirs(working_dir, exist_ok=True)
print("Working dir:", working_dir)
st.session_state['working_dir'] = working_dir

st.title("FAIR MS Library Curation Editor")
st.markdown(f"Provisional submission ID: {submission_id}")

# Using "with" notation
with st.sidebar:
st.markdown("## Datasets")
if 'datasets' not in st.session_state or st.session_state['datasets'] == {}:
st.warning("Please upload a file to begin!")
if 'selected_sheets' not in st.session_state or st.session_state['selected_sheets'] == {}:
st.warning("Please select a dataset to begin!")
# with st.spinner("Loading..."):
# time.sleep(5)
# st.success("Done!")
if 'datasets' in st.session_state and st.session_state['datasets'] != {}:
for key in st.session_state['selected_sheets']:
with st.expander(key):
datasets = st.session_state['datasets']
rowsMetricColumn, columnsMetricColumn = st.columns(2)
with rowsMetricColumn:
st.metric('Rows', datasets[key].shape[0])
with columnsMetricColumn:
st.metric('Columns', datasets[key].shape[1])
# if st.button("Edit", key=key):
# selected_sheet = key
# if key in datasets_metadata:
# st.write(datasets_metadata[key].keys())
# st.write(datasets[dataset_key])
# st.json(datasets)
25 changes: 25 additions & 0 deletions streamlit_app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Streamlit Application for FAIR MassSpectral Library Curation and Editing

[GitHub repository](https://github.com/mzmine/biohack23_p15) - folder _streamlit_app_

## Installation

## Development

Use python venv to use defined dependencies.

python -m venv venv

source venv/bin/activate

to activate the virtual environment.

You can then use the provided requirements.txt to populate the required dependencies in your virtual environment.

pip install -r requirements.txt

## Running the application

After you have activated the virtual environment and the packages listed in requirements.txt are installed, you can launch the streamlit application as follows:

streamlit run FAIR_MS_Library_Editor.py
Empty file added streamlit_app/__init__.py
Empty file.
Empty file added streamlit_app/assets/.empty
Empty file.
20 changes: 20 additions & 0 deletions streamlit_app/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"ontologies": {
"NCIT": "ncit",
"MS": "ms",
"MSIO": "msio",
"UO": "uo",
"NCBITaxon": "ncbitaxon",
"BTO": "bto",
"PRIDE": "pride",
"EFO": "efo"
},
"static_cv_terms": {
"MS:1003309": {
"term_obo_id": "MS:1003309",
"cv": "MS",
"name": "Goslin",
"value": null
}
}
}
Loading

0 comments on commit 4a8c4f1

Please sign in to comment.