From 395389582cf4fb7e99a1dcabcc250070aa9155b5 Mon Sep 17 00:00:00 2001 From: Logan Drescher Date: Thu, 24 Aug 2023 16:59:27 -0400 Subject: [PATCH] Flake8 changes --- biosimulators_copasi/core.py | 26 ++++++------- biosimulators_copasi/data_model.py | 60 ++++++++++++++++++------------ biosimulators_copasi/utils.py | 8 +--- 3 files changed, 48 insertions(+), 46 deletions(-) diff --git a/biosimulators_copasi/core.py b/biosimulators_copasi/core.py index 920c4ab..2a10a12 100644 --- a/biosimulators_copasi/core.py +++ b/biosimulators_copasi/core.py @@ -19,13 +19,12 @@ import biosimulators_copasi.utils as utils from biosimulators_utils.config import get_config, Config # noqa: F401 -from biosimulators_utils.log.data_model import CombineArchiveLog, TaskLog, \ - StandardOutputErrorCapturerLevel, SedDocumentLog # noqa: F401 +from biosimulators_utils.log.data_model import TaskLog, StandardOutputErrorCapturerLevel, SedDocumentLog # noqa: F401 from biosimulators_utils.viz.data_model import VizFormat # noqa: F401 from biosimulators_utils.report.data_model import ReportFormat, VariableResults, SedDocumentResults # noqa: F401 -from biosimulators_utils.sedml.data_model import (Algorithm, AlgorithmParameterChange, Task, Model, Simulation, - ModelLanguage, ModelChange, ModelAttributeChange, - UniformTimeCourseSimulation, Variable, Symbol, SedDocument) # noqa: F401 +from biosimulators_utils.sedml.data_model import \ + Algorithm, Task, Model, Simulation, ModelLanguage, ModelChange, ModelAttributeChange, \ + UniformTimeCourseSimulation, Variable, SedDocument # noqa: F401 from biosimulators_utils.sedml import validation from biosimulators_utils.utils.core import raise_errors_warnings from biosimulators_utils.warnings import warn, BioSimulatorsWarning @@ -35,7 +34,6 @@ import basico import COPASI import lxml -import math import numpy import os import tempfile @@ -45,6 +43,7 @@ proper_args: dict = {} + def get_simulator_version(): """ Get the version of COPASI @@ -53,6 +52,7 @@ def get_simulator_version(): """ return basico.__version__ + def exec_sedml_docs_in_combine_archive(archive_filename: str, out_dir: str, config: Config = None, should_fix_copasi_generated_combine_archive: bool = None) -> tuple: """ Execute the SED tasks defined in a COMBINE/OMEX archive and save the outputs @@ -234,7 +234,8 @@ def get_copasi_error_message(sim: Simulation, details=None): return error_msg -def preprocess_sed_task(task: Task, variables: list[Variable], config: Config = None) -> data_model.BasicoInitialization: +def preprocess_sed_task(task: Task, variables: list[Variable], + config: Config = None) -> data_model.BasicoInitialization: """ Preprocess a SED task, including its possible model changes and variables. This is useful for avoiding repeatedly initializing tasks on repeated calls of :obj:`exec_sed_task`. @@ -282,7 +283,7 @@ def preprocess_sed_task(task: Task, variables: list[Variable], config: Config = # process solution algorithm has_events: bool = basico_data_model.getModel().getNumEvents() >= 1 - copasi_algorithm = utils.get_algorithm(sim.algorithm.kisao_id, has_events, config=config) + copasi_algorithm = utils.get_algorithm(utc_sim.algorithm.kisao_id, has_events, config=config) # Create and return preprocessed simulation settings preprocessed_info = data_model.BasicoInitialization(copasi_algorithm, variables, has_events) @@ -332,9 +333,6 @@ def _apply_model_changes(sedml_model: Model, copasi_algorithm: utils.CopasiAlgor legal_changes: list[ModelAttributeChange] = [] illegal_changes: list[ModelChange] = [] - specs = basico.get_species() - comps = basico.get_compartments() - # If there's no changes, get out of here if not sedml_model.changes: return legal_changes, illegal_changes @@ -368,8 +366,8 @@ def _apply_model_changes(sedml_model: Model, copasi_algorithm: utils.CopasiAlgor basico.set_compartment(compart_map["name"], initial_size=model_change.new_value) continue - #reaction = basico.get_reactions(sbml_id=sbml_id) - #if reaction is not None: + # reaction = basico.get_reactions(sbml_id=sbml_id) + # if reaction is not None: # basico.set_reaction(sbml_id=sbml_id, ???) # continue @@ -382,7 +380,6 @@ def _apply_model_changes(sedml_model: Model, copasi_algorithm: utils.CopasiAlgor def _load_algorithm_parameters(sim: Simulation, copasi_algorithm: utils.CopasiAlgorithm, config: Config = None): # Load the algorithm parameter changes specified by `simulation.algorithm_parameter_changes` - method_parameters = {} algorithm_substitution_policy: AlgSubPolicy = bsu_sim_utils.get_algorithm_substitution_policy(config=config) requested_algorithm: Algorithm = sim.algorithm if copasi_algorithm.KISAO_ID != requested_algorithm.kisao_id: @@ -411,4 +408,3 @@ def _load_algorithm_parameters(sim: Simulation, copasi_algorithm: utils.CopasiAl warn(warning_message.format(change.new_value, change.kisao_id), BioSimulatorsWarning) return - diff --git a/biosimulators_copasi/data_model.py b/biosimulators_copasi/data_model.py index 1cabb68..d36624f 100644 --- a/biosimulators_copasi/data_model.py +++ b/biosimulators_copasi/data_model.py @@ -13,10 +13,7 @@ import basico import pandas -from biosimulators_utils.data_model import ValueType -import collections import enum -import math __all__ = [ 'Units', @@ -107,7 +104,8 @@ def get_value(self) -> float: return self._value def set_value(self, new_value: float): - if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285 + # can't use isinstance because PEP 285 + if new_value is not None and not (type(new_value) == float): # noqa: E721 raise ValueError self._value = new_value @@ -125,7 +123,8 @@ def get_value(self) -> float: return self._value def set_value(self, new_value: float): - if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285 + # can't use isinstance because PEP 285 + if new_value is not None and not (type(new_value) == float): # noqa: E721 raise ValueError self._value = new_value @@ -143,7 +142,8 @@ def get_value(self) -> bool: return self._value def set_value(self, new_value: bool): - if new_value is not None and not (type(new_value) == bool): # can't use isinstance because PEP 285 + # can't use isinstance because PEP 285 + if new_value is not None and not (type(new_value) == bool): # noqa: E721 raise ValueError self._value = new_value @@ -161,7 +161,8 @@ def get_value(self) -> int: return self._value def set_value(self, new_value: int): - if new_value is not None and not (type(new_value) == int): # can't use isinstance because PEP 285 + # can't use isinstance because PEP 285 + if new_value is not None and not (type(new_value) == int): # noqa: E721 raise ValueError self._value = new_value @@ -179,7 +180,8 @@ def get_value(self) -> float: return self._value def set_value(self, new_value: float): - if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285 + # can't use isinstance because PEP 285 + if new_value is not None and not (type(new_value) == float): # noqa: E721 raise ValueError self._value = new_value @@ -197,7 +199,8 @@ def get_value(self) -> int: return self._value def set_value(self, new_value: int): - if new_value is not None and not (type(new_value) == int): # can't use isinstance because PEP 285 + # can't use isinstance because PEP 285 + if new_value is not None and not (type(new_value) == int): # noqa: E721 raise ValueError self._value = new_value @@ -224,7 +227,8 @@ def get_value(self) -> float: return self._value def set_value(self, new_value: float): - if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285 + # can't use isinstance because PEP 285 + if new_value is not None and not (type(new_value) == float): # noqa: E721 raise ValueError self._value = new_value @@ -242,7 +246,8 @@ def get_value(self) -> float: return self._value def set_value(self, new_value: float): - if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285 + # can't use isinstance because PEP 285 + if new_value is not None and not (type(new_value) == float): # noqa: E721 raise ValueError self._value = new_value @@ -260,7 +265,8 @@ def get_value(self) -> float: return self._value def set_value(self, new_value: float): - if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285 + # can't use isinstance because PEP 285 + if new_value is not None and not (type(new_value) == float): # noqa: E721 raise ValueError self._value = new_value @@ -278,7 +284,8 @@ def get_value(self) -> int: return self._value def set_value(self, new_value: int): - if new_value is not None and not (type(new_value) == int): # can't use isinstance because PEP 285: + # can't use isinstance because PEP 285: + if new_value is not None and not (type(new_value) == int): # noqa: E721 raise ValueError self._value = new_value @@ -296,7 +303,8 @@ def get_value(self) -> float: return self._value def set_value(self, new_value: float): - if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285: + # can't use isinstance because PEP 285: + if new_value is not None and not (type(new_value) == float): # noqa: E721 raise ValueError self._value = new_value @@ -325,7 +333,8 @@ def get_value(self) -> float: return self._value def set_value(self, new_value: float): - if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285 + # can't use isinstance because PEP 285 + if new_value is not None and not (type(new_value) == float): # noqa: E721 raise ValueError self._value = new_value @@ -342,7 +351,8 @@ def get_value(self) -> float: return self._value def set_value(self, new_value: float): - if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285 + # can't use isinstance because PEP 285 + if new_value is not None and not (type(new_value) == float): # noqa: E721 raise ValueError self._value = new_value @@ -360,7 +370,8 @@ def get_value(self) -> float: return self._value def set_value(self, new_value: float): - if new_value is not None and not (type(new_value) == float): # can't use isinstance because PEP 285 + # can't use isinstance because PEP 285 + if new_value is not None and not (type(new_value) == float): # noqa: E721 raise ValueError self._value = new_value @@ -378,7 +389,8 @@ def get_value(self) -> bool: return self._value def set_value(self, new_value: bool): - if new_value is not None and not (type(new_value) == bool): # can't use isinstance because PEP 285: + # can't use isinstance because PEP 285: + if new_value is not None and not (type(new_value) == bool): # noqa: E721 raise ValueError self._value = new_value @@ -432,12 +444,11 @@ def get_method_settings(self) -> dict[str, str]: def __eq__(self, other): if not isinstance(other, type(self)): return False - return (True if ( - self.KISAO_ID == other.KISAO_ID, - self.ID == other.ID, - self.NAME == other.NAME, + equality = self.KISAO_ID == other.KISAO_ID and \ + self.ID == other.ID and \ + self.NAME == other.NAME and \ self.CAN_SUPPORT_EVENTS == other.CAN_SUPPORT_EVENTS - ) else False) + return True if equality else False class GibsonBruckAlgorithm(CopasiAlgorithm): @@ -757,6 +768,7 @@ class CopasiAlgorithmType(enum.Enum): HYBRID_RK45 = HybridRK45Algorithm SDE_SOLVE_RI5 = SDESolveRI5Algorithm + class CopasiMappings: @staticmethod def format_to_copasi_reaction_name(sbml_name: str): @@ -821,7 +833,7 @@ def _map_sbml_id_to_copasi_name(for_output: bool) -> dict[str, str]: compartment_mapping = {compartments.at[row, "sbml_id"]: str(row) for row in compartments.index} metabolites_mapping = {metabolites.at[row, "sbml_id"]: str(row) for row in metabolites.index} reactions_mapping = {reactions.at[row, "sbml_id"]: str(row) for row in reactions.index} - parameters_mapping = {parameters.at[row, "sbml_id"] : str(row) for row in parameters.index} + parameters_mapping = {parameters.at[row, "sbml_id"]: str(row) for row in parameters.index} # Combine mappings sbml_id_to_sbml_name_map = {"Time": "Time"} diff --git a/biosimulators_copasi/utils.py b/biosimulators_copasi/utils.py index 13991f7..a093be8 100644 --- a/biosimulators_copasi/utils.py +++ b/biosimulators_copasi/utils.py @@ -14,7 +14,7 @@ from biosimulators_utils.combine.io import CombineArchiveReader, CombineArchiveWriter from biosimulators_utils.config import get_config, Config # noqa: F401 from biosimulators_utils.simulator.utils import get_algorithm_substitution_policy -from biosimulators_utils.sedml.data_model import Variable, UniformTimeCourseSimulation, AlgorithmParameterChange +from biosimulators_utils.sedml.data_model import AlgorithmParameterChange from kisao.data_model import AlgorithmSubstitutionPolicy, ALGORITHM_SUBSTITUTION_POLICY_LEVELS from kisao.utils import get_preferred_substitute_algorithm_by_ids import libsedml @@ -22,7 +22,6 @@ import os import shutil import tempfile -import pandas __all__ = [ 'get_algorithm', @@ -178,8 +177,3 @@ def fix_copasi_generated_combine_archive(in_filename, out_filename, config=None) CombineArchiveWriter().run(archive, archive_directory_name, out_filename) finally: shutil.rmtree(archive_directory_name) - - - - -