add pandas df conversion#5622
Conversation
jpfeuffer
left a comment
There was a problem hiding this comment.
Cool! A few changes would be nice.
And have a look at CodeFactor.
| from . import Plotting as Plot | ||
|
|
||
| try: | ||
| from .Dataframes import ConsensusMap, FeatureMap, MSExperiment, DFConverter |
There was a problem hiding this comment.
To be honest, I don't think we should import this subpackage by default.
OpenMS/src/pyOpenMS/pyopenms/__init__.py
Line 59 in 0a9f260
IMHO users should do from pyopenms import Dataframes if they want that functionality, and only then it should try to import pandas.
There was a problem hiding this comment.
I have no idea though if we would need to hide core classes under a separate subnamespace (E.g. core) or what happens if you do from pyopenms import *.
Needs to be tested.
There was a problem hiding this comment.
Maybe also namespaces should be lowercase? So you don't confuse with classes?
There was a problem hiding this comment.
To be honest, I don't think we should import this subpackage by default.
OpenMS/src/pyOpenMS/pyopenms/__init__.py
Line 59 in 0a9f260
IMHO users should do
from pyopenms import Dataframesif they want that functionality, and only then it should try to import pandas.
Hmm what would be the downside if we make pandas a requirement for pyOpenMS and by default include the Dataframes as Axel did?
There was a problem hiding this comment.
I kind of would like to make this as easy as possible for the user
There was a problem hiding this comment.
Downside is that people always need pandas.
And it would need to go into the setup.py
There was a problem hiding this comment.
I am in the camp of "batteries included" and we already require numpy, so I think requiring pandas is not that big of a step.
There was a problem hiding this comment.
OK. Fine with me. I guess then we can leave those imports and just need to add it to setup.py.
And install it on the build slaves.
| b'score_fit': 'f', | ||
| b'score_correlation': 'f', | ||
| b'FWHM': 'f', | ||
| b'spectrum_native_id': 'U30', |
hroest
left a comment
There was a problem hiding this comment.
Can you please add tests for this new functionality?
|
@hroest Regarding tests, when should we load pandas? What is your opinion? E.g.:
|
|
If its required to run the tests, then I would say we should check in cmake. |
|
What is your opinion if someone takes a shortcut and does testing via the jupyter notebooks? At least I had the impression that people are more willing to write tests by creating an example in the readthedocs page. It now get's automatically tested. i.e., we get a good test coverage. Of course, the "right thing to do" is to do unit testing in the OpenMS repo. |
do we check that these still work with every change in OpenMS? I see that happening with the documentation that requires updating for a new release... |
|
No I think Julianus added that it only tests the changed notebooks. Initially it tested all of manually triggered or at least one notebook changed |
|
@jpfeuffer would or make sense to regularly test all e.g. nightly? |
|
Sure, just send a workflow dispatch trigger from the pyopenms builds to the "push action" of the binder branch. |
and create a new action for considering all files? |
|
It's there already. Just never gets triggered. See issues. |
|
But to be honest, since you have to add pandas in OpenMS now anyway, we can also just add a one liner to the tests to at least see that it works. |
|
so how would that look like: |
|
Yes but currently pyopenms only runs on pushes to nightly. |
sure it is the better way to do it. still would be great to include the new documentation and example notebooks into the testing (e.g. only nightly) |
|
Problem is that pyopenms builds take 3.5 hours. |
|
Hmm wasn't enough. |
|
Feel free to add tests now. @timosachsenberg @axelwalter |
|
I think we can add code from the pyOpenMS examples on the readthedocs page here that also tests writing and reading of files as well as conversion of the resulting maps to pandas: for featureXML |
|
I will work on a readthedocs tutorial and add the examples as test cases. |
|
Hmm but wouldn't it be better to have it merged first with a very basic test? |
|
yep I agree.e.g. just adding one or two features and then test the df shape |
|
I added quite some Todos that should be addressed in the future, in addition to an idXML test. But from my side we could merge it after CI. |
timosachsenberg
left a comment
There was a problem hiding this comment.
Feel free to merge if tests pass
|
Still need to fix handling missing values in meta values. |
| switchDict = {bool: '?', int: 'i', float: 'f', str: 'U100'} | ||
|
|
||
| # filter out PeptideIdentifications without PeptideHits if export_unidentified == False | ||
| if not export_unidentified: |
There was a problem hiding this comment.
Thanks for taking my suggestion, however, I would do it during the main iteration.
In C++ this would be fine, but in python this will do copies of each PeptideID.
I make a comment on where I would add it.
EDIT: Ah you might need the count, right? Maybe just use this pre-iteration for the count then.
EDIT2: Hmm maybe does not matter. Since we do not have a count function, we need to copy anyway.
There was a problem hiding this comment.
First I put it in the main iteration (line 302), however, returning None (when there are no peptide hits and export_unidentified == False) does not work with np.fromiter(). Therefore I filtered them out in advance.
There was a problem hiding this comment.
In this case, I would just "continue" the loop without yielding, but I think we can leave it for now. Maybe add a TODO.
There was a problem hiding this comment.
Sorry, I might have gotten it wrong. Yes we would need to think about it.
There was a problem hiding this comment.
Ok. Is it possible to continue here since we pass only one PeptideIdentification at a time and it is not really a loop?
There was a problem hiding this comment.
I just checked and yes you can just do "return" without argument.
There was a problem hiding this comment.
Not sure if the iteration for counting is worth it, but we have to benchmark.
|
woohhoo! |
|
I think peptide evidences are not exported (e.g, the protein accessions and start, end in the protein) |
Description
Add conversion for FeatureMap, ConsensusMap, MSExperiment and list of PeptideIdentification.
Checklist:
How can I get additional information on failed tests during CI:
If your PR is failing you can check out
Note: