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

Simplify cosine computation #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

hubernhard
Copy link

@hubernhard hubernhard commented Jan 27, 2022

Hi Nicolas,

while going through your code, I noticed that the cosine computation in _compare_spectra() can be simplified, as the if dm == 0. statement is not needed since all possible cases are already handled in the else part:

if dm == 0.:
for i in range(spectrum1_data.shape[0]):
for j in range(spectrum2_data.shape[0]):
diff = spectrum2_data[j, MZ] - spectrum1_data[i, MZ]
if abs(diff) <= mz_tolerance:
scores.append((spectrum1_data[i, INTENSITY] * spectrum2_data[j, INTENSITY], i, j, SpectraMatchState.fragment))
else:
for i in range(spectrum1_data.shape[0]):
for j in range(spectrum2_data.shape[0]):
diff = spectrum2_data[j, MZ] - spectrum1_data[i, MZ]
if abs(diff) <= mz_tolerance:
scores.append((spectrum1_data[i, INTENSITY] * spectrum2_data[j, INTENSITY], i, j, SpectraMatchState.fragment))
elif abs(diff + dm) <= mz_tolerance:
scores.append((spectrum1_data[i, INTENSITY] * spectrum2_data[j, INTENSITY], i, j, SpectraMatchState.neutral_loss))

And as it took me some time to figure out how the neutral loss computation actually works, I added a commet that explains the derivation in more detail.

And by the way, thank you for your work on MetGem! It really helps a lot.

Best regards,
Bernhard

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.

None yet

1 participant