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

Add new extractByIndex method #332

Merged
merged 3 commits into from
Sep 27, 2024
Merged

Add new extractByIndex method #332

merged 3 commits into from
Sep 27, 2024

Conversation

jorainer
Copy link
Member

This PR adds a new generic and method extractByIndex() to subset/extract data from a MsBackend given integer indices. Properties:

  • [ method calls extractByIndex(), converting first parameter i to an integer.
  • analysis methods for Spectra use now extractByIndex() to subset the backend instead of [:

Disadvantage:

  • each MsBackend implementation must implement this method now. So, I'll need to fix the other backend classes/packages accordingly.

Open to discussion.

- Add an `extractByIndex()` method to subset/extract content from a
  `MsBackend`. Using this method in contrast to `[` avoids errors with some
  parallel processing setups in which a `[` method for a backend might not be
  found (see
  rformassspectrometry/MsBackendMetaboLights#5).
@jorainer
Copy link
Member Author

Update: just added a backward compatibility that fails back to use [ if extractByIndex() is not implemented for a backend.

Below we implement a possible `[` for our test backend class. We ignore the
parameters `j` from the definition of the `[` generic, since we treat our data
to be one-dimensional (with each spectrum being one element).
The `extractByIndex()` method is used by the data operation and analysis methods
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just so I understand, from now on when we need to implement some code in Spectra we have to use extractByIndex() instead of [ ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use both - but it would be better to use extractByIndex.

Copy link
Collaborator

@philouail philouail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, a bit annoying you had to get to such a big change to fix something like that ! Thanks for figuring it out ! I have one question in comment.

Did you get any answer from the S4Vectors issue you made ?

@jorainer jorainer merged commit 1bb1a1d into main Sep 27, 2024
3 checks passed
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.

2 participants