Trouble plotting XChromatograms
JasonBason opened this issue · comments
Hello,
I am trying to plot extracted ion chromatograms from a pre-processed XcmsExperiment object "xdata". The output of this object looks like this:
Object of class XcmsExperiment
Spectra: MS1 (116921)
Experiment data: 120 sample(s)
Sample data links:
- spectra: 120 sample(s) to 116921 element(s).
xcms results: - chromatographic peaks: 689768 in MS level(s): 1
- correspondence results: 11444 features in MS level(s): 1
As a test to see if I can plot the first feature, I made an "XChromatograms" object, and tried to plot it:
chrs <- featureChromatograms(xdata,
features = 1)
plot(chrs)
This gives me the following error (specifically when I attempt to plot:
Error in FUN(X[[i]], ...) :
invalid class "XChromatogram" object: column "ms_level" should only contain integer values
This is the traceback:
13: stop(msg, ": ", errors, domain = NA)
12: FUN(X[[i]], ...)
11: lapply(object, validObject)
10: validityMethod(object)
9: isTRUE(x)
8: anyStrings(validityMethod(object))
7: validObject(x)
6: .local(x, i, j, ..., drop)
5: x[i, , drop = FALSE]
4: x[i, , drop = FALSE]
3: .local(x, ...)
2: plot(chrs)
1: plot(chrs)
This object only contains MS1 data, so this has me a little confused.
I have no problem plotting the feature chromatograms from the test data provided in the examples of the featureChromatograms function:
# load in test data
faahko_sub <- loadXcmsData("faahko_sub2")
# group data
xdata_test <- groupChromPeaks(faahko_sub,
param = PeakDensityParam(minFraction = 0.8,
sampleGroups = rep(1,3)))
# get an Xchromatograms object for the first feature
chrs <- featureChromatograms(xdata_test,
features = 1)
# plotting is successful
plot(chrs, col = c("red", "green", "blue"))
Any help would be appreciated!
Here is my session info:
R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8
time zone: America/New_York
tzcode source: internal
attached base packages:
[1] parallel stats4 stats graphics grDevices utils datasets
[8] methods base
other attached packages:
[1] faahKO_1.42.0 MsFeatures_1.10.0 commonMZ_0.0.2
[4] CAMERA_1.56.0 RColorBrewer_1.1-3 Spectra_1.13.5
[7] tictoc_1.2 MsExperiment_1.5.4 xcms_4.1.9
[10] MSnbase_2.28.1 ProtGenerics_1.35.3 S4Vectors_0.40.2
[13] mzR_2.36.0 Rcpp_1.0.12 Biobase_2.62.0
[16] BiocGenerics_0.48.1 BiocParallel_1.36.0 lubridate_1.9.3
[19] forcats_1.0.0 stringr_1.5.1 purrr_1.0.2
[22] readr_2.1.5 tidyr_1.3.1 tibble_3.2.1
[25] ggplot2_3.5.0 tidyverse_2.0.0 readxl_1.4.3
[28] dplyr_1.1.4
loaded via a namespace (and not attached):
[1] splines_4.3.3 later_1.3.2
[3] bitops_1.0-7 cellranger_1.1.0
[5] preprocessCore_1.64.0 graph_1.78.0
[7] XML_3.99-0.16.1 rpart_4.1.23
[9] lifecycle_1.0.4 doParallel_1.0.17
[11] vroom_1.6.5 processx_3.8.3
[13] lattice_0.22-5 MASS_7.3-60.0.1
[15] MultiAssayExperiment_1.28.0 backports_1.4.1
[17] magrittr_2.0.3 limma_3.58.1
[19] Hmisc_5.1-1 rmarkdown_2.26
[21] remotes_2.4.2.1 httpuv_1.6.14
[23] sessioninfo_1.2.2 pkgbuild_1.4.3
[25] MsCoreUtils_1.15.4 DBI_1.2.2
[27] abind_1.4-5 pkgload_1.3.4
[29] zlibbioc_1.48.0 GenomicRanges_1.54.1
[31] AnnotationFilter_1.26.0 RCurl_1.98-1.14
[33] nnet_7.3-19 GenomeInfoDbData_1.2.11
[35] IRanges_2.36.0 ncdf4_1.22
[37] codetools_0.2-19 DelayedArray_0.28.0
[39] tidyselect_1.2.0 matrixStats_1.2.0
[41] base64enc_0.1-3 jsonlite_1.8.8
[43] multtest_2.58.0 ellipsis_0.3.2
[45] Formula_1.2-5 survival_3.5-8
[47] iterators_1.0.14 foreach_1.5.2
[49] tools_4.3.3 progress_1.2.3
[51] snow_0.4-4 glue_1.7.0
[53] gridExtra_2.3 SparseArray_1.2.4
[55] xfun_0.42 MatrixGenerics_1.14.0
[57] usethis_2.2.3 GenomeInfoDb_1.38.7
[59] withr_3.0.0 BiocManager_1.30.22
[61] fastmap_1.1.1 fansi_1.0.6
[63] callr_3.7.5 digest_0.6.34
[65] timechange_0.3.0 R6_2.5.1
[67] mime_0.12 colorspace_2.1-0
[69] utf8_1.2.4 generics_0.1.3
[71] data.table_1.15.2 robustbase_0.99-2
[73] prettyunits_1.2.0 htmlwidgets_1.6.4
[75] S4Arrays_1.2.1 pkgconfig_2.0.3
[77] gtable_0.3.4 impute_1.76.0
[79] MassSpecWavelet_1.68.0 XVector_0.42.0
[81] htmltools_0.5.7 profvis_0.3.8
[83] RBGL_1.76.0 MALDIquant_1.22.2
[85] clue_0.3-65 scales_1.3.0
[87] knitr_1.45 MetaboCoreUtils_1.11.2
[89] rstudioapi_0.15.0 tzdb_0.4.0
[91] checkmate_2.3.1 curl_5.2.1
[93] cachem_1.0.8 miniUI_0.1.1.1
[95] foreign_0.8-86 mzID_1.40.0
[97] vsn_3.70.0 desc_1.4.3
[99] pillar_1.9.0 grid_4.3.3
[101] vctrs_0.6.5 RANN_2.6.1
[103] pcaMethods_1.94.0 urlchecker_1.0.1
[105] promises_1.2.1 xtable_1.8-4
[107] cluster_2.1.6 htmlTable_2.4.2
[109] evaluate_0.23 cli_3.6.2
[111] compiler_4.3.3 rlang_1.1.3
[113] crayon_1.5.2 QFeatures_1.13.2
[115] ps_1.7.6 affy_1.80.0
[117] plyr_1.8.9 fs_1.6.3
[119] stringi_1.8.3 munsell_0.5.0
[121] lazyeval_0.2.2 devtools_2.4.5
[123] Matrix_1.6-5 hms_1.1.3
[125] bit64_4.0.5 statmod_1.5.0
[127] shiny_1.8.0 highr_0.10
[129] SummarizedExperiment_1.32.0 igraph_2.0.2
[131] memoise_2.0.1 affyio_1.72.0
[133] bit_4.0.5 DEoptimR_1.1-3
This error was fixed with xcms
version 4.1.4 - so it's a bit strange that you still get it. Can you please verify what type the column "ms_level"
in your object's featureDefinitions
is? It should be an integer, as shown below.
> class(featureDefinitions(xdata_test)$ms_level)
[1] "integer"
>
If it's not, can you convert to integer
and try again?
featureDefinitions(xdata_test)$ms_level <- as.integer(featureDefinitions(xdata_test)$ms_level)
When I run
class(featureDefinitions(xdata)$ms_level)
I do get "integer"
However, when I run:
class(chrs[[1]]@chromPeakData@listData$ms_level)
This gives me "numeric"
I can change this nested ms_level parameter to integer:
chrs[[1]]@chromPeakData@listData$ms_level <- as.integer(chrs[[1]]@chromPeakData@listData$ms_level)
Then I can plot a single chromatogram that is filled in, with no errors:
However, if I try to plot a different XChromatogram, the plot is successful, but I get an error in the console, and the plot is not filled in:
plot(chrs[[5]])
Error in validObject(object) :
invalid class "XChromatogram" object: column "ms_level" should only contain integer values
did you create the chrs
object with an older xcms version (and export/import from RData) or was this object created with xcms version 4.1.9?
Hey Jorainer,
You were right! I ran the preprocessing again, and now I can plot the Xchromatograms.
Thank you!!
Great! thanks for reporting back. I'll close the issue now - feel free to re-open if needed.