Skip to content
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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Remove losses #321

wants to merge 6 commits into from

Conversation

florian-huber
Copy link
Collaborator

@florian-huber florian-huber commented Feb 16, 2022

  • Storing losses as part of spectrum seems a waste of resources (given how quick it is to compute).
  • But: This will break pipelines that use spectrum.losses

@florian-huber florian-huber linked an issue Feb 16, 2022 that may be closed by this pull request
@sonarcloud
Copy link

sonarcloud bot commented Feb 17, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Comment on lines +207 to +222
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
Copy link
Collaborator

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.

Copy link
Collaborator

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

@hechth
Copy link
Collaborator

hechth commented Apr 18, 2023

@niekdejonge maybe you could give some input on this? This has been open for a while but I think it is still relevant.

@niekdejonge
Copy link
Collaborator

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No longer store losses but compute on the fly
3 participants