Skip to content

Commit beafada

Browse files
author
CiaranWelsh
committed
changed mixin to base class
1 parent 90b236e commit beafada

File tree

5 files changed

+131
-226
lines changed

5 files changed

+131
-226
lines changed

Tests/build_antimony_tests.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,10 @@ def test_exception(self):
105105
)
106106

107107
except Exception as E:
108-
self.assertEqual(E.message, exception_message)
109-
110-
def tearDown(self):
111-
rmtree(self.dire)
108+
self.assertEqual(str(E.message), str(exception_message))
112109

110+
# def tearDown(self):
111+
# rmtree(self.dire)
113112

114113

115114
class BuildAntimonyTestsWithoutRemovalBetweenTests(unittest.TestCase):
@@ -151,8 +150,8 @@ def setUp(self):
151150

152151
assert os.path.isfile(self.copasi_file1)
153152

154-
def tearDown(self):
155-
rmtree(self.dire)
153+
# def tearDown(self):
154+
# rmtree(self.dire)
156155

157156
def test_build_model_to_file_path_which_already_exists(self):
158157
with model.BuildAntimony(self.copasi_file1) as loader:
@@ -221,8 +220,8 @@ def setUp(self):
221220

222221
assert os.path.isfile(self.copasi_file1)
223222

224-
def tearDown(self):
225-
rmtree(self.dire)
223+
# def tearDown(self):
224+
# rmtree(self.dire)
226225

227226
def test_metabolites(self):
228227
self.assertListEqual(['A', 'B'], sorted([i.name for i in self.mod.metabolites]))
File renamed without changes.

Tests/test_pearsons_heatmap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def setUp(self):
9191

9292

9393
def test(self):
94-
P = viz.PearsonsHeatMap(self.fit1)
94+
P = viz.PearsonsCorrelation(self.fit1)
9595
print(P.pearsons)
9696
print(P.p_val)
9797

pycotools/tasks.py

+46-85
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@
6262
font_scale=3)
6363

6464

65-
66-
class GetModelVariableFromStringMixin(Mixin):
65+
class _Task(object):
66+
"""
67+
base class for tasks
68+
"""
6769
@staticmethod
6870
def get_variable_from_string(m, v, glob=False):
6971
"""
@@ -111,9 +113,6 @@ def get_variable_from_string(m, v, glob=False):
111113
assert isinstance(v, str) != True
112114
return v
113115

114-
115-
class UpdatePropertiesMixin(Mixin):
116-
117116
def update_properties(self, kwargs):
118117
"""
119118
method for updating properties from kwargs
@@ -128,21 +127,16 @@ def update_properties(self, kwargs):
128127
except AttributeError:
129128
setattr(self, k, kwargs[k])
130129

131-
132-
class Bool2Numeric(Mixin):
133-
"""
134-
CopasiML uses 1's and 0's for True or False in some
135-
but not all places. When one of these options
136-
is required by the user and is specified as bool,
137-
this class converts them into 1's or 0's.
138-
139-
Use this method in early on in constructor for
140-
all subclasses where this applies.
141-
"""
142-
143130
@staticmethod
144131
def convert_bool_to_numeric(dct):
145132
"""
133+
CopasiML uses 1's and 0's for True or False in some
134+
but not all places. When one of these options
135+
is required by the user and is specified as bool,
136+
this class converts them into 1's or 0's.
137+
138+
Use this method in early on in constructor for
139+
all subclasses where this applies.
146140
:param:
147141
`dict`. __dict__ or kwargs or options
148142
@@ -182,15 +176,36 @@ def convert_bool_to_numeric(dct):
182176
raise Exception('{} is not True or False'.format(v))
183177
return dct
184178

179+
@staticmethod
180+
def check_integrity(allowed, given):
181+
"""
182+
Method to raise an error when a wrong
183+
kwarg is passed to a subclass
184+
:param allowed:
185+
`list`. List of allowed kwargs
186+
187+
:param given: List of kwargs given by user or default
188+
189+
:return:
190+
None
191+
"""
192+
for key in given:
193+
if key not in allowed:
194+
raise errors.InputError('{} not in {}'.format(key, allowed))
195+
185196

186-
class Bool2Str():
197+
class Bool2Str(object):
187198
"""
188199
copasiML expects strings and we pythoners
189200
want to use python booleans not strings
190201
This class quickly converts between them
191202
"""
192203

193204
def __init__(self, dct):
205+
"""
206+
207+
:param dct: dict[kwarg] = boolean
208+
"""
194209
self.dct = dct
195210
if isinstance(self.dct, dict) != True:
196211
raise errors.InputError('Input must be dict')
@@ -223,26 +238,7 @@ def convert_dct(self):
223238
return self.dct
224239

225240

226-
class CheckIntegrityMixin(Mixin):
227-
@staticmethod
228-
def check_integrity(allowed, given):
229-
"""
230-
Method to raise an error when a wrong
231-
kwarg is passed to a subclass
232-
:param allowed:
233-
`list`. List of allowed kwargs
234-
235-
:param given: List of kwargs given by user or default
236-
237-
:return:
238-
None
239-
"""
240-
for key in given:
241-
if key not in allowed:
242-
raise errors.InputError('{} not in {}'.format(key, allowed))
243-
244-
245-
class CopasiMLParser(object):
241+
class CopasiMLParser(_Task):
246242
"""
247243
Parse a copasi file into xml.etree.
248244
@@ -284,11 +280,8 @@ def write_copasi_file(self, copasi_filename, xml):
284280
root.write(copasi_filename)
285281

286282

287-
@mixin(UpdatePropertiesMixin)
288-
@mixin(Bool2Numeric)
289283
@mixin(model.ReadModelMixin)
290-
@mixin(CheckIntegrityMixin)
291-
class Run(object):
284+
class Run(_Task):
292285
"""
293286
Execute a copasi model using CopasiSE. To
294287
be operational the environment variable CopasiSE
@@ -517,11 +510,8 @@ def submit_copasi_job_slurm(self):
517510

518511

519512
@mixin(model.GetModelComponentFromStringMixin)
520-
@mixin(UpdatePropertiesMixin)
521513
@mixin(model.ReadModelMixin)
522-
@mixin(CheckIntegrityMixin)
523-
@mixin(Bool2Numeric)
524-
class RunParallel(object):
514+
class RunParallel(_Task):
525515
"""
526516
527517
@@ -635,12 +625,8 @@ def run_parallel(self):
635625

636626

637627
@mixin(model.GetModelComponentFromStringMixin)
638-
# @mixin(GetModelVariableFromStringMixin)
639-
@mixin(UpdatePropertiesMixin)
640628
@mixin(model.ReadModelMixin)
641-
@mixin(CheckIntegrityMixin)
642-
@mixin(Bool2Numeric)
643-
class Reports(object):
629+
class Reports(_Task):
644630
"""
645631
Creates reports in copasi output specification section. Which report is
646632
controlled by the report_type key word. The following are valid types of
@@ -1091,12 +1077,8 @@ def clear_all_reports(self):
10911077
return self.model
10921078

10931079

1094-
@mixin(GetModelVariableFromStringMixin)
1095-
@mixin(UpdatePropertiesMixin)
1096-
@mixin(Bool2Numeric)
10971080
@mixin(model.ReadModelMixin)
1098-
@mixin(CheckIntegrityMixin)
1099-
class TimeCourse(object):
1081+
class TimeCourse(_Task):
11001082
"""
11011083
##todo implement arguments that get passed on to report
11021084
as **report_kwargs
@@ -1678,12 +1660,8 @@ def get_report_key(self):
16781660
return key
16791661

16801662

1681-
@mixin(GetModelVariableFromStringMixin)
1682-
@mixin(UpdatePropertiesMixin)
1683-
@mixin(Bool2Numeric)
16841663
@mixin(model.ReadModelMixin)
1685-
@mixin(CheckIntegrityMixin)
1686-
class Scan(object):
1664+
class Scan(_Task):
16871665
"""
16881666
Interface to COPASI scan task
16891667
@@ -2096,11 +2074,8 @@ def execute(self):
20962074

20972075

20982076
@mixin(model.GetModelComponentFromStringMixin)
2099-
@mixin(UpdatePropertiesMixin)
21002077
@mixin(model.ReadModelMixin)
2101-
@mixin(CheckIntegrityMixin)
2102-
@mixin(Bool2Numeric)
2103-
class ExperimentMapper(object):
2078+
class ExperimentMapper(_Task):
21042079
"""
21052080
Class for mapping variables from file to cps
21062081
@@ -2588,13 +2563,9 @@ def map_experiments(self):
25882563
return self.model
25892564

25902565

2591-
@mixin(GetModelVariableFromStringMixin)
25922566
@mixin(model.GetModelComponentFromStringMixin)
2593-
@mixin(UpdatePropertiesMixin)
25942567
@mixin(model.ReadModelMixin)
2595-
@mixin(CheckIntegrityMixin)
2596-
@mixin(Bool2Numeric)
2597-
class ParameterEstimation(object):
2568+
class ParameterEstimation(_Task):
25982569
"""
25992570
Set up and run a parameter estimation in copasi.
26002571
@@ -3800,7 +3771,7 @@ def setup(self):
38003771
# print self.model
38013772

38023773

3803-
class ChaserParameterEstimations(object):
3774+
class ChaserParameterEstimations(_Task):
38043775
"""
38053776
Perform secondary hook and jeeves parameter estimations
38063777
starting from the best values of a primary global estimator.
@@ -4080,11 +4051,8 @@ def run(self):
40804051
Run(mod, task='parameter_estimation', mode=self.run_mode)
40814052

40824053

4083-
@mixin(UpdatePropertiesMixin)
4084-
@mixin(Bool2Numeric)
40854054
@mixin(model.ReadModelMixin)
4086-
@mixin(CheckIntegrityMixin)
4087-
class MultiModelFit(object):
4055+
class MultiModelFit(_Task):
40884056
"""
40894057
Coordinate a systematic multi model fitting parameter estimation and
40904058
compare results using :py:class:`viz.ModelSelection`
@@ -4320,11 +4288,8 @@ def format_data(self):
43204288

43214289

43224290
@mixin(model.GetModelComponentFromStringMixin)
4323-
@mixin(UpdatePropertiesMixin)
4324-
@mixin(Bool2Numeric)
43254291
@mixin(model.ReadModelMixin)
4326-
@mixin(CheckIntegrityMixin)
4327-
class ProfileLikelihood(object):
4292+
class ProfileLikelihood(_Task):
43284293
"""
43294294
43304295
@@ -4930,14 +4895,10 @@ def run_analysis(self):
49304895
sge_job_filename = re.sub('[().]', '', sge_job_filename)
49314896
Run(self.model_dct[m][param], task='scan', mode=self.run, sge_job_filename=sge_job_filename + '.sh')
49324897

4898+
49334899
@mixin(model.GetModelComponentFromStringMixin)
4934-
@mixin(UpdatePropertiesMixin)
4935-
@mixin(Bool2Numeric)
49364900
@mixin(model.ReadModelMixin)
4937-
@mixin(CheckIntegrityMixin)
4938-
class Sensitivities(object):
4939-
4940-
4901+
class Sensitivities(_Task):
49414902

49424903

49434904
def __init__(self, model, **kwargs):

0 commit comments

Comments
 (0)