Closed MaaikeRemeijer closed 9 months ago
Hello! Thank you very much for submitting this bug report, it really helped us, and you're right that we miss an opportunity to check the reaction ID for a whitespace which causes all these annoying and non-recoverable further bugs D: I'll submit a pull request with a fix in a second, and it will be integrated in CNApy's next version :-)
Hi,
I am currently making a model of a small network in CNApy. Sometimes I accidentally type a space in the reaction id field, which is understandably not allowed, and I get this error:
Traceback (most recent call last): File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\cnapy\gui_elements\reactions_list.py", line 938, in reaction_data_changed self.apply() File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\cnapy\gui_elements\reactions_list.py", line 701, in apply self.reaction.id = self.id.text() File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\cobra\core\object.py", line 56, in id self._set_id_with_model(value) File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\cobra\core\reaction.py", line 145, in _set_id_with_model forward_variable.name = self.id File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\optlang\glpk_interface.py", line 147, in name super(Variable, Variable).name.fset(self, value) File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\optlang\interface.py", line 195, in name self.__validate_variable_name(value) File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\optlang\interface.py", line 149, in __validate_variable_name raise ValueError( ValueError: Variable names cannot contain whitespace characters. "NAD " contains whitespace character " ".
When I try to save to store my progress, this does not work anymore and I lose all my progress (after I have corrected the reaction id). I get the following error when trying to save (also repeatedly when correcting the reaction id):
Traceback (most recent call last): File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\optlang\container.py", line 82, in __getitem__ return self._object_list[item] # Try treating item as int or slice TypeError: list indices must be integers or slices, not str During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\cnapy\gui_elements\main_window.py", line 1389, in save_project self.continue_save_project() File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\cnapy\gui_elements\main_window.py", line 1399, in continue_save_project self.save_sbml(tmp_dir + "model.sbml") File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\cnapy\gui_elements\main_window.py", line 1360, in save_sbml cobra.io.write_sbml_model( File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\cobra\io\sbml.py", line 1171, in write_sbml_model doc = _model_to_sbml(cobra_model, f_replace=f_replace, **kwargs) File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\cobra\io\sbml.py", line 1353, in _model_to_sbml reaction_coefficients = linear_reaction_coefficients(cobra_model) File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\cobra\util\solver.py", line 100, in linear_reaction_coefficients forward_coefficient = coefficients.get(rxn.forward_variable, 0) File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\cobra\core\reaction.py", line 190, in forward_variable return self.model.variables[self.id] File "C:\Users\mre283\Documents\CNApy\CNApy\miniconda\envs\cnapy-1.1.9\lib\site-packages\optlang\container.py", line 84, in __getitem__ return self._dict[item] # Treat item as key (name) KeyError: 'NAD '
It is also not possible to export the model to SBML to be able to save my progress in another way.
Best, Maaike