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

filterPolarity #388

Closed
zeehio opened this issue Dec 10, 2018 · 3 comments
Closed

filterPolarity #388

zeehio opened this issue Dec 10, 2018 · 3 comments

Comments

@zeehio
Copy link

zeehio commented Dec 10, 2018

Thank you for your time and efforts on this package.

My apologies if I am overlooking something obvious (I am a newcomer here). If that is the case, feel free to tell me and I will close the issue.

I found out I needed a filterPolarity function and I wonder if it would be worth including a filterPolarity function in your MSnbase package. Here is my use case and a demo implementation:

Without polarity filtering

Loading a single sample and plotting a region, without filterPolarity, both polarities appear mixed:

# My apologies, I don't have permissions to submit data right now :-S
MSnbase::readMSData("1.mzXML") %>%
  MSnbase::filterRt(rt = c(500, 520)) %>%
  MSnbase::filterMz(mz = c(300, 400)) %>%
  MSnbase::plot(type = "XIC")

imatge

With polarity filtering

Based on MSnbase::filterMsLevel I wrote this filterPolarity function.

filterPolarity <- function(object, polarity.) {
  if (missing(polarity.)) return(object)
  polarity. <- as.numeric(polarity.)
  object[MSnbase::polarity(object) %in% polarity.]
}

Filtering the polarity I can easily see the positive and negative polarities:

MSnbase::readMSData("1.mzXML") %>%
  filterPolarity(polarity. = 1) %>%
  MSnbase::filterRt(rt = c(500, 520)) %>%
  MSnbase::filterMz(mz = c(300, 400)) %>%
  MSnbase::plot(type = "XIC")

imatge

MSnbase::readMSData("1.mzXML") %>%
  filterPolarity(polarity. = 0) %>%
  MSnbase::filterRt(rt = c(500, 520)) %>%
  MSnbase::filterMz(mz = c(300, 400)) %>%
  MSnbase::plot(type = "XIC")

imatge

Is there a reason why there is not a filterPolarity function in MSnbase? I feel I am missing something obvious, but I'd rather ask just in case...

Thanks

@lgatto
Copy link
Owner

lgatto commented Dec 10, 2018

Thank you for your report @zeehio. Firstly, I suppose we should indeed add a function filterPolarity.

I will let @jotsetung also chime in, put I spotted an issue in your function (which might be a false positive though):

filterPolarity <- function(object, polarity.) {
  if (missing(polarity.)) return(object)
  polarity. <- as.numeric(polarity.)
  object[MSnbase::polarity(dataset_not_dia) %in% polarity.] ## should be object, rather than dataset_no_dia
}

Could you confirm if that's the reason for the lack of effective filtering, or if it's only a typo.

@zeehio
Copy link
Author

zeehio commented Dec 10, 2018

That dataset_not_dia should have been object, it was a copy-paste error on my side. Thanks for spotting it, I have updated the code above fixing it.

On my own code filterPolarity was working fine and the results match my expectations. I would contribute a pull request but I am just starting to get familiar with all those Bioconductor methods...

@lgatto lgatto closed this as completed in ac0028b Dec 10, 2018
@lgatto
Copy link
Owner

lgatto commented Dec 10, 2018

I have added the method to MSnbase - only on github for now. And thank you for feature request.

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

No branches or pull requests

2 participants