rickhelmus / patRoon

Workflow solutions for mass-spectrometry based non-target analysis.
https://rickhelmus.github.io/patRoon/
GNU General Public License v3.0
61 stars 18 forks source link

Does compare/consensus on feature groups only work for fGroups based on the exact same data files (anaInfo)? #90

Closed bhc928 closed 9 months ago

bhc928 commented 1 year ago

Hi there,

I am trying to merge three feature groups using the comparison() and consensus() functions. However, I keep getting the error: "Error in .local(obj, ...) : This function only works with feature groups with equal analyses".

Each of my fGroups have 12 data files associated with them (as I understand it, these are the "analyses" the error refers to). I have 3 treatments (12 files each) that I have processed separately to simplify the filtering by sub-treatments (replicate groups specified in PatRoon "anaInfo$group") within a treatment.

So then does consensus() only work for fGroups originating from the exact same data files (but processed using different algorithms)? Or is there a way to merge "unrelated" fGroups - I'm thinking kind of like the "makeSet" function for POS and NEG mode runs (but with Treatment1, Treatment2, etc.)? Could I potentially "trick" R by renaming my anaInfo so that it matches between treatments and then create an anaInfo$Treatment column for clarity (or is the problem still that all columns in anaInfo must match perfectly)?

Thanks for your help and clarifications, Cleo

rickhelmus commented 1 year ago

Hi Cleo,

The consensus functionality was primarily developed to compare feature groups from different algorithms. In such a case restricting the analyses doesn't have to be limitation, and it made the implementation easier.

If I understand your use case it's actually more like concatenating different feature groups together. While I agree this is a nice to have, it is currently not possible. However, in my experience it's usually possible to work the other way around: first generate feature data for all your analyses, and then subset to divide the data as wanted. This also makes it easier to apply a general pre-processing (eg filters) in advance for all the subsets. Furthermore, you can always 'go back' to the original fGroups to compare things as the feature group names are constant with each subset and their parent.

If you really want to do this right now, it might be possible to do it via XCMS. I think it's possible to concatenate XCMS objects, so you could export your patRoon fGroups objects to XCMS objects, concatenate there and re-import. But I have no experience with this, and I'm not even sure if this will work and what limitations you may run into.

Thanks, Rick

bhc928 commented 1 year ago

Hi Rick,

Thanks for the suggestion. I have actually been playing around today and discovered that makeSet appears to work for fGroups based on different filenames and polarity modes (but with the same chromatographic method). I.e., I created fLists and fGroups for my 3 treatments (T1, T2, T3) and 2 polarities (POS/NEG), filtered the fGroups independently according to various rules (my original goal), then used makeSet to combine all six fGroups into one fGroupSet:

fGroupSet <- makeSet(fGroupsT1POS, fGroupsT2POS, fGroupsT3POS, fGroupsT1NEG, fGroupsT2NEG, fGroupsT3NEG, groupAlgo="openms", labels=c("T1_POS", "T2_POS", "T3_POS", "T1_NEG", "T2_NEG", "T3_NEG"), adducts=c("[M+H]+", "[M+H]+", "[M+H]+", "[M-H]-", "[M-H]-", "[M-H]-"))

The sum of feature groups from the original fGroups was 298 and the number of feature groups in fGroupSet is 289 - the loss of 9 makes sense when I use plotVenn to view the overlap between fGroups within the set, as there are 9 "overlaps". So as far as I can tell, this has worked!

I haven't quite finished my workflow and testing all of the further annotation steps, but so far this appears to work and I haven't found any issues (in case it helps others or demonstrates glaring errors/misunderstanding on my part...).

Cheers, Cleo

rickhelmus commented 1 year ago

Hi Cleo,

Yeah I guess the sets functionality can be tricked a little bit for this ... ;-) I do think you will get funny results when doing tha annotation, as all the sets with the same polarity will still be annotated separately (but obviously result in very similar output). Just something to be aware of. I'm now getting curious about how that will work out, so keep me updated :-)

Thanks, Rick

bhc928 commented 1 year ago

Hi Rick,

Yes, unfortunately I have no experience with annotation before now, so am kind of wading my way through and don't know what is normal, which makes things tricky... But I am also not necessarily sure that I expect different sets of the same polarity (in my case, different treatments) to have similar annotations?

However, I did run into two issues during the subsequent fGroupSet annotation steps:

  1. Compound annotations with the "library" search did not work (although they do work using the "metfrag" algorithm). The library search appeared to run ok, without errors, but resulted in 0 feature annotations (and I know I definitely had some hits when I ran the same treatment batches independently before).

e.g., compounds_library <- generateCompounds(fGroupSet, mslists, "library", MSLibrary=mslibrary, minSim=0.75, absMzDev=0.002)

Processing 50 feature groups with a library of 67032 records...

========================================================================| 100%

Loaded 0 compounds from 0 features (0.00%).

  1. I get the same report() error every time (I have tried modifying the "report.yml" file, but to no avail), but I am fairly certain this has been a problem with independent treatment fGroup batches as well, so is unlikely the fault of the fGroupSet. However, the legacy reportHTML() function does work in its place.

Legacy report = functioning

reportHTML(fGroupAnnotate, MSPeakLists=mslists, formulas=formulas, compounds=compounds, components=components, selfContained=FALSE, openReport=TRUE)

New report interface = not functioning

report(fGroupAnnotate, MSPeakLists=mslists, formulas=formulas, compounds=compounds, components=components, openReport=TRUE)

Loading all EICs... Verifying if your data is centroided... Done! Done!

Genarate summary plots... Done!

Generate large chromatograms...

|=======================================================================| 100%

Generate small chromatograms...

|=======================================================================| 100%

Generate structures...

|=======================================================================| 100%

Generate MS spectra...

|=======================================================================| 100%

Generate formula annotation plots...

|=======================================================================| 100%

Generate compound annotation plots...

|=======================================================================| 100%

Generate component plots...

|=======================================================================| 100%

Generating report parts: Feature groups...

Quitting from lines 38-336 [unnamed-chunk-8] (./details.Rmd)

Quitting from lines NA-336 [unnamed-chunk-3] (./details.Rmd)

Error in if (nidl <= 2) ...:

! missing value where TRUE/FALSE needed

Backtrace:

  1. bslib::layout_column_wrap(...)
    1. utils$genFGTableSuspects()
    2. patRoon:::makeFGReactable(...)
    3. patRoon:::makeReactable(...)
    4. reactable::reactable(...) ...
    5. reactable (local) FUN(X[[i]], ...)
    6. reactable:::callFunc(cell, value, index, key)
    7. patRoon (local) <fn>(NAcharacter)
    8. htmltools::span(...)
    9. rlang::dots_list(...)

I hope this helps you (or others in future) understand what is going on. For now, I think I will revert back to independent batches to focus on and better understand the annotation steps, before returning to the makeSets approach.

Many thanks again, Cleo

rickhelmus commented 1 year ago

Hi Cleo,

Thanks for the feedback again!

I tried to replicate your issues, but could only do so for your second issue. This was related to having >2 sets, which I never really got around to test much (but should work nonetheless). Anyway, this bug should now be fixed if you update patRoon.

For the library: maybe you can reprocess everything with a clean cache. I don't expect the issues were related, but who knows... Otherwise, which library were you using? I just loaded the last .msp from massbank.eu and all went fine.

Thanks, Rick

rickhelmus commented 9 months ago

Closed due to inactivity, feel free to re-open if needed!