-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check annotation to be of type dict while reading it from the json #930
Conversation
@cdiener , I have implemented the needs for annotations format that were discussed on issue:736. I have also added the test cases to test the parsing. However, a few other tests are now producing error. One of them is: cobra/test/test_io/test_sbml.py. It has a test_read_2 test which compares models from two files. For eg: it compares models mini.pickle and mini_fbc2.xml using the function extra_comparisons() of same file. However, while comparing data from two files, the following error occurs :
Here as you can see, the two annotation lists are different (one is empty and other is ['sbo', 'bigg.reaction']) from the two models and hence a false assert is produced which fails the test. I tried to look into the corresponding models (mini.pickle and mini_fbc2.xml). I parsed the pickle into json but there is no annotation list, and there is one in mini_fbc2.xml file. Can you help me a little to understand why it is happening? |
Sure, I'll have a look during the week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I currently don't have a good overview of where we use direct assignment to the annotation
attribute. Overall, I think it would be cleaner to add a method that hides the internal data structure. Something like
def add_annotation(self, namespace: str, identifier: str, biology_qualifier="is"):
but as I said I don't know how much code would be affected by this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. At least some of the test failures come from pickled test models with annotation == None
. Don't know where exactly that arises but for now you could try to rebuild the pickles as described in https://github.com/opencobra/cobrapy/blob/devel/.github/CONTRIBUTING.rst#faqs .
Thanks Sir for looking into the matter. The error occurring here is due to the changes I made in Object class for annotation. I haven't repickled the models after modifying the Object class, that's why it is giving the annotation list as an empty list. So I tried to repickle the models using the modified Object class using the update_pickles.py file, but I think this file is outdated, and it throws the following error:
Am I missing something or is it really outdated? |
Yeah, most likely outdated. It only really gets updated when someone needs to run it, like you do now 😉 |
Ok. Let me guess, what we will have to change in it is somewhat like this :
But even here also, it is not in any actual use. In the first test i.e
it gets skipped due to no provided validation_function for it. And similarly for further test cases also, it is either marked as 'pytest.xfail('not supported')' or skipped. So it is not actually used anywhere.
|
Codecov Report
@@ Coverage Diff @@
## devel #930 +/- ##
==========================================
+ Coverage 84.44% 84.63% +0.18%
==========================================
Files 50 50
Lines 4353 4438 +85
Branches 996 998 +2
==========================================
+ Hits 3676 3756 +80
- Misses 433 441 +8
+ Partials 244 241 -3
Continue to review full report at Codecov.
|
Sir, I have updated update_pickle.py file as per the changes discussed above. About the third error which I mentioned, I have removed the reaction 'D__LACt2pp' from model iJO1366 and have updated the pickle and other resource files using the updated Object class. Changes suggested by @Midnighter have also been done. There was one test case that was failing i.e test_validate inside test_sbml.py (line 277) file. It was asking for 23 errors when validation is performed over mini_fbc3.xml resource model, but there were no errors generated after I have modified the Object class. |
@cdiener , @Midnighter do you suggest some changes or is it fine? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Hemant27031999, sorry for the long wait on this one. I have a few minor comments, otherwise this PR looks good to me.
@Midnighter, I have made the changes. Please review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your work!
Let me know @cdiener when you're happy, too. I can merge it then and make a new release. |
I'm on board if it looks good to you. Seems like CI is failing again due to unsorted imports. |
What does it fixes:
The current version of code throws an error at the time of writing model in SBML format if annotations are of type list of lists. The JSON schema wants annotations to be of dictionary type, but the validation check of JSON is not performed using the schema because it will make the parsing slow. So I have updated cobra/io/object.py class by adding setter for annotation which checks if the annotation is of type dictionary or not at the time reading model from the JSON and throws a TypeError if it is not.
Files changed/added: