Open zakandrewking opened 5 years ago
So cobrapy does not allow for spaces in IDs but does in names (description). Do you know if matlab models make a distinction between id and description/name? Looks like they don't and this is why the matlab reader uses the names as the IDs. There is basically two options:
It seems like 2 might be what you prefer but has some edge cases (what if my compartment
and my_compartment
are both in the model?
I'm not familiar enough with the needs in MATLAB / COBRA Toolbox to provide much direction here.
If necessary, we can restrict compartment names in BiGG to not include spaces, but that could be confusing going forward since other descriptive names allow spaces.
I believe I'm facing a similar error from loading a .mat file with a space in a variable name, rather than a compartment name. If there are any short-term workarounds I'd try them out - any ideas?
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-9-6e190386ff75> in <module>
----> 1 iJN = cobra.io.load_matlab_model(join(model_dir, "IndiMeSH/Cb_iJN746_rGEM.mat"))
~/.local/lib/python3.8/site-packages/cobra/io/mat.py in load_matlab_model(infile_path, variable_name, inf)
81 variable_name = possible_names[0]
82 if variable_name is not None:
---> 83 return from_mat_struct(data[variable_name], model_id=variable_name, inf=inf)
84 for possible_name in possible_names:
85 try:
~/.local/lib/python3.8/site-packages/cobra/io/mat.py in from_mat_struct(mat_struct, model_id, inf)
251 pass
252 new_reactions.append(new_reaction)
--> 253 model.add_reactions(new_reactions)
254 set_objective(model, coefficients)
255 coo = scipy_sparse.coo_matrix(m["S"][0, 0])
~/.local/lib/python3.8/site-packages/cobra/core/model.py in add_reactions(self, reaction_list)
708
709 # from cameo ...
--> 710 self._populate_solver(pruned)
711
712 def remove_reactions(self, reactions, remove_orphans=False):
~/.local/lib/python3.8/site-packages/cobra/core/model.py in _populate_solver(self, reaction_list, metabolite_list)
1002 for reaction in reaction_list:
1003 if reaction.id not in self.variables:
-> 1004 forward_variable = self.problem.Variable(reaction.id)
1005 reverse_variable = self.problem.Variable(reaction.reverse_id)
1006 self.add_cons_vars([forward_variable, reverse_variable])
~/.local/lib/python3.8/site-packages/optlang/symbolics.py in __new__(cls, name, **kwargs)
127 obj = sympy.Symbol.__new__(cls, str(uuid.uuid1()))
128
--> 129 obj.name = name
130 obj._assumptions = FactKB(_assume_rules)
131 obj._assumptions._tell('commutative', True)
~/.local/lib/python3.8/site-packages/optlang/gurobi_interface.py in name(self, value)
170 def name(self, value):
171 internal_var = self._internal_variable
--> 172 super(Variable, Variable).name.fset(self, value)
173 if internal_var is not None:
174 internal_var.setAttr('VarName', value)
~/.local/lib/python3.8/site-packages/optlang/interface.py in name(self, value)
193 @name.setter
194 def name(self, value):
--> 195 self.__validate_variable_name(value)
196 old_name = getattr(self, 'name', None)
197 self._name = value
~/.local/lib/python3.8/site-packages/optlang/interface.py in __validate_variable_name(name)
147 for char in name:
148 if char.isspace():
--> 149 raise ValueError(
150 'Variable names cannot contain whitespace characters. "%s" contains whitespace character "%s".' % (
151 name, char)
ValueError: Variable names cannot contain whitespace characters. "clpn120 transport" contains whitespace character " ".
One question about that, maybe need @matthiaskoenig input. How does SBML standard deal with spaces in various places? Could we do the same? I doubt SBML would allow spaces in variable names.
No it does not allow that. So that should throw an error or be fixed with a warning.
would SBML allow spaces if they are escaped like "\ " or not that either?
On Thu, Apr 7, 2022 at 2:04 PM Christian Diener @.***> wrote:
No it does not. So that should throw an error or be fixed with a warning.
— Reply to this email directly, view it on GitHub https://github.com/opencobra/cobrapy/issues/919#issuecomment-1092049883, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACQYYZQPITTALLRHYQHRL6DVD4PSJANCNFSM4JFIXAUQ . You are receiving this because you commented.Message ID: @.***>
Nope. Tools usually sub with ASCII codes like "first32second". But subbing with underscores might be okay.
Problem description
In BiGG Models, we have some compartment names with spaces in them:
http://bigg.ucsd.edu/models/iCHOv1/metabolites/h_im
COBRApy (v0.17) can read JSON and SBML files generated with this data. But if one tries to round-trip to a .mat file, an error occurs:
Dependency Information