forked from OpenMS/streamlit-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request OpenMS#41 from axelwalter/main
Framework for TOPP tool workflows
- Loading branch information
Showing
19 changed files
with
1,953 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"mzML_files": [ | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import streamlit as st | ||
from src.common import page_setup | ||
from src.Workflow import Workflow | ||
|
||
# The rest of the page can, but does not have to be changed | ||
if __name__ == "__main__": | ||
|
||
params = page_setup() | ||
|
||
wf = Workflow() | ||
|
||
st.title(wf.name) | ||
|
||
t = st.tabs(["📁 **File Upload**", "⚙️ **Configure**", "🚀 **Run**", "📊 **Results**"]) | ||
with t[0]: | ||
wf.show_file_upload_section() | ||
|
||
with t[1]: | ||
wf.show_parameter_section() | ||
|
||
with t[2]: | ||
wf.show_execution_section() | ||
|
||
with t[3]: | ||
wf.show_results_section() | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import streamlit as st | ||
from .workflow.WorkflowManager import WorkflowManager | ||
|
||
class Workflow(WorkflowManager): | ||
# Setup pages for upload, parameter, execution and results. | ||
# For layout use any streamlit components such as tabs (as shown in example), columns, or even expanders. | ||
def __init__(self) -> None: | ||
# Initialize the parent class with the workflow name. | ||
super().__init__("TOPP Workflow", st.session_state["workspace"]) | ||
|
||
def upload(self)-> None: | ||
t = st.tabs(["MS data", "Example with fallback data"]) | ||
with t[0]: | ||
# Use the upload method from StreamlitUI to handle mzML file uploads. | ||
self.ui.upload_widget(key="mzML-files", name="MS data", file_type="mzML") | ||
with t[1]: | ||
# Example with fallback data (not used in workflow) | ||
self.ui.upload_widget(key="image", file_type="png", fallback="assets/OpenMS.png") | ||
|
||
def configure(self) -> None: | ||
# Allow users to select mzML files for the analysis. | ||
self.ui.select_input_file("mzML-files", multiple=True) | ||
|
||
# Create tabs for different analysis steps. | ||
t = st.tabs( | ||
["**Feature Detection**", "**Adduct Detection**", "**SIRIUS Export**", "**Python Custom Tool**"] | ||
) | ||
with t[0]: | ||
# Parameters for FeatureFinderMetabo TOPP tool. | ||
self.ui.input_TOPP("FeatureFinderMetabo") | ||
with t[1]: | ||
# A single checkbox widget for workflow logic. | ||
self.ui.input_widget("run-adduct-detection", False, "Adduct Detection") | ||
# Paramters for MetaboliteAdductDecharger TOPP tool. | ||
self.ui.input_TOPP("MetaboliteAdductDecharger") | ||
with t[2]: | ||
# Paramters for SiriusExport TOPP tool | ||
self.ui.input_TOPP("SiriusExport") | ||
with t[3]: | ||
# Generate input widgets for a custom Python tool, located at src/python-tools. | ||
# Parameters are specified within the file in the DEFAULTS dictionary. | ||
self.ui.input_python("example") | ||
|
||
def execution(self) -> None: | ||
# Get mzML input files from self.params. | ||
# Can be done without file manager, however, it ensures everything is correct. | ||
in_mzML = self.file_manager.get_files(self.params["mzML-files"]) | ||
|
||
# Log any messages. | ||
self.logger.log(f"Number of input mzML files: {len(in_mzML)}") | ||
|
||
# Prepare output files for feature detection. | ||
out_ffm = self.file_manager.get_files(in_mzML, "featureXML", "feature-detection") | ||
|
||
# Run FeatureFinderMetabo tool with input and output files. | ||
self.executor.run_topp( | ||
"FeatureFinderMetabo", input_output={"in": in_mzML, "out": out_ffm} | ||
) | ||
|
||
# Check if adduct detection should be run. | ||
if self.params["run-adduct-detection"]: | ||
|
||
# Run MetaboliteAdductDecharger for adduct detection, with disabled logs. | ||
# Without a new file list for output, the input files will be overwritten in this case. | ||
self.executor.run_topp( | ||
"MetaboliteAdductDecharger", {"in": out_ffm, "out_fm": out_ffm}, write_log=False | ||
) | ||
|
||
# Example for a custom Python tool, which is located in src/python-tools. | ||
self.executor.run_python("example", {"in": in_mzML}) | ||
|
||
# Prepare output file for SiriusExport. | ||
out_se = self.file_manager.get_files("sirius.ms", set_results_dir="sirius-export") | ||
self.executor.run_topp("SiriusExport", {"in": self.file_manager.get_files(in_mzML, collect=True), | ||
"in_featureinfo": self.file_manager.get_files(out_ffm, collect=True), | ||
"out": out_se}) | ||
|
||
def results(self) -> None: | ||
st.warning("Not implemented yet.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import json | ||
import sys | ||
|
||
############################ | ||
# default paramter values # | ||
########################### | ||
# | ||
# Mandatory keys for each parameter | ||
# key: a unique identifier | ||
# value: the default value | ||
# | ||
# Optional keys for each parameter | ||
# name: the name of the parameter | ||
# hide: don't show the parameter in the parameter section (e.g. for input/output files) | ||
# options: a list of valid options for the parameter | ||
# min: the minimum value for the parameter (int and float) | ||
# max: the maximum value for the parameter (int and float) | ||
# step_size: the step size for the parameter (int and float) | ||
# help: a description of the parameter | ||
# widget_type: the type of widget to use for the parameter (default: auto) | ||
# advanced: whether or not the parameter is advanced (default: False) | ||
|
||
DEFAULTS = [ | ||
{"key": "in", "value": [], "help": "Input files for Python Script.", "hide": True}, | ||
{"key": "out", "value": [], "help": "Output files for Python Script.", "hide": True}, | ||
{ | ||
"key": "number-slider", | ||
"name": "number of features", | ||
"value": 6, | ||
"min": 2, | ||
"max": 10, | ||
"help": "How many features to consider.", | ||
"widget_type": "slider", | ||
"step_size": 2, | ||
}, | ||
{ | ||
"key": "selectbox-example", | ||
"value": "a", | ||
"options": ["a", "b", "c"], | ||
}, | ||
{ | ||
"key": "adavanced-input", | ||
"value": 5, | ||
"step_size": 5, | ||
"help": "An advanced example parameter.", | ||
"advanced": True, | ||
}, | ||
{ | ||
"key": "checkbox", "value": True | ||
} | ||
] | ||
|
||
def get_params(): | ||
if len(sys.argv) > 1: | ||
with open(sys.argv[1], "r") as f: | ||
return json.load(f) | ||
else: | ||
return {} | ||
|
||
if __name__ == "__main__": | ||
params = get_params() | ||
# Add code here: | ||
print("Writing stdout which will get logged...") | ||
print("Parameters for this example Python tool:") | ||
print(json.dumps(params, indent=4)) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__ |
Oops, something went wrong.