Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
XBanalysis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Schubert
XBanalysis
Commits
29170105
Commit
29170105
authored
2 years ago
by
Peter Schubert
Browse files
Options
Downloads
Patches
Plain Diff
support unit definitions
parent
961ba3d4
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
xbanalysis/model/__init__.py
+3
-2
3 additions, 2 deletions
xbanalysis/model/__init__.py
xbanalysis/model/xba_model.py
+3
-0
3 additions, 0 deletions
xbanalysis/model/xba_model.py
xbanalysis/model/xba_unit_def.py
+55
-0
55 additions, 0 deletions
xbanalysis/model/xba_unit_def.py
with
61 additions
and
2 deletions
xbanalysis/model/__init__.py
+
3
−
2
View file @
29170105
"""
Subpackage with XBA model classes
"""
from
.xba_model
import
XbaModel
from
.xba_unit_def
import
XbaUnitDef
,
XbaUnit
from
.xba_compartment
import
XbaCompartment
from
.xba_function
import
XbaFunction
from
.xba_parameter
import
XbaParameter
...
...
@@ -8,5 +9,5 @@ from .xba_reaction import XbaReaction
from
.xba_species
import
XbaSpecies
from
.sbo_term
import
SboTerm
__all__
=
[
'
XbaModel
'
,
'
Xba
Compartment
'
,
'
XbaFunction
'
,
'
Xba
P
ar
a
met
er
'
,
'
XbaReaction
'
,
'
XbaSpecies
'
,
'
SboTerm
'
]
__all__
=
[
'
XbaModel
'
,
'
Xba
UnitDef
'
,
'
XbaUnit
'
,
'
Xba
Comp
ar
t
me
n
t
'
,
'
XbaFunction
'
,
'
XbaParameter
'
,
'
XbaReaction
'
,
'
XbaSpecies
'
,
'
SboTerm
'
]
This diff is collapsed.
Click to expand it.
xbanalysis/model/xba_model.py
+
3
−
0
View file @
29170105
...
...
@@ -9,6 +9,7 @@ import numpy as np
import
sbmlxdf
from
scipy.sparse
import
coo_array
from
.xba_unit_def
import
XbaUnitDef
from
.xba_compartment
import
XbaCompartment
from
.xba_function
import
XbaFunction
from
.xba_parameter
import
XbaParameter
...
...
@@ -32,6 +33,8 @@ class XbaModel:
print
(
f
'
{
sbml_file
}
seems not to be a valid SBML model
'
)
return
model_dict
=
sbml_model
.
to_df
()
self
.
unit_defs
=
{
udid
:
XbaUnitDef
(
row
)
for
udid
,
row
in
model_dict
[
'
unitDefs
'
].
iterrows
()}
self
.
compartments
=
{
cid
:
XbaCompartment
(
row
)
for
cid
,
row
in
model_dict
[
'
compartments
'
].
iterrows
()}
self
.
parameters
=
{
pid
:
XbaParameter
(
row
)
...
...
This diff is collapsed.
Click to expand it.
xbanalysis/model/xba_unit_def.py
0 → 100644
+
55
−
0
View file @
29170105
"""
Implementation of XbaUnitDef class.
Peter Schubert, HHU Duesseldorf, May 2022
"""
import
numpy
as
np
import
sbmlxdf
class
XbaUnitDef
:
def
__init__
(
self
,
s_unit_def
):
self
.
id
=
s_unit_def
.
name
self
.
name
=
s_unit_def
.
get
(
'
name
'
,
self
.
id
)
self
.
units
=
[
XbaUnit
(
sbmlxdf
.
extract_params
(
u
))
for
u
in
sbmlxdf
.
record_generator
(
s_unit_def
[
'
units
'
])]
def
is_equivalent
(
self
,
qry_units
):
if
len
(
qry_units
)
!=
len
(
self
.
units
):
return
False
else
:
equivalent_u
=
np
.
zeros
(
len
(
qry_units
))
for
i
,
qry_unit
in
enumerate
(
qry_units
):
for
unit
in
self
.
units
:
if
unit
==
qry_unit
:
equivalent_u
[
i
]
=
1
break
return
np
.
all
(
equivalent_u
)
class
XbaUnit
:
def
__init__
(
self
,
params
):
self
.
kind
=
params
.
get
(
'
kind
'
)
self
.
exp
=
float
(
params
.
get
(
'
exp
'
,
'
1.0
'
))
self
.
scale
=
int
(
params
.
get
(
'
scale
'
,
'
0
'
))
self
.
mult
=
float
(
params
.
get
(
'
mult
'
,
'
1.0
'
))
def
__eq__
(
self
,
other
):
if
(
self
.
kind
==
other
.
kind
and
self
.
exp
==
other
.
exp
and
self
.
scale
==
other
.
scale
and
self
.
mult
==
other
.
mult
):
return
True
else
:
return
False
def
__str__
(
self
):
factor
=
self
.
mult
*
10
**
self
.
scale
factor_str
=
f
'
{
factor
}
'
if
factor
!=
1.0
else
''
if
self
.
exp
!=
1.0
:
unit_str
=
f
'
(
{
factor_str
}{
self
.
kind
}
)^
{
self
.
exp
}
'
else
:
unit_str
=
f
'
{
factor_str
}{
self
.
kind
}
'
return
unit_str
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment