Skip to content

Commit

Permalink
fixed more flake8 and planemo linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
emikar committed Dec 2, 2024
1 parent e54e3d5 commit 90088d9
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 116 deletions.
13 changes: 0 additions & 13 deletions tools/gem_tools/.shed.yml

This file was deleted.

7 changes: 1 addition & 6 deletions tools/gem_tools/gem_check_memote.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<tool id="gem_check_memote" name="GEM check memote" version="0.17.0">
<description>Uses the Memote test suite to generate a quality report on a genome-scale metabolic model. See more at https://memote.readthedocs.io/en/latest/index.html</description>
<macros>
<import>gem_macros.xml</import>
</macros>
<description>Uses the Memote test suite to generate a quality report on a genome-scale metabolic model. See more at https://memote.readthedocs.io/en/latest/index.html</description>
<requirements>
<requirement type="package" version="0.17.0">memote</requirement>
<requirement type="package" version="8.3.3">pytest</requirement>
Expand Down Expand Up @@ -42,29 +42,24 @@
The GEM Check Memote tool runs the Memote test suite to generate a detailed report on the quality of a genome-scale metabolic model (GEM). Memote assesses various model characteristics such as stoichiometric consistency and model annotations.
Inputs
------
`Model to check with memote`: The metabolic model in SBML format (.xml or .sbml) to be analyzed by Memote. Ensure the file conforms to SBML standards.
Outputs
-------
`Memote report`: An HTML file that contains the full results of the Memote assessment. This report includes overall model quality scores and highlights any issues that need correction.
Usage Example
-------------
1. Upload your SBML model file.
2. Run the tool to generate the Memote report.
3. Review the report to identify any errors or areas for improvement in the model.
Troubleshooting
---------------
If the tool fails to run, ensure that your input file is a valid SBML model. Incorrect file formats or non-compliant models may trigger errors.
References
----------
Full documentation and further examples can be found at: https://memote.readthedocs.io/en/latest/index.html
]]></help>
Expand Down
3 changes: 2 additions & 1 deletion tools/gem_tools/gem_escher_visualization.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import argparse

import cobra
from escher import Builder
import pandas as pd
from escher import Builder


def __main__():
Expand Down
29 changes: 10 additions & 19 deletions tools/gem_tools/gem_escher_visualization.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<tool id="gem_escher_visualization" name="Escher visualization" version="1.7.3">
<description> Visualize the flux distribution of a GEM </description>
<macros>
<import>gem_macros.xml</import>
</macros>
<description> Visualize the flux distribution of a GEM </description>
<requirements>
<expand macro="requirement_cobra"/>
<expand macro="requirement_pandas"/>
<requirement type="package" version="1.7.3">escher</requirement>
<requirement type="package" version="2.4.7">pyparsing</requirement>
</requirements>
<expand macro="version_command_escher"/>
<command>
python '$__tool_directory__/gem_escher_visualization.py'
'-output' '${output}'
Expand Down Expand Up @@ -82,7 +83,6 @@
</when>
</conditional>
</inputs>
<expand macro="version_command_escher"/>
<outputs>
<data name="output" format="html" label="Escher visualization interactive html"/>
</outputs>
Expand All @@ -94,36 +94,28 @@
<param name="provide_custom_constraints" value="no"/>
<param name="map_selection" value="load_map"/>
<param name="map_load_name" value="e_coli_core.Core metabolism"/>
<output name="output">
<assert_contents>
<has_line line=" var data = get_data();"/>
</assert_contents>
</output>
</test>
<expand macro="test_invalid_model"/>
</tests>
<help><![CDATA[
Escher Visualization Tool
Overview
--------
This tool generates an interactive HTML visualization of metabolic flux distributions in a Genome-scale Metabolic Model (GEM) using Escher.
Inputs
------
1. Model File (Required):
* Upload a COBRA-compatible metabolic model file
* Supported formats include SBML (.xml) and JSON (.json)
2. Flux Distribution (Optional):
* Either upload a pre-calculated flux distribution
* Or let the tool calculate optimal flux distribution through FBA
* If calculating, you can optionally provide custom uptake constraints
3. Map Selection:
* Choose from pre-loaded maps for common metabolic models
* Upload your own Escher map
* Create a new map from scratch
* Model File (Required): COBRA-compatible metabolic model file
* Flux Distribution (Optional): a pre-calculated flux distribution
* Map Selection (Optional): maps for common metabolic models
Output
------
The tool generates an interactive HTML file that:
* Displays metabolic pathways with reaction fluxes
Expand All @@ -132,7 +124,6 @@
* Provides options for customizing the visualization
Tips
----
* Ensure your model is properly formatted and constrained
* For large models, consider visualizing specific subsystems
Expand Down
14 changes: 8 additions & 6 deletions tools/gem_tools/gem_extract_exchange.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse

import cobra


Expand All @@ -11,12 +12,13 @@ def get_exchange_reactions_info(model):
exchange_reactions = model.exchanges
exchange_reactions_info = []
for reaction in exchange_reactions:
exchange_reactions_info.append([
reaction.id,
reaction.name,
reaction.reaction,
reaction.lower_bound,
reaction.upper_bound
exchange_reactions_info.append(
[
reaction.id,
reaction.name,
reaction.reaction,
reaction.lower_bound,
reaction.upper_bound
])
txt_object = (
"reaction_id;reaction_name;reaction_stoichiometry;"
Expand Down
5 changes: 1 addition & 4 deletions tools/gem_tools/gem_extract_exchange.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<tool id="gem_extract_exchange" name="GEM get exchange bounds" version="@VERSION@">
<description> Extract the exchange reactions and bounds of a GEM </description>
<macros>
<import>gem_macros.xml</import>
</macros>
<description> Extract the exchange reactions and bounds of a GEM </description>
<requirements>
<expand macro="requirement_cobra"/>
</requirements>
Expand Down Expand Up @@ -35,17 +35,14 @@ python '$__tool_directory__/gem_extract_exchange.py' '--cb_model_location' '${cb
GEM Extract Exchange Bounds
Overview
--------
This tool extracts the exchange reactions and their associated bounds from a Genome-scale Metabolic (GEM) model in SBML format. The extracted exchange reactions are saved in a CSV file for further analysis or modification. Exchange reactions represent interactions between the metabolic network and the external environment, often used to simulate fluxes of metabolites in and out of the system.
Inputs
------
- `Model to extract exchange for`: This should be an SBML file containing the GEM model. The tool will identify and extract only the exchange reactions (reactions responsible for importing/exporting metabolites).
Outputs
-------
- `GEM exchange reactions`: A CSV file with the following columns:
- `reaction_id`: The ID of the exchange reaction.
Expand Down
17 changes: 9 additions & 8 deletions tools/gem_tools/gem_flux_distribution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse

import cobra
import pandas as pd

Expand Down Expand Up @@ -46,9 +47,9 @@ def __main__():
cb_model = cobra.io.read_sbml_model(args.cb_model_location)
except Exception as e:
raise Exception(
"The model could not be read. Ensure "
"it is in correct SBML format."
) from e
"The model could not be read. Ensure "
"it is in correct SBML format."
) from e

if args.uptake_constraints_file is not None\
and args.uptake_constraints_file != "None":
Expand All @@ -57,14 +58,14 @@ def __main__():
sep=";",
header=0,
index_col=False
)
for index, row in constraints_df.iterrows():
)
for _, row in constraints_df.iterrows():
cb_model.reactions.get_by_id(
row["reaction_id"]
).lower_bound = row["lower_bound"]
).lower_bound = row["lower_bound"]
cb_model.reactions.get_by_id(
row["reaction_id"]
).upper_bound = row["upper_bound"]
).upper_bound = row["upper_bound"]

# do pFBA
solution = cobra.flux_analysis.pfba(cb_model)
Expand All @@ -73,7 +74,7 @@ def __main__():
# reaction ids, and flux distribution
flux_distribution = pd.DataFrame(
columns=["reaction_name", "reaction_id", "flux"]
)
)

flux_distribution["reaction_name"] = \
[reaction.name for reaction in cb_model.reactions]
Expand Down
22 changes: 8 additions & 14 deletions tools/gem_tools/gem_flux_distribution.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<tool id="gem_flux_distribution" name="FBA flux distribution" version="@VERSION@">
<description> Calculate the optimal flux distribution of a GEM </description>
<macros>
<import>gem_macros.xml</import>
</macros>
<description> Calculate the optimal flux distribution of a GEM </description>
<requirements>
<expand macro="requirement_cobra"/>
<expand macro="requirement_pandas"/>
Expand All @@ -26,6 +26,11 @@
<test>
<param name="cb_model_location" value="textbook_model_cobrapy.xml"/>
<param name="uptake_constraints_file" value="textbook_model_cobrapy_exchange.csv"/>
<output name="output">
<assert_contents>
<has_line line="reaction_name;reaction_id;flux"/>
</assert_contents>
</output>
</test>
<!-- Test 2: Invalid model format -->
<test expect_failure="true">
Expand All @@ -42,36 +47,25 @@
This tool performs Flux Balance Analysis (FBA) to calculate the optimal flux distribution of a Genome-scale Metabolic Model (GEM).
What it does
-----------
* Reads a SBML-formatted metabolic model
* Applies user-specified uptake constraints
* Calculates the optimal flux distribution using FBA
* Outputs the results in CSV format
Input files
-----------
1. **Model file** (required):
* Must be in SBML format (.xml)
* Should contain a valid genome-scale metabolic model
* Must be compatible with COBRApy
2. **Uptake constraints file** (optional):
* CSV format
* Contains exchange reaction constraints
* Format: reaction_id,lower_bound,upper_bound
*Model file** (required): Must be in SBML format (.xml), compatible with COBRApy
*Uptake constraints file* (optional): CSV format
Output
------
The tool generates a CSV file containing:
* Reaction IDs
* Calculated flux values for each reaction
* Optimal flux distribution based on the model's objective function
Common Issues
------------
If the tool fails, check:
* Is your SBML model valid?
Expand Down
7 changes: 4 additions & 3 deletions tools/gem_tools/gem_flux_variability_analysis.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse

import cobra
import pandas as pd

Expand Down Expand Up @@ -77,7 +78,7 @@ def __main__():
except FileNotFoundError:
raise FileNotFoundError(
f"Constraints file not found: {args.uptake_constraints_file}"
)
)
except pd.errors.EmptyDataError:
raise ValueError("Constraints file is empty")
except Exception as e:
Expand Down Expand Up @@ -106,12 +107,12 @@ def __main__():
fva_result["reaction_id"] = fva_result.index
fva_result["reaction_name"] = fva_result["reaction_id"].apply(
lambda x: cb_model.reactions.get_by_id(x).name
)
)

# reorder the columns
fva_result = fva_result[[
"reaction_id", "reaction_name", "minimum", "maximum"
]]
]]

fva_result.to_csv(args.out_file, sep=";", index=False, header=True)

Expand Down
15 changes: 12 additions & 3 deletions tools/gem_tools/gem_flux_variability_analysis.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@
<test>
<param name="cb_model_location" value="textbook_model_cobrapy.xml"/>
<param name="fraction_of_optimum" value="0.99"/>
<output name="output">
<assert_contents>
<has_line line="reaction_id;reaction_name;minimum;maximum" />
</assert_contents>
</output>
</test>
<test>
<param name="cb_model_location" value="textbook_model_cobrapy.xml"/>
<param name="fraction_of_optimum" value="0.99"/>
<param name="uptake_constraints_file" value="textbook_model_cobrapy_exchange.csv"/>
<output name="output">
<assert_contents>
<has_line line="reaction_id;reaction_name;minimum;maximum" />
</assert_contents>
</output>
</test>
</tests>
<help><![CDATA[
Expand All @@ -43,7 +53,6 @@
This tool performs Flux Variability Analysis (FVA) on a Genome-scale Metabolic Model (GEM). FVA is a method used to determine the minimum and maximum flux values that each reaction in the network can carry while maintaining a specific objective value.
Input Parameters
--------------
**Model File**: A GEM in SBML format (.xml) that will be analyzed.
Expand All @@ -55,15 +64,15 @@
**Uptake Constraints File** (optional): A CSV file specifying constraints for exchange reactions. The file should contain columns for exchange reaction IDs and their corresponding bounds.
Output
------
The tool generates a CSV file containing:
- Reaction IDs
- Minimum flux values
- Maximum flux values
for each reaction in the model.
Common Issues
------------
- Ensure your model is well-formatted and contains no structural errors
- Check that exchange reactions are properly defined
- Verify that the model is feasible under the given constraints
Expand Down
Loading

0 comments on commit 90088d9

Please sign in to comment.