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

Need all chromatograms in particular sample #688

Open
13479776 opened this issue Sep 17, 2023 · 1 comment
Open

Need all chromatograms in particular sample #688

13479776 opened this issue Sep 17, 2023 · 1 comment

Comments

@13479776
Copy link

13479776 commented Sep 17, 2023

Dear Sir or madam,

I would like to require if it possible to get the feature chromatograms of different samples based on the intensity . Is it to use the chromatograms function for this task? For example, if a feature peak is strongest in a particular sample, obtain the chromatogram of that feature peak in this sample.

Thanks

best wish,
hees

@jorainer
Copy link
Collaborator

A single function that you could use is featureChromatograms, but that will extract you a chromatogram for every feature in every sample.

if you want to get the chromatogram with the highest signal for each feature, you would need to loop over the features (not sure if the code below works, did not try, but it's to give you an idea how it could be done):

## Get the feature definitions
fdef <- featureDefinitions(xdata)
cpks <- chromPeaks(xdata)

## Get the index (within the chromPeak matrix) of the peak with the highest intensity (using
## "maxo" for that, but could also use "into" instead.
idx <- vapply(fdef$peakidx, function(x) {
    i <- which.max(cpks[x, "maxo"])
    x[i]
}, integer(1))

## Extracting the chromatograms. Need to subset to the respective sample and then
## use the chromatogram call with the m/z and retention time range of the selected
## chromatographic peak
chrs <- lapply(idx, function(i) {
    pk <- cpks[i, , drop = FALSE]
    tmp <- filterFile(xdata, pk[1, "sample"])
    ## maybe expand the rt width a bit
    pk[, "rtmin"] <- pk[, "rtmin"] - 2
    pk[, "rtmax"] <- pk[, "rtmax"] + 2
    chromatogram(tmp, mz = pk[, c("mzmin", "mzmax")], rt = pk[, c("rtmin", "rtmax")])
})

chrs should then be a list of individual MChromatogram objects, each representing the EIC of the peak with the highest intensity for a feature in that sample.

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