-
Notifications
You must be signed in to change notification settings - Fork 57
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
Remove losses #321
base: master
Are you sure you want to change the base?
Remove losses #321
Conversation
Kudos, SonarCloud Quality Gate passed! |
def losses(self, loss_mz_from, loss_mz_to) -> Optional[Fragments]: | ||
precursor_mz = self.get("precursor_mz", None) | ||
if precursor_mz: | ||
assert isinstance(precursor_mz, (float, int)), ("Expected 'precursor_mz' to be a scalar number.", | ||
"Consider applying 'add_precursor_mz' filter first.") | ||
peaks_mz, peaks_intensities = self.peaks.mz, self.peaks.intensities | ||
losses_mz = (precursor_mz - peaks_mz)[::-1] | ||
losses_intensities = peaks_intensities[::-1] | ||
# Add losses which are within given boundaries | ||
mask = np.where((losses_mz >= loss_mz_from) | ||
& (losses_mz <= loss_mz_to)) | ||
losses = Fragments(mz=losses_mz[mask], | ||
intensities=losses_intensities[mask]) | ||
return losses | ||
logger.warning("No precursor_mz found. Consider applying 'add_precursor_mz' filter first.") | ||
return None |
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.
Is it possible in python to have a property that is in fact a proper function? This way, the compatibility with the spectrum.losses
pipelines would be retained.
I'm not sure on how to incorporate the filtering here though.
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.
That seems like a nice solution
@niekdejonge maybe you could give some input on this? This has been open for a while but I think it is still relevant. |
@hechth @florian-huber I agree with both points, it makes sense to remove this and make this a function. But it will indeed also break functionality of Spec2Vec and MS2Query. For MS2Query this is not directly a problem, since it is set to Matchms 0.13.0 anyway, so we can make this switch when upgrading to matchms >0.18.0. |
spectrum.losses