├── .Rbuildignore ├── .github └── workflows │ ├── codecov.yml │ ├── r.yaml │ └── rhub.yaml ├── .gitignore ├── CRAN-RELEASE ├── CRAN-SUBMISSION ├── ChangeLog ├── DESCRIPTION ├── Dockerfile ├── LICENSE ├── NAMESPACE ├── R ├── RCQC.R ├── calculate.similarity.R ├── defineExperiment.R ├── do.findmain.R ├── exportDataset.R ├── findfeature.R ├── findmass.R ├── getData.R ├── mergeRCobjects.R ├── ramclustR.R ├── rc.calibrate.ri.R ├── rc.cmpd.cv.filter.R ├── rc.cmpd.filter.blanks.R ├── rc.cmpd.replace.na.R ├── rc.expand.sample.names.R ├── rc.export.msp.rc.R ├── rc.feature.filter.blanks.R ├── rc.feature.filter.cv.R ├── rc.feature.normalize.batch.qc.R ├── rc.feature.normalize.qc.R ├── rc.feature.normalize.quantile.R ├── rc.feature.normalize.tic.R ├── rc.feature.replace.na.R ├── rc.get.csv.data.R ├── rc.get.df.data.R ├── rc.get.xmcs.data.R ├── rc.merge.clusters.R ├── rc.qc.R ├── rc.ramclustr.R ├── rc.remove.qc.R ├── rc.restore.qc.samples.R ├── write.gcei.mat.R ├── write.methods.R └── write.msp.R ├── README.md ├── conda ├── environment-dev.yaml └── environment-test.yaml ├── cran-comments.md ├── docker-compose.yml ├── docs └── ramclustR.png ├── inst ├── extdata │ ├── featDefinition.rds │ ├── featValues.rds │ ├── peaks.csv │ ├── phenoData.csv │ └── phenoData_df.rds ├── params │ ├── defparamsets.Rdata │ ├── greek.csv │ ├── params.csv │ └── paramsets.Rdata └── references.txt ├── man ├── RCQC.Rd ├── add_params.Rd ├── check_arguments_filter.blanks.Rd ├── check_arguments_filter.cv.Rd ├── check_arguments_replace.na.Rd ├── checks.Rd ├── compute_SpecAbundAve.Rd ├── compute_do.sets.Rd ├── compute_wt_mean.Rd ├── create_ramclustObj.Rd ├── defineExperiment.Rd ├── define_samples.Rd ├── do.findmain.Rd ├── exportDataset.Rd ├── filter_blanks.Rd ├── filter_good_features.Rd ├── filter_signal.Rd ├── find_good_features.Rd ├── findfeature.Rd ├── findmass.Rd ├── getData.Rd ├── getSampleMetadata.Rd ├── get_ExpDes.Rd ├── get_instrument_platform.Rd ├── mean_signal_intensities.Rd ├── mergeRCobjects.Rd ├── normalized_data_batch_qc.Rd ├── normalized_data_tic.Rd ├── order_datasets.Rd ├── ramclustR.Rd ├── rc.calibrate.ri.Rd ├── rc.cmpd.filter.blanks.Rd ├── rc.cmpd.filter.cv.Rd ├── rc.cmpd.replace.na.Rd ├── rc.expand.sample.names.Rd ├── rc.export.msp.rc.Rd ├── rc.feature.filter.blanks.Rd ├── rc.feature.filter.cv.Rd ├── rc.feature.normalize.batch.qc.Rd ├── rc.feature.normalize.qc.Rd ├── rc.feature.normalize.quantile.Rd ├── rc.feature.normalize.tic.Rd ├── rc.feature.replace.na.Rd ├── rc.get.csv.data.Rd ├── rc.get.df.data.Rd ├── rc.get.xcms.data.Rd ├── rc.merge.split.clusters.Rd ├── rc.qc.Rd ├── rc.ramclustr.Rd ├── rc.remove.qc.Rd ├── rc.restore.qc.samples.Rd ├── remove_blanks.Rd ├── replace_na.Rd ├── write.gcei.mat.Rd ├── write.methods.Rd ├── write.msp.Rd └── write_csv.Rd ├── tests ├── testthat.R └── testthat │ ├── helper.R │ ├── test-do.findmain.R │ ├── test-rc.calibrate.ri.R │ ├── test-rc.expand.sample.names.R │ ├── test-rc.feature.filter.blanks.R │ ├── test-rc.feature.filter.cv.R │ ├── test-rc.feature.normalize.batch.qc.R │ ├── test-rc.feature.normalize.qc.R │ ├── test-rc.feature.normalize.quantile.R │ ├── test-rc.feature.normalize.tic.R │ ├── test-rc.feature.replace.na.R │ ├── test-rc.get.csv.data.R │ ├── test-rc.get.df.data.R │ ├── test-rc.get.xcms.data.R │ ├── test-rc.qc.R │ ├── test-rc.ramclustr.R │ ├── test-rc.remove.qc.R │ ├── test-rc.restore.qc.samples.R │ ├── test-stepwise-workflow.R │ ├── test-workflow-comparison.R │ ├── test.R │ └── testdata │ ├── calibrant.data.csv │ ├── clustering │ ├── normal_rc.ramclustr.rds │ └── only_rt_rc.ramclustr.rds │ ├── do.findmain.rds │ ├── input.rc.calibrate.ri.rds │ ├── ms1_featureDefinitions.rds │ ├── ms1_featureValues.rds │ ├── output.msp │ ├── peaks.csv │ ├── phenoData.csv │ ├── phenoData_df.rds │ ├── rc.calibrate.ri.rds │ ├── rc.expand.sample.names.rds │ ├── rc.feature.filter.blanks.rds │ ├── rc.feature.filter.cv.rds │ ├── rc.feature.normalize.batch.qc.rds │ ├── rc.feature.normalize.qc.rds │ ├── rc.feature.normalize.quantile.rds │ ├── rc.feature.normalize.tic.rds │ ├── rc.feature.replace.na.rds │ ├── rc.get.csv.data.rds │ ├── rc.get.df.data.rds │ ├── rc.get.xcms.data.rds │ ├── rc.qc.rds │ ├── rc.remove.qc.rds │ ├── rc.restore.qc.samples.rds │ ├── test.fillpeaks │ ├── testMetadata.csv │ └── test_csv.rds └── vignettes ├── ExpDes.csv ├── RAMClustR.Rmd └── spectra └── test.mspLib /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^CRAN-RELEASE$ 2 | ^.*\.Rproj$ 3 | ^\.Rproj\.user$ 4 | cran-comments.md 5 | ^CRAN-SUBMISSION$ 6 | ^conda 7 | ^.vscode 8 | ^.github 9 | ^docs 10 | ^Dockerfile$ 11 | ^docker-compose.yml$ -------------------------------------------------------------------------------- /.github/workflows/codecov.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | name: R Conda (with codecov) 3 | 4 | # Controls when the workflow will run 5 | on: 6 | # Triggers the workflow on push or pull request events but only for the main branch 7 | push: 8 | branches: [ master, dev, release_1.3.x] 9 | pull_request: 10 | branches: [ master, dev, release_1.3.x ] 11 | 12 | # Allows you to run this workflow manually from the Actions tab 13 | workflow_dispatch: 14 | 15 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 16 | jobs: 17 | # This workflow contains a single job called "build" 18 | build: 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | os: [ ubuntu-latest, macos-latest, windows-latest] 23 | runs-on: ${{ matrix.os }} 24 | defaults: 25 | run: 26 | shell: bash -l {0} 27 | 28 | # Steps represent a sequence of tasks that will be executed as part of the job 29 | steps: 30 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 31 | - uses: actions/checkout@v4 32 | 33 | - name: Create conda environment 34 | uses: conda-incubator/setup-miniconda@v3 35 | with: 36 | auto-update-conda: true 37 | environment-file: conda/environment-test.yaml 38 | - run: | 39 | conda init bash 40 | conda env list 41 | 42 | - name: Test coverage 43 | run: | 44 | conda activate test 45 | Rscript -e "covr::codecov(quiet = FALSE)" 46 | -------------------------------------------------------------------------------- /.github/workflows/r.yaml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | # 6 | # See https://github.com/r-lib/actions/tree/master/examples#readme for 7 | # additional example workflows available for the R community. 8 | 9 | name: R 10 | 11 | on: 12 | push: 13 | branches: [ master, dev, release_1.3.x] 14 | pull_request: 15 | branches: [ master, dev, release_1.3.x ] 16 | workflow_dispatch: 17 | 18 | permissions: 19 | contents: read 20 | 21 | jobs: 22 | build: 23 | strategy: 24 | matrix: 25 | r-version: ['3.6.3', '4.1.1', '4.4.3'] 26 | os: [ ubuntu-latest, macos-latest, windows-latest] 27 | runs-on: ${{ matrix.os }} 28 | 29 | steps: 30 | - uses: actions/checkout@v4 31 | - name: Set up R ${{ matrix.r-version }} 32 | uses: r-lib/actions/setup-r@f57f1301a053485946083d7a45022b278929a78a 33 | with: 34 | r-version: ${{ matrix.r-version }} 35 | - name: Install dependencies 36 | run: | 37 | install.packages(c("remotes", "rcmdcheck")) 38 | remotes::install_deps(dependencies = TRUE) 39 | shell: Rscript {0} 40 | - name: Check 41 | run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error") 42 | shell: Rscript {0} 43 | - name: Run codecov 44 | run: | 45 | install.packages(c("covr")) 46 | covr::codecov(quiet = FALSE) 47 | shell: Rscript {0} 48 | -------------------------------------------------------------------------------- /.github/workflows/rhub.yaml: -------------------------------------------------------------------------------- 1 | # R-hub's generic GitHub Actions workflow file. It's canonical location is at 2 | # https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml 3 | # You can update this file to a newer version using the rhub2 package: 4 | # 5 | # rhub::rhub_setup() 6 | # 7 | # It is unlikely that you need to modify this file manually. 8 | 9 | name: R-hub 10 | run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}" 11 | 12 | on: 13 | workflow_dispatch: 14 | inputs: 15 | config: 16 | description: 'A comma separated list of R-hub platforms to use.' 17 | type: string 18 | default: 'linux,windows,macos' 19 | name: 20 | description: 'Run name. You can leave this empty now.' 21 | type: string 22 | id: 23 | description: 'Unique ID. You can leave this empty now.' 24 | type: string 25 | 26 | jobs: 27 | 28 | setup: 29 | runs-on: ubuntu-latest 30 | outputs: 31 | containers: ${{ steps.rhub-setup.outputs.containers }} 32 | platforms: ${{ steps.rhub-setup.outputs.platforms }} 33 | 34 | steps: 35 | # NO NEED TO CHECKOUT HERE 36 | - uses: r-hub/actions/setup@v1 37 | with: 38 | config: ${{ github.event.inputs.config }} 39 | id: rhub-setup 40 | 41 | linux-containers: 42 | needs: setup 43 | if: ${{ needs.setup.outputs.containers != '[]' }} 44 | runs-on: ubuntu-latest 45 | name: ${{ matrix.config.label }} 46 | strategy: 47 | fail-fast: false 48 | matrix: 49 | config: ${{ fromJson(needs.setup.outputs.containers) }} 50 | container: 51 | image: ${{ matrix.config.container }} 52 | 53 | steps: 54 | - uses: r-hub/actions/checkout@v1 55 | - uses: r-hub/actions/platform-info@v1 56 | with: 57 | token: ${{ secrets.RHUB_TOKEN }} 58 | job-config: ${{ matrix.config.job-config }} 59 | - uses: r-hub/actions/setup-deps@v1 60 | with: 61 | token: ${{ secrets.RHUB_TOKEN }} 62 | job-config: ${{ matrix.config.job-config }} 63 | - uses: r-hub/actions/run-check@v1 64 | with: 65 | token: ${{ secrets.RHUB_TOKEN }} 66 | job-config: ${{ matrix.config.job-config }} 67 | 68 | other-platforms: 69 | needs: setup 70 | if: ${{ needs.setup.outputs.platforms != '[]' }} 71 | runs-on: ${{ matrix.config.os }} 72 | name: ${{ matrix.config.label }} 73 | strategy: 74 | fail-fast: false 75 | matrix: 76 | config: ${{ fromJson(needs.setup.outputs.platforms) }} 77 | 78 | steps: 79 | - uses: r-hub/actions/checkout@v1 80 | - uses: r-hub/actions/setup-r@v1 81 | with: 82 | job-config: ${{ matrix.config.job-config }} 83 | token: ${{ secrets.RHUB_TOKEN }} 84 | - uses: r-hub/actions/platform-info@v1 85 | with: 86 | token: ${{ secrets.RHUB_TOKEN }} 87 | job-config: ${{ matrix.config.job-config }} 88 | - uses: r-hub/actions/setup-deps@v1 89 | with: 90 | job-config: ${{ matrix.config.job-config }} 91 | token: ${{ secrets.RHUB_TOKEN }} 92 | - uses: r-hub/actions/run-check@v1 93 | with: 94 | job-config: ${{ matrix.config.job-config }} 95 | token: ${{ secrets.RHUB_TOKEN }} 96 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Editor backup files 2 | *~ 3 | \#*\# 4 | 5 | # Vignette generated files 6 | RAMClusteR-concordance.tex 7 | RAMClusteR.tex 8 | inst/doc 9 | 10 | # R stuff 11 | .Rhistory 12 | .Rproj.user 13 | .Rhistory 14 | .Rhistory 15 | .Rproj.user/shared/notebooks/paths 16 | .Rhistory 17 | .Rhistory 18 | .Rhistory 19 | .vscode 20 | 21 | # build artifacts 22 | RAMClustR.Rcheck 23 | RAMClustR_*.tar.gz -------------------------------------------------------------------------------- /CRAN-RELEASE: -------------------------------------------------------------------------------- 1 | This package was submitted to CRAN on 2021-08-11. 2 | Once it is accepted, delete this file and tag the release (commit ad45e22). 3 | -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 1.3.1 2 | Date: 2023-07-07 05:49:28 UTC 3 | SHA: 7a96d4d55ea0d67c8402829a69d1c5194a4c35bb 4 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2023-05-17 Helge Hecht v1.3.0 2 | * Added test cases for several functions [PR #3](https://github.com/RECETOX/RAMClustR/pull/3) 3 | * Extracted functions for several duplicate code [PR #23](https://github.com/RECETOX/RAMClustR/pull/23) 4 | * Added option for dataframe input [PR #25](https://github.com/RECETOX/RAMClustR/pull/25) 5 | * Updated ramclustR function with individual function calls [PR #32](https://github.com/RECETOX/RAMClustR/pull/32) 6 | * Added `sample_names` attribute to `ramclustObj` [PR#33](https://github.com/RECETOX/RAMClustR/pull/33) 7 | * Replaced sample.names from phenoData with sample_names attribute in rc.feature files [PR #33](https://github.com/RECETOX/RAMClustR/pull/33) 8 | * Updated featnames with the xcms feature names in rc.get.xcms.data [PR #46](https://github.com/RECETOX/RAMClustR/pull/46) 9 | 10 | 2022-04-05 Helge Hecht v1.2.4 11 | * Adapted tests to also be working on MAC M1 12 | 13 | 2022-03-16 Corey Broeckling v1.2.3 14 | * fixed machineIntegerMax limit. (courtesy Helge Hecht) 15 | * import Sirius output 16 | * import ADAP KDB annotations 17 | 18 | 2021-08-11 Corey Broeckling v1.2.2 19 | * fixed clri bug in write.msp 20 | * fixed annotation bug - no structures from MSFinder were being assigned 21 | * fixed a neutral loss format error used for findMain 22 | 23 | 2021-04-19 Corey Broeckling v1.2.1 24 | * removed closeAllConnections() call from rc.cmpd.get.pubchem for CRAN compatibility 25 | 26 | 2021-04-19 Corey Broeckling v1.2.0 27 | * added pubchem retreival functionality 28 | * added blank filter to remove background features 29 | * added normalization to QC samples 30 | 31 | 2020-04-14 Corey Broeckling v1.1.0 32 | * splitting ramclustR function into several smaller functions 33 | * adjust $history to a list. 34 | 35 | 2019-09-17 Corey Broeckling v1.0.8 36 | * remove dependency on XCMS, replace with XCMS as suggestion 37 | 38 | 2019-08-27 Corey Broeckling v1.0.8 39 | * add reporting, fix processing history narrative issues. 40 | 41 | 2019-04-23 Corey Broeckling v1.0.7 42 | * trying to improve stability of getClassyFire - bug fix in tryCatch part of problem. 43 | 44 | 2019-04-23 Corey Broeckling v1.0.6 45 | * adapted getClassyFire to limit number of new structure ClassyFications to 5/minute per server regulations 46 | * bug fix in annotate, get.synonyms 47 | 48 | 2019-02-15 Corey Broeckling v1.0.5 49 | * fixed bug in do.findmain 50 | 51 | 2019-02-12 Corey Broeckling v1.0.4 52 | * fixed bug in batch.qc correction for MSe data 53 | 54 | 2019-01-30 Corey Broeckling v1.0.3 55 | * added write.methods function to export processing history 56 | 57 | 2019-01-30 Corey Broeckling v1.0.2 58 | * changed behavior of msfinder import and annotation. Structure results from a relevant database can be used to set the formula, rather than formula being independently assigned. 59 | * added rt.only.low.n option to control behavior of clustering with low n (< 5) 60 | 61 | 2019-01-18 Corey Broeckling v1.0.1 62 | * fixed bug in ramclustR function when fewer than five samples. 63 | * added function to convert foodb download to MSFinder structure database import format. 64 | 65 | 2019-01-17 Corey Broeckling 66 | * update R, CRAN check, 1.0.0 67 | 68 | 2019-01-11 Corey Broeckling 69 | * check() returns zero errors or warnings, two notes. 70 | * check.windows() returns BioC warning, unclear how to fix (no reference to BioC apparent) 71 | * updated do.findmain, altered ramclustR scoring algorithm, made ramclustR default, and changed selection criterion for find.main vs ramclustR scoring when mass assignment is conflicted between the two. 72 | 73 | 2018-06-26 Corey Broeckling 74 | * check() returns zero errors, warnings, or notes. 75 | 76 | 2014-09-02 Steffen Neumann 77 | * Fix some minor stuff to make R CMD check happy 78 | 79 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: RAMClustR 2 | Type: Package 3 | Title: Mass Spectrometry Metabolomics Feature Clustering and Interpretation 4 | Version: 1.3.2 5 | Date: 2025-03-26 6 | Authors@R: c( 7 | person("Corey D.", "Broeckling", , "Corey.Broeckling@ColoState.EDU", role = "aut", 8 | comment = c(ORCID = "0000-0002-6158-827X")), 9 | person("Fayyaz", "Afsar", role = "aut"), 10 | person("Steffen", "Neumann", role = "aut"), 11 | person("Asa", "Ben-Hur", role = "aut"), 12 | person("Jessica", "Prenni", role = "aut"), 13 | person("Helge", "Hecht", , "helge.hecht@recetox.muni.cz", role = "cre", 14 | comment = c(ORCID = "0000-0001-6744-996X")), 15 | person("Matej", "Trojak", , "matej.trojak@recetox.muni.cz", role = "ctb"), 16 | person("Zargham", "Ahmad", , "zargham.ahmad@recetox.muni.cz", role = "ctb") 17 | ) 18 | Depends: 19 | R (>= 3.5.0) 20 | Imports: 21 | dynamicTreeCut, 22 | fastcluster, 23 | jsonlite, 24 | e1071, 25 | gplots, 26 | pcaMethods, 27 | utils, 28 | ggplot2, 29 | methods 30 | Suggests: 31 | knitr, 32 | rmarkdown, 33 | xcms, 34 | testthat, 35 | patrick, 36 | MSnbase, 37 | InterpretMSSpectrum (>= 1.3.8), 38 | BiocManager, 39 | xml2, 40 | stringi, 41 | readxl, 42 | curl, 43 | rentrez, 44 | MsExperiment 45 | License: GPL (>= 2) + file LICENSE 46 | Description: A feature clustering algorithm for non-targeted mass spectrometric metabolomics data. This method is compatible with gas and liquid chromatography coupled mass spectrometry, including indiscriminant tandem mass spectrometry data . 47 | URL: https://github.com/cbroeckl/RAMClustR 48 | Encoding: UTF-8 49 | biocViews: MassSpectrometry, Metabolomics 50 | RoxygenNote: 7.3.2 51 | VignetteBuilder: knitr 52 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rocker/r-ver:devel 2 | 3 | RUN apt-get update 4 | # Install system dependencies for R packages (you can add more if needed) 5 | RUN apt-get install -y \ 6 | libcurl4-openssl-dev \ 7 | libssl-dev \ 8 | libxml2-dev \ 9 | libfontconfig1-dev \ 10 | libharfbuzz-dev \ 11 | libcairo2-dev \ 12 | libsqlite3-dev \ 13 | libgit2-dev \ 14 | libv8-dev \ 15 | libprotobuf-dev \ 16 | protobuf-compiler \ 17 | libfribidi-dev \ 18 | libfreetype6-dev \ 19 | libpango1.0-dev \ 20 | pkg-config \ 21 | libtiff-dev \ 22 | libpng-dev \ 23 | libjpeg-dev \ 24 | libnetcdf-dev \ 25 | libhdf5-dev \ 26 | pandoc \ 27 | qpdf 28 | 29 | # Install RAMClustR from source 30 | COPY . /RAMClustR 31 | WORKDIR /RAMClustR 32 | 33 | # Install R packages 34 | RUN R -e "install.packages('ps')" 35 | RUN R -e "install.packages('ragg')" 36 | RUN R -e "install.packages(c('miniUI', 'pkgdown'))" 37 | RUN R -e "install.packages('devtools')" 38 | RUN R -e 'devtools::install_deps(dependencies = TRUE)' 39 | RUN R -e "BiocManager::install(c('ncdf4', 'mzR', 'MSnbase', 'xcms'))" 40 | RUN R -e "BiocManager::install('MsExperiment')" 41 | 42 | 43 | # Default command to run R 44 | CMD [ "R"] -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(RCQC) 4 | export(add_params) 5 | export(compute_SpecAbundAve) 6 | export(compute_do.sets) 7 | export(compute_wt_mean) 8 | export(create_ramclustObj) 9 | export(defineExperiment) 10 | export(define_samples) 11 | export(do.findmain) 12 | export(exportDataset) 13 | export(filter_blanks) 14 | export(filter_good_features) 15 | export(filter_signal) 16 | export(find_good_features) 17 | export(findfeature) 18 | export(findmass) 19 | export(getData) 20 | export(getSampleMetadata) 21 | export(get_ExpDes) 22 | export(get_instrument_platform) 23 | export(mean_signal_intensities) 24 | export(mergeRCobjects) 25 | export(ramclustR) 26 | export(rc.calibrate.ri) 27 | export(rc.cmpd.filter.blanks) 28 | export(rc.cmpd.filter.cv) 29 | export(rc.cmpd.replace.na) 30 | export(rc.expand.sample.names) 31 | export(rc.export.msp.rc) 32 | export(rc.feature.filter.blanks) 33 | export(rc.feature.filter.cv) 34 | export(rc.feature.normalize.batch.qc) 35 | export(rc.feature.normalize.qc) 36 | export(rc.feature.normalize.quantile) 37 | export(rc.feature.normalize.tic) 38 | export(rc.feature.replace.na) 39 | export(rc.get.csv.data) 40 | export(rc.get.df.data) 41 | export(rc.get.xcms.data) 42 | export(rc.merge.split.clusters) 43 | export(rc.qc) 44 | export(rc.ramclustr) 45 | export(rc.remove.qc) 46 | export(rc.restore.qc.samples) 47 | export(remove_blanks) 48 | export(replace_na) 49 | export(write.gcei.mat) 50 | export(write.methods) 51 | export(write.msp) 52 | export(write_csv) 53 | importFrom(dynamicTreeCut,cutreeDynamicTree) 54 | importFrom(e1071,skewness) 55 | importFrom(fastcluster,hclust) 56 | importFrom(gplots,heatmap.2) 57 | importFrom(grDevices,dev.off) 58 | importFrom(grDevices,pdf) 59 | importFrom(graphics,"legend") 60 | importFrom(graphics,"par") 61 | importFrom(graphics,"plot") 62 | importFrom(graphics,"points") 63 | importFrom(graphics,"title") 64 | importFrom(graphics,abline) 65 | importFrom(graphics,axis) 66 | importFrom(graphics,boxplot) 67 | importFrom(graphics,hist) 68 | importFrom(jsonlite,fromJSON) 69 | importFrom(methods,is) 70 | importFrom(pcaMethods,pca) 71 | importFrom(stats,aggregate) 72 | importFrom(stats,cor) 73 | importFrom(stats,fitted) 74 | importFrom(stats,lm) 75 | importFrom(stats,loess) 76 | importFrom(stats,median) 77 | importFrom(stats,predict) 78 | importFrom(stats,quantile) 79 | importFrom(stats,sd) 80 | importFrom(stats,weighted.mean) 81 | importFrom(utils,citation) 82 | importFrom(utils,edit) 83 | importFrom(utils,packageVersion) 84 | importFrom(utils,read.csv) 85 | importFrom(utils,read.delim) 86 | importFrom(utils,read.delim2) 87 | importFrom(utils,write.csv) 88 | -------------------------------------------------------------------------------- /R/calculate.similarity.R: -------------------------------------------------------------------------------- 1 | compute.start <- function(position, blocksize, numcols) { 2 | return(min((1 + ((position - 1) * blocksize)), numcols)) 3 | } 4 | 5 | compute.stop <- function(position, blocksize, numcols) { 6 | if ((position) * blocksize > numcols) { 7 | stop_pos <- numcols 8 | } else { 9 | stop_pos <- (position) * blocksize 10 | } 11 | return(stop_pos) 12 | } 13 | 14 | calculate.similarity <- function(numcols, 15 | data1, 16 | data2, 17 | times, 18 | blocksize, 19 | mult, 20 | maxt, 21 | st, 22 | sr, 23 | rt.only.low.n, 24 | cor.method, 25 | cor.use) { 26 | ######## 27 | # establish some constants for downstream processing 28 | vlength <- (numcols * (numcols - 1)) / 2 29 | nblocks <- ceiling(numcols / blocksize) 30 | 31 | cat(paste("Calculating ramclustR similarity using", sum((nblocks+1):1), "nblocks.\n")) 32 | 33 | ramclustObj <- vector(mode = "integer", length = vlength) 34 | block = 1 35 | column <- NULL 36 | 37 | for (row in 1:(nblocks)) { 38 | for (col in row:(nblocks)) { 39 | cat(block, " ") 40 | block <- block + 1 41 | 42 | start_col <- compute.start(row, blocksize, numcols) 43 | stop_col <- compute.stop(row, blocksize, numcols) 44 | 45 | start_row <- compute.start(col, blocksize, numcols) 46 | stop_row <- compute.stop(col, blocksize, numcols) 47 | 48 | if (start_col <= start_row) { 49 | mint <- min(abs(outer(range(times[start_row:stop_row]), 50 | range(times[start_col:stop_col]), 51 | FUN = "-"))) 52 | if (mint <= maxt) { 53 | # RT similarity 54 | RT_sim <- round(exp(-(((abs(outer(times[start_row:stop_row], 55 | times[start_col:stop_col], 56 | FUN = "-")) 57 | )) ^ 2) / (2 * (st ^ 2))), digits = 20) 58 | 59 | if (nrow(data1) < 5 & rt.only.low.n) { 60 | # correlational similarity 61 | corr_sim <- matrix(data = 1, 62 | nrow = length(start_row:stop_row), 63 | ncol = length(start_col:stop_col) 64 | ) 65 | } else { 66 | suppressWarnings( 67 | max_value <- pmax( 68 | cor( 69 | data1[, start_row:stop_row], data1[, start_col:stop_col], method = cor.method, use = cor.use), 70 | cor( 71 | data1[, start_row:stop_row], data2[, start_col:stop_col], method = cor.method, use = cor.use), 72 | cor( 73 | data2[, start_row:stop_row], data2[, start_col:stop_col], method = cor.method, use = cor.use) 74 | , na.rm = TRUE 75 | ) 76 | 77 | ) 78 | if(any(is.na(max_value))) { 79 | max_value[is.na(max_value)] <- 0 80 | } 81 | # correlational similarity 82 | corr_sim <- round(exp(-((1 - max_value) ^ 2) / (2 * (sr ^ 2))), digits = 20) 83 | } 84 | 85 | # overall similarity 86 | sim_matrix <- 1 - (RT_sim * corr_sim) 87 | # remove nans and infs 88 | sim_matrix[which(is.nan(sim_matrix)) | 89 | which(is.na(sim_matrix)) | 90 | which(is.infinite(sim_matrix))] <- 1 91 | } else { 92 | # overall similarity 93 | sim_matrix <- matrix(data = 1, 94 | nrow = length(start_row:stop_row), 95 | ncol = length(start_col:stop_col) 96 | ) 97 | } 98 | } 99 | 100 | # merge computed similarity matrices to single matrix (extend rows) 101 | if (is.null(column)) { 102 | column <- sim_matrix 103 | } else { 104 | column <- rbind(column, sim_matrix) 105 | } 106 | } 107 | 108 | # remove values above the diagonal and convert to vector by columns 109 | column <- column[which(row(column) - col(column) > 0)] 110 | 111 | if (exists("startv") == FALSE) 112 | startv <- 1 113 | stopv <- startv + length(column) - 1 114 | 115 | # assign obtained vector to result 116 | ramclustObj[startv:stopv] <- column 117 | startv <- stopv + 1 118 | 119 | # remove column to start next iteration with clean slate 120 | column <- NULL 121 | } 122 | 123 | cat('\n RAMClust feature similarity matrix calculated and stored.\n') 124 | gc() 125 | 126 | return(ramclustObj) 127 | } 128 | -------------------------------------------------------------------------------- /R/exportDataset.R: -------------------------------------------------------------------------------- 1 | #' exportDataset 2 | #' 3 | #' export one of 'SpecAbund', 'SpecAbundAve', 'MSdata' or 'MSMSdata' from an RC object to csv 4 | #' @details Useful for exporting the processed signal intensity matrix to csv for analysis elsewhere. 5 | #' @param ramclustObj ramclustR object to export from 6 | #' @param which.data name of dataset to export. SpecAbund, SpecAbundAve, MSdata, or MSMSdata 7 | #' @param label.by either 'ann' or 'cmpd', generally. name of ramclustObj slot used as csv header for each column (compound) 8 | #' @param appendFactors logical. If TRUE (default) the factor data frame is appended to the left side of the dataset. 9 | #' @return nothing is returned. file exported as csf to 'datasets/*.csv' 10 | #' @concept ramclustR 11 | #' @concept RAMClustR 12 | #' @author Corey Broeckling 13 | #' @references Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 14 | #' @export 15 | 16 | exportDataset<-function( 17 | ramclustObj=NULL, 18 | which.data="SpecAbund", 19 | label.by="cmpd", 20 | appendFactors = TRUE 21 | ) { 22 | 23 | if(is.null(ramclustObj)) { 24 | stop("must supply ramclustObj as input. i.e. ramclustObj = RC", '\n') 25 | } 26 | 27 | d <- RAMClustR::getData( 28 | ramclustObj = ramclustObj, 29 | which.data = which.data, 30 | cmpdlabel = label.by 31 | ) 32 | 33 | # if(filter){ 34 | # if(!is.null(ramclustObj$cmpd.use)) { 35 | # if(length(ramclustObj$cmpd.use == ncol(d[[2]]))) { 36 | # cmpd.use <- which(ramclustObj$cmpd.use) 37 | # } else { 38 | # cmpd.use <- 1:ncol(d[[2]]) 39 | # } 40 | # } else { 41 | # cmpd.use <- 1:ncol(d[[2]]) 42 | # } 43 | # } else { 44 | # cmpd.use <- 1:ncol(d[[2]]) 45 | # } 46 | check.names = FALSE 47 | dimnames(d[[2]])[[2]] <- ramclustObj[[label.by]] 48 | dimnames(d[[3]])[[2]][((dim(d[[3]])[2] - dim(d[[2]])[2] + 1)):(dim(d[[3]])[2])] <- ramclustObj[[label.by]] 49 | if(appendFactors) { 50 | write.csv(d[[3]], paste("datasets/", which.data, ".csv", sep=""), row.names=FALSE) 51 | } else { 52 | write.csv(d[[2]], paste("datasets/", which.data, ".csv", sep=""), row.names=TRUE) 53 | } 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /R/findfeature.R: -------------------------------------------------------------------------------- 1 | #' findfeature 2 | #' 3 | #' see if any features match a given mass, and whether they are plausibly M0 4 | #' @details a convenience function to perform a targeted search of all features for a mass of interest. Also performs a crude plausibility check as to whether the matched feature could be M0, based on the assumption of approximately 1 carbon per 17 m/z units and natural isotopic abundance of 1.1% 13C. Note that this function returns the cluster to which the feature is assigned, but that the M0_plausibility is independent of cluster membership. 5 | #' 6 | #' @param ramclustObj R object: the ramclustR object to explore 7 | #' @param mz numeric: mz value to search for 8 | #' @param mztol numeric: absolute mass tolerance around mz 9 | #' @param rt numeric: optional rt value to search for (generally in seconds, though use whatever units your data is in) 10 | #' @param rttol numeric: absolute retention time tolerance around rt. 11 | #' @param iso.rttol numeric: when examining isotope patterns, feature retention time tolerance around features matching mz +- mztol 12 | #' @param zmax integer: maximum charge state to consider. default is 6. 13 | #' @param m.check logical: check whether the matching masses are plausibly M0. That is, we look for ions 1 proton mass (from charge state 1:zmax) below the target m/z at the same time that have intensities consistent with target ion being a non-M0 isotope. 14 | #' @return returns a table to the console listing masses which match, their retention time and intensity, and whether it appears to be plausible as M0 15 | #' @concept ramclustR 16 | #' @concept RAMClustR 17 | #' @concept metabolomics 18 | #' @concept mass spectrometry 19 | #' @concept clustering 20 | #' @concept feature 21 | #' @concept MSFinder 22 | #' @concept xcms 23 | #' @author Corey Broeckling 24 | #' @export 25 | 26 | findfeature <- function (ramclustObj = NULL, 27 | mz = NULL, 28 | mztol = 0.02, 29 | rt = NULL, 30 | rttol = 2, 31 | iso.rttol = 2, 32 | zmax = 6, 33 | m.check = TRUE) 34 | { 35 | 36 | if(is.null(ramclustObj)) { 37 | stop("must supply ramclustObj as input. i.e. ramclustObj = RC", '\n') 38 | } 39 | 40 | if (is.null(mz)) { 41 | stop("must set 'mz'", "\n") 42 | } 43 | if (is.null(mztol)) { 44 | stop("must set 'mztol'", "\n") 45 | } 46 | if(is.numeric(rt)) { 47 | tar <- which((abs(ramclustObj$fmz - mz) <= mztol) & (abs(ramclustObj$frt - rt) <= rttol)) 48 | } else { 49 | tar <- which(abs(ramclustObj$fmz - mz) <= mztol) 50 | } 51 | if (length(tar) == 0) { 52 | out <- data.frame(featn = NA, featclus = NA, 53 | mz = NA, rt = NA, 54 | int = NA, M0_plausible = NA) 55 | out<-out[0,] 56 | } 57 | else { 58 | out <- data.frame(featn = tar, featclus = ramclustObj$featclus[tar], 59 | mz = ramclustObj$fmz[tar], rt = ramclustObj$frt[tar], 60 | int = ramclustObj$msint[tar], M0_plausible = rep(NA, 61 | length(tar))) 62 | if (m.check) { 63 | for (i in 1:length(tar)) { 64 | check <- vector() 65 | for (j in 1:zmax) { 66 | check1 <- which((abs(ramclustObj$fmz - mz + 67 | 1.007276) <= mztol) & (abs(ramclustObj$frt - 68 | ramclustObj$frt[tar[i]]) <= iso.rttol)) 69 | check <- unique(c(check, check1)) 70 | } 71 | if (length(check) > 0) { 72 | negrange <- c(0.5, 2) * (ramclustObj$msint[tar[i]]/((ramclustObj$fmz[tar[i]]/17) * 73 | 0.011)) 74 | out[i, "M0_plausible"] <- !any(ramclustObj$msint[check] > 75 | negrange[1] & ramclustObj$msint[check] < 76 | negrange[2]) 77 | } 78 | else { 79 | out[i, "M0_plausible"] <- TRUE 80 | } 81 | } 82 | } 83 | } 84 | return(out) 85 | } 86 | 87 | -------------------------------------------------------------------------------- /R/findmass.R: -------------------------------------------------------------------------------- 1 | #' findmass 2 | #' 3 | #' see if any features match a given mass, and whether they are plausibly M0 4 | #' @details a convenience function to perform a targeted search of all feaures for a mass of interest. Also performs a crude plausibility check as to whether the matched feature could be M0, based on the assumption of approximately 1 carbon per 17 m/z units and natural isotopic abundance of 1.1% 13C. Note that this function returns the cluster to which the feature is assigned, but that the M0_plausibility is independent of cluster membership. 5 | #' 6 | #' @param ramclustObj R object: the ramclustR object to explore 7 | #' @param mz numeric: mz value to search for 8 | #' @param mztol numeric: absolute mass tolerance around mz 9 | #' @param rttol numeric: when examining isotope patterns, feature retention time tolerance around features matching mz +- mztol 10 | #' @param zmax integer: maximum charge state to consider. default is 6. 11 | #' @param m.check logical: check whether the matching masses are plausibly M0. That is, we look for ions 1 proton mass (from charge state 1:zmax) below the target m/z at the same time that have intensities consistent with target ion being a non-M0 isotope. 12 | #' @return returns a table to the console listing masses which match, their retention time and intensity, and whether it appears to be plausible as M0 13 | #' @concept ramclustR 14 | #' @concept RAMClustR 15 | #' @concept metabolomics 16 | #' @concept mass spectrometry 17 | #' @concept clustering 18 | #' @concept feature 19 | #' @concept MSFinder 20 | #' @concept xcms 21 | #' @author Corey Broeckling 22 | #' @export 23 | 24 | findmass <- function (ramclustObj = NULL, 25 | mz = NULL, 26 | mztol = 0.02, 27 | rttol = 2, 28 | zmax = 6, 29 | m.check = TRUE) 30 | { 31 | 32 | if(is.null(ramclustObj)) { 33 | stop("must supply ramclustObj as input. i.e. ramclustObj = RC", '\n') 34 | } 35 | 36 | if (is.null(mz)) { 37 | stop("must set 'mz'", "\n") 38 | } 39 | if (is.null(mztol)) { 40 | stop("must set 'mztol'", "\n") 41 | } 42 | tar <- which(abs(ramclustObj$fmz - mz) <= mztol) 43 | if (length(tar) == 0) { 44 | out <- data.frame(featn = NA, featclus = NA, 45 | mz = NA, rt = NA, 46 | int = NA, M0_plausible = NA) 47 | out<-out[0,] 48 | } 49 | else { 50 | out <- data.frame(featn = tar, featclus = ramclustObj$featclus[tar], 51 | mz = ramclustObj$fmz[tar], rt = ramclustObj$frt[tar], 52 | int = ramclustObj$msint[tar], M0_plausible = rep(NA, 53 | length(tar))) 54 | if (m.check) { 55 | for (i in 1:length(tar)) { 56 | check <- vector() 57 | for (j in 1:zmax) { 58 | check1 <- which((abs(ramclustObj$fmz - mz + 59 | 1.007276) <= mztol) & (abs(ramclustObj$frt - 60 | ramclustObj$frt[tar[i]]) <= rttol)) 61 | check <- unique(c(check, check1)) 62 | } 63 | if (length(check) > 0) { 64 | negrange <- c(0.5, 2) * (ramclustObj$msint[tar[i]]/((ramclustObj$fmz[tar[i]]/17) * 65 | 0.011)) 66 | out[i, "M0_plausible"] <- !any(ramclustObj$msint[check] > 67 | negrange[1] & ramclustObj$msint[check] < 68 | negrange[2]) 69 | } 70 | else { 71 | out[i, "M0_plausible"] <- TRUE 72 | } 73 | } 74 | } 75 | } 76 | return(out) 77 | } 78 | 79 | -------------------------------------------------------------------------------- /R/getData.R: -------------------------------------------------------------------------------- 1 | #' getData 2 | #' 3 | #' retrieve and parse sample names, retrieve metabolite data. returns as list of two data frames 4 | #' @details convenience function for parsing sample names and returning a dataset. 5 | #' @param ramclustObj ramclustR object to retrieve data from 6 | #' @param which.data character; which dataset (SpecAbund or SpecAbundAve) to reference 7 | #' @param delim character; "-" by default - the delimiter for parsing sample names to factors 8 | #' @param cmpdlabel = "cmpd"; label the data with the annotation. can also be set to 'ann' for column names assigned as annotatins. 9 | #' @param filter = TRUE; logical, if TRUE, checks for $cmpd.use slot generated by rc.cmpd.cv.filter() function, and only gets acceptable compounds. 10 | #' @return returns a list of length 3: $design is the experimental sample factors after parsing by the delim, $data is the dataset, $full.data is merged $des and $data data.frames. 11 | #' @concept RAMClustR 12 | #' @author Corey Broeckling 13 | 14 | #' @export 15 | 16 | getData<-function(ramclustObj=NULL, 17 | which.data="SpecAbund", 18 | delim="-", 19 | cmpdlabel="cmpd", 20 | filter = FALSE 21 | ) { 22 | 23 | if(which.data == 'MSdata') { 24 | cmpdlabel = 'featnames' 25 | } 26 | 27 | 28 | if(is.null(ramclustObj$phenoData)) { 29 | dat <- ramclustObj[[which.data]] 30 | if(filter) { 31 | if(!is.null(ramclustObj$cmpd.use)) { 32 | if(ncol(dat) == length(ramclustObj$cmpd.use)) { 33 | cmpd.use <- which(ramclustObj$cmpd.use) 34 | dat <- dat[,cmpd.use] 35 | } 36 | } 37 | } 38 | 39 | if(length(ramclustObj[[cmpdlabel]]) == dim(ramclustObj[[which.data]])[2]) { 40 | names(dat) <- ramclustObj[[cmpdlabel]] 41 | } else { 42 | stop(paste("ramclustObj slot", cmpdlabel, "has length", length(ramclustObj[[cmpdlabel]]), "while the", which.data, "dataset has", dim(ramclustObj[[which.data]])[2], "columns", '\n')) 43 | } 44 | des <- data.frame(t(data.frame(strsplit(row.names(dat), delim), check.names = FALSE)), stringsAsFactors = FALSE, check.names = FALSE) 45 | row.names(des) <- row.names(dat) 46 | 47 | factors<-sapply(1:nrow(dat), FUN=function(x) length(strsplit(as.character(dimnames(dat)[[1]]), delim)[[x]])) 48 | maxfact<-max(factors) 49 | factnames<-c(ramclustObj$ExpDes$design[which(row.names(ramclustObj$ExpDes$design)=="fact1name"): 50 | (which(row.names(ramclustObj$ExpDes$design)=="fact1name")+(maxfact-1)), 1]) 51 | 52 | names(des)<-factnames 53 | dat<-list("design" = des, "data" = dat, "full.data" = cbind(des, dat)) 54 | } else { 55 | if(nrow(ramclustObj$phenoData) != nrow(ramclustObj[[which.data]])) { 56 | stop('number of rows for phenoData and ', which.data, ' are not the same.', '\n') 57 | } 58 | if(filter) { 59 | if(!is.null(ramclustObj$cmpd.use)) { 60 | cmpd.use <- which(ramclustObj$cmpd.use) 61 | }else { 62 | cmpd.use <- 1:length(ramclustObj[[cmpdlabel]]) 63 | } 64 | } else { 65 | cmpd.use <- 1:length(ramclustObj[[cmpdlabel]]) 66 | } 67 | dat <- list( 68 | "design" = ramclustObj$phenoData, 69 | "data" = ramclustObj[[which.data]][,cmpd.use], 70 | "full.data" = data.frame(ramclustObj$phenoData, ramclustObj[[which.data]][,cmpd.use]) 71 | ) 72 | dimnames(dat$data)[[2]] <- ramclustObj[[cmpdlabel]] 73 | dimnames(dat$full.data)[[2]][(ncol(dat$design)+1):ncol(dat$full.data)] <- ramclustObj[[cmpdlabel]] 74 | } 75 | return(dat) 76 | } 77 | 78 | -------------------------------------------------------------------------------- /R/rc.calibrate.ri.R: -------------------------------------------------------------------------------- 1 | #' rc.calibrate.ri 2 | #' 3 | #' extractor for xcms objects in preparation for clustering 4 | #' 5 | #' @param ramclustObj ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS) 6 | #' @param calibrant.data character vector defining the file path/name to a csv file containing columns including 'rt', and 'ri'. Alternatively, a data.frame with those columnn names (case sensitive) 7 | #' @param poly.order integer default = 3. polynomical order used to fit rt vs ri data, and calculate ri for all feature and metabolite rt values. poly.order should be apprciably smaller than the number of calibrant points. 8 | #' @details This function generates a new slot in the ramclustR object for retention index. Calibration is performed using a polynomial fit of order poly.order. It is the user's responsibility to ensure that the number and span of calibrant points is sufficient to calibrate the full range of feature and compound retention times. i.e. if the last calibration point is at 1000 seconds, but the last eluting peak is at 1300 seconds, the calibration will be very poor for the late eluting compound. 9 | #' @return ramclustR object with retention index assigned for features ($fri) and compounds ($clri). 10 | #' 11 | #' @references Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 12 | #' @concept ramclustR 13 | #' @concept RAMClustR 14 | #' @concept metabolomics 15 | #' @concept mass spectrometry 16 | #' @concept clustering 17 | #' @concept feature 18 | #' @concept MSFinder 19 | #' @concept xcms 20 | #' @author Corey Broeckling 21 | #' @export 22 | 23 | rc.calibrate.ri <- function( 24 | ramclustObj=NULL, 25 | calibrant.data = "", 26 | poly.order = 3 27 | ) { 28 | 29 | if(is.null(ramclustObj)) { 30 | stop("RAMClustR object must be provided") 31 | } 32 | 33 | if(!is.numeric(poly.order)) { 34 | stop("poly.order must be an integer value - default = 2") 35 | } 36 | 37 | if(!is.data.frame(calibrant.data)) { 38 | if(file.exists(calibrant.data)) { 39 | tmp <- read.csv(calibrant.data, 40 | header = TRUE, 41 | check.names = FALSE, 42 | stringsAsFactors = FALSE, 43 | encoding = "UTF-8") 44 | if(!all(c("ri", "rt") %in% names(tmp))) { 45 | stop("calibrant data must have column names minimally containing 'rt' and 'ri'") 46 | } 47 | calibrant.data <- tmp 48 | } 49 | } else { 50 | if(!all(c("ri", "rt") %in% names(tmp))) { 51 | stop("calibrant data must have column names minimally containing 'rt' and 'ri'") 52 | } 53 | } 54 | 55 | calibrant.data$rt <- as.numeric(calibrant.data$rt) 56 | calibrant.data$ri <- as.numeric(calibrant.data$ri) 57 | 58 | pl.data <- calibrant.data[,c("rt", "ri")] 59 | fit <- lm(ri ~ poly(rt, poly.order), data = pl.data) 60 | mean.error <- round(mean(100*abs(fit$fitted.values - pl.data$ri) / pl.data$ri), digits = 2) 61 | nd <- data.frame("rt" = ramclustObj$clrt, 62 | "ri" = rep(NA, length(ramclustObj$clrt))) 63 | clri <- as.vector(stats::predict.lm(fit, newdata = nd)) 64 | type <- c(rep("cal", nrow(pl.data)), rep("cmpd", length(clri))) 65 | pl.data <- rbind(pl.data, nd) 66 | ri.fit <- c(fit$fitted.values, rep(NA, length(clri))) 67 | pl.data <- data.frame(type, pl.data, ri.fit) 68 | pl.data[((nrow(calibrant.data)+1):nrow(pl.data)),"ri"] <- clri 69 | pl.data$type <- factor(pl.data$type, levels = c("cmpd", "cal")) 70 | suppressWarnings(p <- ggplot2::ggplot(pl.data, ggplot2::aes(x=pl.data$rt, y=pl.data$ri)) + 71 | ggplot2::geom_point(ggplot2::aes(shape = type, size = type)) + 72 | ggplot2::geom_line(ggplot2::aes(x=pl.data$rt[1:nrow(calibrant.data)], y=ri.fit[1:nrow(calibrant.data)]), 73 | data = pl.data[1:nrow(calibrant.data),], 74 | size = 0.8, col = 2) + 75 | ggplot2::ggtitle(paste("Calibration: polynomical order =", poly.order)) + 76 | ggplot2::geom_text(x = 1.15*min(pl.data$rt), 77 | y = 0.925*max(pl.data$ri), 78 | hjust=0, 79 | label=paste("Mean RI error: ", mean.error, "%")) + 80 | ggplot2::theme_bw() 81 | ) 82 | suppressWarnings( print(p) ) 83 | if(max(ramclustObj$clrt) > (max(calibrant.data$rt)* 1.1) | 84 | min(ramclustObj$clrt) < (min(calibrant.data$rt)* 0.9) 85 | ) { 86 | warning(" -- calibration range cannot accurantely assign RI values outside the calibrant range.") 87 | } 88 | 89 | if(poly.order*3 > nrow(calibrant.data) 90 | ) { 91 | warning(" -- poly.order should be set to a value appreciably less than the number of calibrant points.") 92 | } 93 | 94 | ramclustObj$clri <- clri 95 | 96 | ## same for features 97 | nd <- data.frame("rt" = ramclustObj$frt, 98 | "ri" = rep(NA, length(ramclustObj$frt))) 99 | fri <- as.vector(stats::predict.lm(fit, newdata = nd)) 100 | ramclustObj$fri <- fri 101 | 102 | ramclustObj$ri.calibrant <- calibrant.data 103 | return(ramclustObj) 104 | } 105 | -------------------------------------------------------------------------------- /R/rc.cmpd.cv.filter.R: -------------------------------------------------------------------------------- 1 | #' rc.cmpd.filter.cv 2 | #' 3 | #' extractor for xcms objects in preparation for clustering 4 | #' 5 | #' @param ramclustObj ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS) 6 | #' @param qc.tag character vector of length one or two. If length is two, enter search string and factor name in $phenoData slot (i.e. c("QC", "sample.type"). If length one (i.e. "QC"), will search for this string in the 'sample.names' slot by default. 7 | #' @param max.cv numeric maximum allowable cv for any feature. default = 0.3 8 | #' @details This function offers normalization by total extracted ion signal. it is recommended to first run 'rc.feature.filter.blanks' to remove non-sample derived signal. 9 | #' @return ramclustR object with total extracted ion normalized data. 10 | #' 11 | #' @references Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 12 | #' @concept ramclustR 13 | #' @concept RAMClustR 14 | #' @concept metabolomics 15 | #' @concept mass spectrometry 16 | #' @concept clustering 17 | #' @concept feature 18 | #' @concept MSFinder 19 | #' @concept xcms 20 | #' @author Corey Broeckling 21 | #' @export 22 | 23 | rc.cmpd.filter.cv <- function( 24 | ramclustObj=NULL, 25 | qc.tag = "QC", 26 | max.cv = 0.5 27 | ) { 28 | 29 | params <- c( 30 | qc.tag = "QC", 31 | max.cv = max.cv 32 | ) 33 | 34 | ## CHECKS 35 | if(is.null(ramclustObj)) { 36 | stop('existing ramclustObj required as input', '\n', 37 | ' see rc.get.xcms.data function for one approach to do so', '\n') 38 | } 39 | 40 | if(is.null(qc.tag)) { 41 | stop("qc.tag = NULL; qc.tag must be defined to enable QC variance examination.", '\n') 42 | } 43 | 44 | if(is.null(ramclustObj$SpecAbund)) { 45 | stop('cannot perform compound removal before clustering', '\n', 46 | ' please run rc.ramclustr before clustering', '\n') 47 | } 48 | 49 | 50 | if(is.null(ramclustObj$SpecAbundAve)) { 51 | do.sets <- "SpecAbund" 52 | } else { 53 | do.sets <- c("SpecAbund", "SpecAbundAve") 54 | } 55 | 56 | ## define QC samples in each set 57 | if(length(qc.tag) == 1) { 58 | qc <- grepl(qc.tag[1], ramclustObj$phenoData$sample.names) 59 | } 60 | if(length(qc.tag) == 2) { 61 | qc <- grepl(qc.tag[1], ramclustObj$phenoData[[qc.tag[2]]]) 62 | } 63 | 64 | if(length(which(qc)) == 0) { 65 | stop("no QC samples found using the qc.tag ", "'", qc.tag, "'", '\n') 66 | } 67 | 68 | ## find 'good' features, acceptable CV at either 69 | ## MS or MSMS level results in keeping 70 | keep <- rep(FALSE, ncol(ramclustObj$SpecAbund)) 71 | # par(mfrow = c(1, length(do.sets))) 72 | for(x in do.sets) { 73 | td <- ramclustObj[[x]] 74 | sds<-apply(td[qc,], 2, FUN="sd", na.rm=TRUE) 75 | #cat(sds, '\n') 76 | means<-apply(td[qc,], 2, FUN="mean", na.rm=TRUE) 77 | cvs<-sds/means 78 | # hist(cvs, main = x, xlab = "CV") 79 | keep[which(cvs <= max.cv)] <- TRUE 80 | # hist(cvs[which(cvs <= max.cv)], add = TRUE, col = "gray") 81 | } 82 | 83 | ## subset all vectors, matrices, data.frames and lists to keep only those of interest 84 | for(x in names(ramclustObj)) { 85 | if(is.vector(ramclustObj[[x]]) | (is.list(ramclustObj[[x]])) & !is.data.frame(ramclustObj[[x]])) { 86 | if(length(ramclustObj[[x]]) == length(cvs)) { 87 | ramclustObj[[x]] <- ramclustObj[[x]][keep] 88 | } 89 | } 90 | 91 | if(is.matrix(ramclustObj[[x]]) | is.data.frame(ramclustObj[[x]])) { 92 | if(dim(ramclustObj[[x]])[[2]] == length(cvs)) { 93 | ramclustObj[[x]] <- ramclustObj[[x]][,keep] 94 | } 95 | } 96 | } 97 | 98 | if(is.null(ramclustObj$params)) {ramclustObj$params <- list()} 99 | ramclustObj$params$rc.cmpd.cv.filter <- params 100 | 101 | ramclustObj$history$filter.cmpds <- paste0( 102 | "Compounds were filtered based on their qc sample CV values.", 103 | " All compounds with CV values greater than ", max.cv, 104 | " in the cluster intensity (SpecAbund) dataset", 105 | " were removed. ", length(which(!keep))," of ", length(keep), " compounds were removed." 106 | ) 107 | 108 | cat(ramclustObj$history$filter.cmpds) 109 | 110 | return(ramclustObj) 111 | } 112 | -------------------------------------------------------------------------------- /R/rc.cmpd.filter.blanks.R: -------------------------------------------------------------------------------- 1 | #' rc.cmpd.filter.blanks 2 | #' 3 | #' used to remove compounds which are found at similar intensity in blank samples. Only applied after clustering. see also rc.feature.filter.blanks for filtering at the feature level (only done before clustering). 4 | #' 5 | #' @param ramclustObj ramclustObj containing SpecAbund dataframe. 6 | #' @param qc.tag character vector of length one or two. If length is two, enter search string and factor name in $phenoData slot (i.e. c("QC", "sample.type"). If length one (i.e. "QC"), will search for this string in the 'sample.names' slot by default. 7 | #' @param blank.tag see 'qc.tag' , but for blanks to use as background. 8 | #' @param sn numeric defines the ratio for 'signal'. i.e. sn = 3 indicates that signal intensity must be 3 fold higher in sample than in blanks, on average, to be retained. 9 | #' @param remove.blanks logical. TRUE by default. this removes any recognized blanks samples from the SpecAbund sets after they are used to filter contaminant compounds 10 | #' @details This function removes compounds which contain signal in QC samples comparable to blanks. 11 | #' @return ramclustR object with normalized data. 12 | #' 13 | #' @references Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 14 | #' @concept ramclustR 15 | #' @concept RAMClustR 16 | #' @concept metabolomics 17 | #' @concept mass spectrometry 18 | #' @concept clustering 19 | #' @concept feature 20 | #' @concept MSFinder 21 | #' @concept xcms 22 | #' @author Corey Broeckling 23 | #' @export 24 | 25 | rc.cmpd.filter.blanks <- function(ramclustObj=NULL, 26 | qc.tag = "QC", 27 | blank.tag = "blank", 28 | sn = 3, 29 | remove.blanks = TRUE 30 | ) { 31 | 32 | if(is.null(ramclustObj)) { 33 | stop("please provide a ramclustR Object as input.", '\n') 34 | } 35 | 36 | if(is.null(ramclustObj$SpecAbund)) { 37 | 38 | } 39 | 40 | if(!is.numeric(sn)) { 41 | stop("sn must be numeric",'\n') 42 | } 43 | 44 | if(is.null(ramclustObj$SpecAbund)) { 45 | stop("this data does not contain a SpecAbund dataset", '\n') 46 | } else { 47 | d1 <- ramclustObj$SpecAbund 48 | } 49 | 50 | 51 | ## define QC and Blank samples in each set 52 | if(length(qc.tag) == 1) { 53 | qc <- grep(qc.tag[1], ramclustObj$phenoData$sample.names) 54 | qc <- qc[which(qc <= nrow(d1))] 55 | } 56 | 57 | if(length(qc.tag) == 2) { 58 | qc <- grep(qc.tag[1], ramclustObj$phenoData[[qc.tag[2]]]) 59 | qc <- qc[which(qc <= nrow(d1))] 60 | } 61 | 62 | if(length(qc) == 0) { 63 | stop("no qc samples found. ", '\n') 64 | } 65 | 66 | if(length(blank.tag) == 1) { 67 | blank <- grep(blank.tag[1], ramclustObj$phenoData$sample.names) 68 | blank <- blank[which(blank <= nrow(d1))] 69 | } 70 | 71 | if(length(blank.tag) == 2) { 72 | blank <- grep(blank.tag[1], ramclustObj$phenoData[[blank.tag[2]]]) 73 | blank <- blank[which(blank <= nrow(d1))] 74 | } 75 | 76 | if(length(blank) == 0) { 77 | stop("no blank samples found. ", '\n') 78 | } 79 | 80 | ## create logical vector of features to keep 81 | ## 'good' features should have signal intensity 82 | ## in pooled QC and/or Samples that is at least 83 | ## sn higher than the process blank 84 | 85 | # MS1 mean signal intensities 86 | if(length(qc) > 1) { 87 | ms1.qc.mean <- apply(d1[qc,], 2, FUN = "mean", na.rm = TRUE) 88 | } else { 89 | ms1.qc.mean <- d1[qc,] 90 | } 91 | if(length(blank)>1) { 92 | ms1.blank.mean <- apply(d1[blank,], 2, FUN = "mean", na.rm = TRUE) 93 | } else { 94 | ms1.blank.mean <- d1[blank,] 95 | } 96 | absent.in.blank <- which(is.nan(ms1.blank.mean)) 97 | 98 | # filters 99 | # which signal is at least 3x larger in QC 100 | keep.ms1.a <- which(ms1.qc.mean/ms1.blank.mean >= sn) 101 | # which signal is present in QC and absent in blank 102 | keep.ms1.b <- which((!is.nan(ms1.qc.mean)) & is.nan(ms1.blank.mean)) 103 | # union of these two are keepers 104 | keep <- union(keep.ms1.a, keep.ms1.b) 105 | 106 | length(keep)/ncol(d1) 107 | cat(round(100*length(keep)/ncol(d1), digits = 1), "% of compounds move forward", '\n', sep = "") 108 | 109 | ## define variables that we need to subset 110 | do <- rep(FALSE, length(ramclustObj)) 111 | rf <- data.frame(index = 1:ncol(d1)); rf <- rf[,0] 112 | for(i in 1:length(do)) { 113 | if(any(names(ramclustObj)[i] %in% c("MSdata_raw","MSMSdata_raw"))) { 114 | next 115 | } 116 | if(is.vector(ramclustObj[[i]]) & !is.list(ramclustObj[[i]])) { 117 | if(length(ramclustObj[[i]]) == ncol(d1)) { 118 | rf <- data.frame(rf, ramclustObj[[i]]) 119 | names(rf)[ncol(rf)] <- names(ramclustObj[i]) 120 | ramclustObj[[i]] <- ramclustObj[[i]][keep] 121 | } 122 | } 123 | 124 | if(is.list(ramclustObj[[i]])) { 125 | if(length(ramclustObj[[i]]) == ncol(d1)) { 126 | ramclustObj[[i]] <- ramclustObj[[i]][keep] 127 | } 128 | } 129 | 130 | if(is.data.frame(ramclustObj[[i]])) { 131 | cat("df", names(ramclustObj)[i], '\n') 132 | if(dim(ramclustObj[[i]])[2] == ncol(d1)) { 133 | ramclustObj[[i]] <- ramclustObj[[i]][,keep] 134 | } 135 | if(dim(ramclustObj[[i]])[1] == ncol(d1)) { 136 | ramclustObj[[i]] <- ramclustObj[[i]][keep,] 137 | } 138 | } 139 | 140 | if(is.matrix(ramclustObj[[i]])) { 141 | cat("ma", names(ramclustObj)[i], '\n') 142 | if(dim(ramclustObj[[i]])[2] == ncol(d1)) { 143 | ramclustObj[[i]] <- ramclustObj[[i]][,keep] 144 | } 145 | if(dim(ramclustObj[[i]])[1] == ncol(d1)) { 146 | ramclustObj[[i]] <- ramclustObj[[i]][keep,] 147 | } 148 | } 149 | 150 | if(is.matrix(ramclustObj[[i]])) { 151 | 152 | } 153 | } 154 | ramclustObj$feature.filter.blanks <- rf[-keep,] 155 | 156 | if(remove.blanks){ 157 | ramclustObj$SpecAbund <- ramclustObj$SpecAbund[-blank,] 158 | if(!is.null(ramclustObj$phenoData)) { 159 | ramclustObj$phenoData <- ramclustObj$phenoData[-blank,] 160 | } 161 | } 162 | 163 | ramclustObj$history$cmpd.filter.blanks <- { 164 | paste0( 165 | "Compounds which failed to demonstrate signal intensity of at least ", 166 | sn, " -fold greater in QC samples than in blanks were removed from the SpecAbund dataset. ", 167 | ncol(d1) - length(keep)," of ", ncol(d1), " compounds were removed." 168 | ) 169 | } 170 | 171 | cat(ramclustObj$history$cmpd.filter.blanks) 172 | 173 | return(ramclustObj) 174 | } 175 | -------------------------------------------------------------------------------- /R/rc.cmpd.replace.na.R: -------------------------------------------------------------------------------- 1 | #' rc.cmpd.replace.na 2 | #' 3 | #' replaces any NA (and optionally zero) values with small signal (20% of minimum feature signal value + 20% random noise) 4 | #' 5 | #' @param ramclustObj ramclustObj containing SpecAbund dataset 6 | #' @param replace.int default = 0.2. proportion of minimum feature value to replace NA (or zero) values with 7 | #' @param replace.noise default = 0.2. proportion ofreplace.int value by which noise is added via 'jitter' 8 | #' @param replace.zero logical if TRUE, any zero values are replaced with noise as if they were NA values 9 | #' @details noise is added by finding for each feature the minimum detected value, multiplying that value by replace.int, then adding (replace.int*replace.noise) noise. abs() is used to ensure no negative values result. 10 | #' @return ramclustR object with NA and zero values removed. 11 | #' 12 | #' @references Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 13 | #' @concept ramclustR 14 | #' @concept RAMClustR 15 | #' @concept metabolomics 16 | #' @concept mass spectrometry 17 | #' @concept clustering 18 | #' @concept feature 19 | #' @concept MSFinder 20 | #' @concept xcms 21 | #' @author Corey Broeckling 22 | #' @export 23 | 24 | rc.cmpd.replace.na <- function( 25 | ramclustObj=NULL, 26 | replace.int = 0.1, 27 | replace.noise = 0.1, 28 | replace.zero = TRUE 29 | ) { 30 | 31 | if(is.null(ramclustObj)) { 32 | stop("please provide a ramclustR Object as input.", '\n') 33 | } 34 | 35 | if(!is.numeric(replace.int)) { 36 | stop("replace.int must be numeric",'\n') 37 | } 38 | 39 | if(!is.numeric(replace.noise)) { 40 | stop("replace.noise must be numeric",'\n') 41 | } 42 | 43 | if(!is.logical(replace.zero)) { 44 | stop("replace.zero must be logical",'\n') 45 | } 46 | 47 | params <- c( 48 | "replace.int" = replace.int, 49 | "replace.noise" = replace.noise, 50 | "replace.zero" = replace.zero 51 | ) 52 | 53 | 54 | ######## 55 | # ensure that we have all numeric values, 56 | # then optionally ensure we have all non-zero values in the dataset. 57 | # uses a noise addition 'jitter' around minimum values with missing data points. 58 | # this is mostly necessary for csv input, where other programs may not have used a 'fillPeaks' like step 59 | # it is important for clustering that variation is present for every feature and MS level. 60 | n.feat.replaced <- 0 61 | n.feat.total <- 0 62 | for(x in c("SpecAbund", "SpecAbundAve")) { 63 | # skip MSMS data if it isn't present 64 | if(x == "SpecAbund" & is.null(ramclustObj$SpecAbund)) { 65 | next 66 | } 67 | if(x == "SpecAbundAve" & is.null(ramclustObj$SpecAbundAve)) { 68 | next 69 | } 70 | # select data frame to use 71 | data <- ramclustObj[[x]] 72 | n.feat.total <- n.feat.total + (dim(data)[[1]] * dim(data)[[2]]) 73 | 74 | # define a global minimum for the data set to use when all feature values are missing/zero 75 | min.int.global <- min(data, na.rm = TRUE) 76 | 77 | 78 | # which values need replacing 79 | for(i in 1:ncol(data)) { 80 | rpl <- unique(c(which(is.na(data[,i])), which(is.nan(data[,i])), which(is.infinite(data[,i])))) 81 | if(replace.zero) { 82 | rpl.z <- which(data[,i] == 0) 83 | if(length(rpl.z) > 0) { 84 | rpl <- unique(c(rpl, rpl.z)) 85 | } 86 | } 87 | if(length(rpl) > 0) { 88 | if(all(is.na(data[,i]))) { 89 | min.int.local <- min.int.global 90 | } else { 91 | min.int.local <- min(data[,i], na.rm = TRUE) 92 | } 93 | min.int <- min(min.int.local, min.int.global, na.rm = TRUE) 94 | rpl.with <- rep((min.int * replace.int), length(rpl)) 95 | rpl.with <- abs(jitter(rpl.with, amount = rpl.with[1]*replace.noise)) 96 | data[rpl, i] <- rpl.with 97 | n.feat.replaced <- n.feat.replaced + length(rpl) 98 | } 99 | } 100 | ramclustObj[[x]] <- data 101 | } 102 | result <- paste("replaced", n.feat.replaced, "of", n.feat.total, "total feature values (", 103 | round((100 * n.feat.replaced/n.feat.total)), "% )", '\n') 104 | cat(result) 105 | 106 | ramclustObj$history$replace.na <- { 107 | paste0( 108 | "Features with missing values were replaced with small values simulating noise. ", 109 | "For each feature, the minimum detected value was multiplied by ", replace.int, ". ", 110 | "Noise was then added using a factor of ", replace.noise, ". ", 111 | "The absolute value of this value was used as the filled value to ensure that only non-negative values carried forward. ", 112 | if(replace.zero) { 113 | "Zero values were treated as missing values." 114 | } 115 | ) 116 | } 117 | 118 | if(is.null(ramclustObj$params)) {ramclustObj$params <- list()} 119 | ramclustObj$params$rc.feature.replace.na <- params 120 | 121 | return(ramclustObj) 122 | } 123 | -------------------------------------------------------------------------------- /R/rc.expand.sample.names.R: -------------------------------------------------------------------------------- 1 | #' rc.expand.sample.names 2 | #' 3 | #' turn concatenated sample names into factors 4 | #' 5 | #' @param ramclustObj ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS) 6 | #' @param delim what delimiter should be used to separate names into factors? '-' by default 7 | #' @param factor.names logical or character vector. if TRUE, user will enter names one by on in console. If character vector (i.e. c("trt", "time")) names are assigned to table 8 | #' @param quiet logical . if TRUE, user will not be prompted to enter names one by on in console. 9 | #' @details THis function only works on newer format ramclustObjects with a $phenoData slot. 10 | #' @details This function will split sample names by a delimiter, and enable users to name factors 11 | #' @return ramclustR object with normalized data. 12 | #' 13 | #' @references Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 14 | #' @concept ramclustR 15 | #' @concept RAMClustR 16 | #' @concept metabolomics 17 | #' @concept mass spectrometry 18 | #' @concept clustering 19 | #' @concept feature 20 | #' @concept MSFinder 21 | #' @concept xcms 22 | #' @author Corey Broeckling 23 | #' @export 24 | 25 | rc.expand.sample.names <- function( 26 | ramclustObj = NULL, 27 | delim = "-", 28 | factor.names = TRUE, 29 | quiet = FALSE 30 | ) { 31 | 32 | params <- c( 33 | "delim" = delim 34 | ) 35 | 36 | 37 | if(!is.null(ramclustObj$phenoData$sample.names.sample_name)) { 38 | sn <- as.character(ramclustObj$phenoData$sample.names.sample_name) 39 | } 40 | if(!is.null(ramclustObj$phenoData$sample.names.sn)) { 41 | sn <- as.character(ramclustObj$phenoData$sample.names.sn) 42 | } 43 | 44 | if(!is.null(ramclustObj$phenoData$sample.names)) { 45 | sn <- as.character(ramclustObj$phenoData$sample.names) 46 | } 47 | 48 | # cat(paste(sn, collapse = ", "), '\n') 49 | 50 | if(!any(ls()=="sn")) { 51 | stop('missing sample names in phenoData slot', '\n') 52 | } 53 | des <- strsplit(sn, delim) 54 | l <- sapply(1:length(des), FUN = function(x) { 55 | length(des[[x]]) 56 | }) 57 | if(length(table(l)) != 1) { 58 | cat("delimited sample names have variable lengths ranging from: ", '\n', 59 | range(l)[1], " to ", range(l)[2], '\n') 60 | ch <- which(l != median(l)) 61 | stop("please fix sample names:", '\n', paste(" ", sn[ch], sep = '\n')) 62 | } 63 | des <- data.frame(t(data.frame(des, check.names = FALSE)), 64 | stringsAsFactors = FALSE, check.names = FALSE) 65 | 66 | if(is.logical(factor.names) & !quiet) { 67 | if(factor.names){ 68 | for(x in 1:ncol(des)) { 69 | cat( 70 | "column",x, "variables:",'\n', 71 | unique(des[,x]), '\n') 72 | fn <- readline(prompt=cat("Type name and press [enter] to continue:", '\n')) 73 | dimnames(des)[[2]][x] <- fn 74 | } 75 | } 76 | } 77 | 78 | if(is.character(factor.names)) { 79 | if(length(factor.names) != ncol(des)) { 80 | stop(length(factor.names), "factor names and", ncol(des), "factors - please correct", '\n') 81 | } 82 | dimnames(des)[[2]] <- factor.names 83 | } 84 | rn <- row.names(ramclustObj$phenoData) 85 | ramclustObj$phenoData <- cbind(ramclustObj$phenoData, des[,1:ncol(des)]) 86 | 87 | if(is.null(ramclustObj$params)) {ramclustObj$params <- list()} 88 | ramclustObj$params$rc.expand.sample.names <- params 89 | 90 | row.names(ramclustObj$phenoData) <- rn 91 | return(ramclustObj) 92 | 93 | } 94 | 95 | 96 | -------------------------------------------------------------------------------- /R/rc.export.msp.rc.R: -------------------------------------------------------------------------------- 1 | #' rc.export.msp.rc 2 | #' 3 | #' Cluster annotation function: inference of 'M' - molecular weight of the compound giving rise to each spectrum - using the InterpretMSSpectrum::findMain function 4 | #' 5 | #' @param ramclustObj ramclustR object to annotate. 6 | #' @param one.file logical, should all msp spectra be written to one file? If false, each spectrum is an individual file. 7 | #' @param mzdec integer. Number of decimal points to export mass values with. 8 | #' @details exports files to a directory called 'spectra'. If one.file = FALSE, a new directory 'spectra/msp' is created to hold the individual msp files. if do.findman has been run, spectra are written as ms2 spectra, else as ms1. 9 | #' @return nothing, just exports files to the working directory 10 | #' @concept ramclustR 11 | #' @concept RAMClustR 12 | #' @concept metabolomics 13 | #' @concept mass spectrometry 14 | #' @concept clustering 15 | #' @concept interpretMSSpectrum 16 | #' @concept xcms 17 | #' @author Corey Broeckling 18 | #' @importFrom methods is 19 | #' @export 20 | #' 21 | rc.export.msp.rc <- function( 22 | ramclustObj = NULL, 23 | one.file = TRUE, 24 | mzdec = 1 25 | ) { 26 | 27 | if(!is(ramclustObj, "hclus") & 28 | ramclustObj$dist.method != "RAMClustR") { 29 | stop("this is not a RAMClustR object") 30 | } 31 | 32 | if(is.null(ramclustObj$precursor.mz)) { 33 | ms2 <- FALSE 34 | } else { 35 | ms2 <- TRUE 36 | } 37 | 38 | if(is.null(ramclustObj$MSMSdata)) { 39 | mslev <- 1 40 | } else { 41 | mslev <- 2 42 | } 43 | 44 | if(!dir.exists('spectra')) { 45 | dir.create('spectra') 46 | } 47 | 48 | if(!one.file) { 49 | if(!dir.exists('spectra/msp')) { 50 | dir.create('spectra/msp') 51 | } 52 | } 53 | ion.mode <- as.character(ramclustObj$ExpDes[[2]][which(row.names(ramclustObj$ExpDes[[2]]) == "msmode"),1]) 54 | if(toupper(substring(ion.mode, 1, 1)) == "P") { 55 | ion.mode = "P" 56 | } else { 57 | ion.mode = "N" 58 | } 59 | 60 | ExpDes <- ramclustObj$ExpDes 61 | out.list <- as.list(rep(NA, length(ramclustObj$cmpd)*mslev)) 62 | 63 | for (m in 1:as.numeric(mslev)){ 64 | for(i in 1:length(ramclustObj$cmpd)) { 65 | ions <- which(ramclustObj$featclus == i) 66 | 67 | if(ms2) { 68 | spectrum <- data.frame( 69 | 'mz' = ramclustObj$fmz[ions], 70 | 'int' = ramclustObj$msmsint[ions] 71 | ) 72 | } else { 73 | spectrum <- data.frame( 74 | 'mz' = ramclustObj$fmz[ions], 75 | 'int' = ramclustObj$msint[ions] 76 | ) 77 | } 78 | 79 | spectrum <- spectrum[order(spectrum[,"int"], decreasing = TRUE), ] 80 | spectrum$mz <- round(spectrum$mz, digits = mzdec) 81 | spectrum$int <- round(spectrum$int, digits = 1) 82 | 83 | tmp <- paste0( 84 | "Name: ", ramclustObj$cmpd[i], '\n', 85 | "SYNON: $:00", if(!ms2){"in-source"} else {"MS2"}, '\n', 86 | "SYNON: $:05", if(m==1) { 87 | ExpDes[[2]]["CE1", 1] 88 | } else { 89 | ExpDes$instrument["CE2", "InstVals"] 90 | }, 91 | '\n', 92 | "SYNON: $:06", ExpDes[[2]]["mstype", 1], '\n', #mstype 93 | "SYNON: $:07", ExpDes[[2]]["msinst", 1], '\n', #msinst 94 | "SYNON: $:09", ExpDes[[2]]["chrominst", 1], '\n', #chrominst 95 | "SYNON: $:10", ExpDes[[2]]["ionization", 1], '\n', #ionization method 96 | "SYNON: $:11", ExpDes[[2]]["msmode", 1], '\n', #msmode 97 | "SYNON: $:14", ExpDes[[2]]["msscanrange", 1], '\n', #ms scanrange 98 | "Comment: Rt=", round(ramclustObj$clrt[i], digits=2), 99 | " Contributor=", ExpDes[[1]]["Contributor", 1], 100 | " Study=", ExpDes[[1]]["Experiment", 1], '\n', 101 | "Num Peaks:", nrow(spectrum), '\n', 102 | paste(sapply(1:nrow(spectrum), 103 | FUN = function(x) { 104 | paste(spectrum$mz[x], spectrum$int[x]) 105 | } 106 | ), collapse = '\n'), '\n', '\n' 107 | ) 108 | 109 | if(m == 1) {out.list[[i]] <- tmp} 110 | if(m == 2) {out.list[[i + length(ramclustObj$cmpd)]] <- tmp} 111 | } 112 | } 113 | 114 | 115 | 116 | if(one.file) { 117 | out <- vector(mode = "character") 118 | for(i in 1:length(out.list)) { 119 | out <- paste0(out, out.list[[i]], '\n') 120 | } 121 | exp.name <- ramclustObj$ExpDes[[1]][which(row.names(ramclustObj$ExpDes[[1]]) == "Experiment"),1] 122 | if(nchar(exp.name) == 0) { 123 | exp.name <- "spectra" 124 | } 125 | sink(paste0("spectra/", exp.name, ".rc.msp")) 126 | cat(out) 127 | sink() 128 | } else { 129 | for(i in 1:length(out.list)) { 130 | sink(paste0("spectra/msp/", ramclustObj$cmpd[[i]], ".rc.msp")) 131 | cat(out.list[[i]], '\n') 132 | sink() 133 | } 134 | } 135 | 136 | } 137 | 138 | -------------------------------------------------------------------------------- /R/rc.feature.normalize.quantile.R: -------------------------------------------------------------------------------- 1 | quantile_normalisation <- function(df) { 2 | df_rank <- apply(df, 2, rank, ties.method = "min") 3 | df_sorted <- data.frame(apply(df, 2, sort)) 4 | df_mean <- apply(df_sorted, 1, mean) 5 | 6 | index_to_mean <- function(my_index, my_mean) { 7 | return(my_mean[my_index]) 8 | } 9 | 10 | df_final <- apply(df_rank, 2, index_to_mean, my_mean = df_mean) 11 | rownames(df_final) <- rownames(df) 12 | return(df_final) 13 | } 14 | 15 | #' rc.feature.normalize.quantile 16 | #' 17 | #' normalize data using quantile 18 | #' 19 | #' @param ramclustObj ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS) 20 | #' @return ramclustR object with normalized data. 21 | #' @export 22 | rc.feature.normalize.quantile <- function(ramclustObj = NULL) { 23 | ramclustObj$MSdata <- t(quantile_normalisation(t(ramclustObj$MSdata))) 24 | 25 | if (!is.null(ramclustObj$MSMSdata)) { 26 | ramclustObj$MSMSdata <- t(quantile_normalisation(t(ramclustObj$MSMSdata))) 27 | } 28 | 29 | ## update msint and optionally msmsint 30 | global.min <- apply(cbind(ramclustObj$MSdata, ramclustObj$MSMSdata), 2, "min", na.rm = TRUE) 31 | 32 | ramclustObj$msint <- compute_wt_mean( 33 | ramclustObj$MSdata, 34 | global.min, 35 | ramclustObj$fmz, 36 | TRUE 37 | ) 38 | 39 | if (!is.null(ramclustObj$MSMSdata)) { 40 | ramclustObj$msmsint <- compute_wt_mean( 41 | ramclustObj$MSMSdata, 42 | global.min, 43 | ramclustObj$fmz, 44 | TRUE 45 | ) 46 | } 47 | 48 | ramclustObj$history$normalize.quantile <- paste( 49 | " Features were normalized using 'quantile' normalization." 50 | ) 51 | 52 | return(ramclustObj) 53 | } 54 | -------------------------------------------------------------------------------- /R/rc.feature.normalize.tic.R: -------------------------------------------------------------------------------- 1 | #' normalized_data_tic 2 | #' 3 | #' normalize data using TIC 4 | #' 5 | #' @param ramclustObj ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS) 6 | #' @return ramclustR object with total extracted ion normalized data. 7 | 8 | normalized_data_tic <- function(ramclustObj = NULL){ 9 | msint <- rowSums(ramclustObj$MSdata, na.rm = TRUE) 10 | msint.mean <- mean(msint) 11 | ramclustObj$MSdata <- (ramclustObj$MSdata / msint) * msint.mean 12 | 13 | if (!is.null(ramclustObj$MSMSdata)) { 14 | msmsint <- rowSums(ramclustObj$MSMSdata, na.rm = TRUE) 15 | msmsint.mean <- mean(msmsint) 16 | ramclustObj$MSMSdata <- (ramclustObj$MSMSdata / msmsint) * msmsint.mean 17 | } 18 | 19 | ramclustObj$history$normalize.tic <- paste0( 20 | "Features were ", 21 | if (!is.null(ramclustObj$history$normalize.batch.qc)) { 22 | "additionally " 23 | }, 24 | "normalized to total extracted ion signal to account for differences in total solute concentration." 25 | ) 26 | 27 | return(ramclustObj) 28 | } 29 | 30 | #' rc.feature.normalize.tic 31 | #' 32 | #' extractor for xcms objects in preparation for clustering 33 | #' 34 | #' @param ramclustObj ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS) 35 | #' @details This function offers normalization by total extracted ion signal. it is recommended to first run 'rc.feature.filter.blanks' to remove non-sample derived signal. 36 | #' @return ramclustR object with total extracted ion normalized data. 37 | #' 38 | #' @references Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 39 | #' @concept ramclustR 40 | #' @concept RAMClustR 41 | #' @concept metabolomics 42 | #' @concept mass spectrometry 43 | #' @concept clustering 44 | #' @concept feature 45 | #' @concept MSFinder 46 | #' @concept xcms 47 | #' @author Corey Broeckling 48 | #' @export 49 | 50 | rc.feature.normalize.tic <- function(ramclustObj = NULL) { 51 | ## CHECKS 52 | if (is.null(ramclustObj)) { 53 | stop( 54 | "existing ramclustObj required as input", "\n", 55 | " see rc.get.xcms.data function for one approach to do so", "\n" 56 | ) 57 | } 58 | 59 | params <- c() 60 | 61 | ramclustObj <- normalized_data_tic(ramclustObj = ramclustObj) 62 | 63 | ## update msint and optionally msmsint 64 | global.min <- apply(cbind(ramclustObj$MSdata, ramclustObj$MSMSdata), 2, "min", na.rm = TRUE) 65 | 66 | ramclustObj$msint <- compute_wt_mean( 67 | ramclustObj$MSdata, 68 | global.min, 69 | ramclustObj$fmz, 70 | TRUE 71 | ) 72 | 73 | if (!is.null(ramclustObj$MSMSdata)) { 74 | ramclustObj$msmsint <- compute_wt_mean( 75 | ramclustObj$MSMSdata, 76 | global.min, 77 | ramclustObj$fmz, 78 | TRUE 79 | ) 80 | } 81 | 82 | if (is.null(ramclustObj$params)) { 83 | ramclustObj$params <- list() 84 | } 85 | 86 | ramclustObj$params$rc.feature.normalize.tic <- params 87 | 88 | return(ramclustObj) 89 | } 90 | -------------------------------------------------------------------------------- /R/rc.merge.clusters.R: -------------------------------------------------------------------------------- 1 | #' rc.merge.split.clusters 2 | #' 3 | #' Cluster refinement - scanning instruments (quadrupole, as in GC-MS) can display cluster splitting, possibily due to slight differences in measured peak retentiont time as a function of mass due to scan dynamics. this function enables a second pass clustering designed to merge two clusters if the second cluster is within a small retention time window and shows a sufficiently strong correlation. 4 | #' 5 | #' @param ramclustObj ramclustR object to annotate. 6 | #' @param merge.threshold numeric. value between -1 and 1 indicating the correlational r threshold above which two clusters will be merged 7 | #' @param cor.method character: which correlational method used to calculate 'r' - see ?cor 'method' option. default = "pearson" 8 | #' @param cor.use character: which data points to use to calculate 'r' - see ?cor 'use' option. default = "pairwise.complete.obs" 9 | #' @param rt.sd.factor numeric. default = 3. clusters within rt.sd.factor * ramclustObj$rtsd (cluster retention time standard deviation) are considered for merging. 10 | #' @param sample.name.column character. column name from ramclustObj$phenoData which should be used as row.names in new ramclustObj$SpecAbund dataset. 11 | #' @details exports files to a directory called 'spectra'. If one.file = FALSE, a new directory 'spectra/msp' is created to hold the individual msp files. if do.findman has been run, spectra are written as ms2 spectra, else as ms1. 12 | #' @return new ramclustR object, with (generally) fewer clusters than the input ramclustR object. 13 | #' @concept ramclustR 14 | #' @concept RAMClustR 15 | #' @concept metabolomics 16 | #' @concept mass spectrometry 17 | #' @concept clustering 18 | #' @concept xcms 19 | #' @author Corey Broeckling 20 | #' @importFrom methods is 21 | #' @export 22 | #' 23 | #' 24 | rc.merge.split.clusters <- function( 25 | ramclustObj = NULL, 26 | merge.threshold = 0.7, 27 | cor.method = 'spearman', 28 | rt.sd.factor = 3, 29 | cor.use = "everything", 30 | sample.name.column = "sample.ID" 31 | 32 | ) { 33 | 34 | if(is.null(ramclustObj)) stop('please provide a ramclustObj', '\n') 35 | if(!is.numeric(merge.threshold)) merge.threshold <- as.numeric(merge.threshold) 36 | if(merge.threshold < 0 | merge.threshold > 1) stop("'merge.threshold' must be between zero and one", '\n') 37 | 38 | 39 | ## for all clusters, see if there are clusters at nearby retentiontimes which highly correlate 40 | ## if there are, join them, renumber featclus, and regenerate SpecAbund file. 41 | orig.cl.n <- max(ramclustObj$featclus) 42 | cls <- max(ramclustObj$featclus):2 43 | # ramclustObj <- RC 44 | for(i in cls) { 45 | if(max(diff(sort(unique(ramclustObj$featclus)))) > 1) stop("error 1") 46 | potential.merges <- which( 47 | (abs(ramclustObj$clrt[1:i] - ramclustObj$clrt[i])) < (rt.sd.factor*ramclustObj$clrtsd[i]) 48 | ) 49 | potential.merges <- potential.merges[!potential.merges == i] 50 | if(length(potential.merges) == 0) next 51 | 52 | rval <- cor(ramclustObj$SpecAbund[,i], ramclustObj$SpecAbund[,potential.merges], method = cor.method, use = cor.use) 53 | merges <- potential.merges[which(rval >= merge.threshold)] 54 | if(length(merges) == 0) next 55 | 56 | merges <- max(merges) 57 | 58 | ramclustObj$featclus[which(ramclustObj$featclus == i)] <- merges 59 | # if(max(diff(sort(unique(ramclustObj$featclus)))) > 1) cat(i, "max diff = ", max(diff(sort(unique(ramclustObj$featclus)))), '\n') 60 | old.featclus <- ramclustObj$featclus 61 | new.featclus <- old.featclus 62 | decend.by.one <- which(old.featclus > i) 63 | new.featclus[decend.by.one] <- (old.featclus[decend.by.one])-1 64 | if(max(diff(sort(unique(new.featclus)))) > 1) stop("error 2") 65 | ramclustObj$featclus <- new.featclus 66 | 67 | } 68 | # sort(unique(ramclustObj$featclus)) 69 | # sort(unique(RC$featclus)) 70 | 71 | ## store SpecAbund sample names 72 | sa.rn <- dimnames(ramclustObj$SpecAbund)[[1]] 73 | 74 | # 0.99888 75 | 76 | # collapse feature dataset into spectrum dataset 77 | data1 <- ramclustObj$MSdata 78 | wts<-colMeans(data1[], na.rm = TRUE) 79 | ramclustObj$SpecAbund<-matrix(nrow=nrow(data1), ncol=max(ramclustObj$featclus)) 80 | for (ro in 1:nrow(ramclustObj$SpecAbund)) { 81 | for (co in 1:ncol(ramclustObj$SpecAbund)) { 82 | ramclustObj$SpecAbund[ro,co]<- weighted.mean(data1[ro,which(ramclustObj$featclus==co)], wts[which(ramclustObj$featclus==co)], na.rm = TRUE) 83 | } 84 | } 85 | dimnames(ramclustObj$SpecAbund)[[1]] <- sa.rn 86 | 87 | strl <- nchar(max(ramclustObj$featclus)) - 1 88 | ramclustObj$cmpd <- paste("C", formatC(1:max(ramclustObj$featclus), digits = strl, flag = 0 ) , sep="") 89 | ramclustObj$ann <- ramclustObj$cmpd 90 | 91 | clrt<-aggregate(ramclustObj$frt, by=list(ramclustObj$featclus), FUN="mean") 92 | ramclustObj$clrt<-clrt[which(clrt[,1]!=0),2] 93 | clrtsd<-aggregate(ramclustObj$frt, by=list(ramclustObj$featclus), FUN="sd") 94 | ramclustObj$clrtsd<-clrtsd[which(clrtsd[,1]!=0),2] 95 | ramclustObj$nfeat<-as.vector(table(ramclustObj$featclus)[2:max(ramclustObj$featclus)]) 96 | ramclustObj$nsing<-length(which(ramclustObj$featclus==0)) 97 | ramclustObj$annconf<-rep(4, length(ramclustObj$clrt)) 98 | ramclustObj$annnotes<-rep("", length(ramclustObj$clrt)) 99 | dimnames(ramclustObj$SpecAbund)[[1]] <- ramclustObj$phenoData[,sample.name.column] 100 | 101 | new.cl.n <- max(ramclustObj$featclus) 102 | cat(paste("Original cluster number =", orig.cl.n, '\n', "New cluster number =", new.cl.n, '\n')) 103 | 104 | return(ramclustObj) 105 | 106 | } 107 | 108 | -------------------------------------------------------------------------------- /R/rc.remove.qc.R: -------------------------------------------------------------------------------- 1 | #' rc.remove.qc 2 | #' 3 | #' summarize quality control for clustering and for quality control sample variation based on compound ($SpecAbund) and feature ($MSdata and $MSMSdata, if present) 4 | #' 5 | #' @param ramclustObj ramclustR object to analyze 6 | #' @param qc.tag qc.tag character vector of length one or two. If length is two, enter search string and factor name in $phenoData slot (i.e. c("QC", "sample.type"). If length one (i.e. "QC"), will search for this string in the 'sample.names' slot by default. 7 | #' 8 | #' @details simply moves QC samples out of the way for downstream processing. moved to a $qc slot. 9 | #' @return new RC object. moves QC samples to new $qc slot from original position. 10 | #' @references Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 11 | #' @references Broeckling CD, Ganna A, Layer M, Brown K, Sutton B, Ingelsson E, Peers G, Prenni JE. Enabling Efficient and Confident Annotation of LC-MS Metabolomics Data through MS1 Spectrum and Time Prediction. Anal Chem. 2016 Sep 20;88(18):9226-34. doi: 10.1021/acs.analchem.6b02479. Epub 2016 Sep 8. PubMed PMID: 7560453. 12 | #' @concept ramclustR 13 | #' @concept RAMClustR 14 | #' @concept metabolomics 15 | #' @concept mass spectrometry 16 | #' @concept clustering 17 | #' @concept feature 18 | #' @concept MSFinder 19 | #' @concept xcms 20 | #' @author Corey Broeckling 21 | #' @export 22 | 23 | rc.remove.qc <- function(ramclustObj = NULL, 24 | qc.tag = "QC") { 25 | params <- c( 26 | "qc.tag" = qc.tag 27 | ) 28 | 29 | 30 | if (is.null(ramclustObj)) { 31 | stop("must supply ramclustObj as input. i.e. ramclustObj = RC", "\n") 32 | } 33 | 34 | if (is.null(qc.tag)) { 35 | stop("qc.tag = NULL; qc.tag must be defined to enable QC variance examination.", "\n") 36 | } 37 | 38 | do.sets <- c("MSdata", "MSMSdata", "SpecAbund") 39 | if (is.null(ramclustObj$MSMSdata)) { 40 | do.sets <- do.sets[!(do.sets %in% "MSMSdata")] 41 | } 42 | if (is.null(ramclustObj$SpecAbund)) { 43 | do.sets <- do.sets[!(do.sets %in% "SpecAbund")] 44 | } 45 | 46 | do.sets.rows <- sapply( 47 | c(do.sets, "phenoData", "sample_names"), 48 | FUN = function(x) { 49 | NROW(ramclustObj[[x]]) 50 | } 51 | ) 52 | 53 | if (!all.equal( 54 | do.sets.rows, do.sets.rows 55 | ) 56 | ) { 57 | stop("number of rows in MSdata, SpecAbund, and phenoData sets are not identical.") 58 | } 59 | 60 | ## define QC samples in each set 61 | qc <- define_samples(ramclustObj, qc.tag) 62 | 63 | ramclustObj$qc <- list() 64 | for (x in c("phenoData", "sample_names",do.sets)) { 65 | if (is.vector(ramclustObj[[x]])) { 66 | ramclustObj$qc[[x]] <- ramclustObj[[x]][qc] 67 | ramclustObj[[x]] <- ramclustObj[[x]][-qc] 68 | } else { 69 | ramclustObj$qc[[x]] <- ramclustObj[[x]][qc, ] 70 | ramclustObj[[x]] <- ramclustObj[[x]][-qc, ] 71 | } 72 | } 73 | 74 | ramclustObj$history$qc.summary <- paste( 75 | ramclustObj$history$qc.summary, 76 | "QC samples were removed from the set for downstream processing." 77 | ) 78 | 79 | if (is.null((ramclustObj$params))) { 80 | ramclustObj$params <- list() 81 | } 82 | ramclustObj$params$rc.remove.qc <- params 83 | 84 | return(ramclustObj) 85 | } 86 | -------------------------------------------------------------------------------- /R/rc.restore.qc.samples.R: -------------------------------------------------------------------------------- 1 | #' rc.restore.qc.samples 2 | #' 3 | #' summarize quality control for clustering and for quality control sample variation based on compound ($SpecAbund) and feature ($MSdata and $MSMSdata, if present) 4 | #' 5 | #' @param ramclustObj ramclustR object to analyze 6 | #' 7 | #' @details moves all of $phenoData, $MSdata, $MSMSdata, $SpecAbund back to original positions from $qc slot 8 | #' @return RC object 9 | #' @references Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 10 | #' @references Broeckling CD, Ganna A, Layer M, Brown K, Sutton B, Ingelsson E, Peers G, Prenni JE. Enabling Efficient and Confident Annotation of LC-MS Metabolomics Data through MS1 Spectrum and Time Prediction. Anal Chem. 2016 Sep 20;88(18):9226-34. doi: 10.1021/acs.analchem.6b02479. Epub 2016 Sep 8. PubMed PMID: 7560453. 11 | #' @concept ramclustR 12 | #' @concept RAMClustR 13 | #' @concept metabolomics 14 | #' @concept mass spectrometry 15 | #' @concept clustering 16 | #' @concept feature 17 | #' @concept MSFinder 18 | #' @concept xcms 19 | #' @author Corey Broeckling 20 | #' @export 21 | 22 | rc.restore.qc.samples<-function( 23 | ramclustObj = NULL 24 | ){ 25 | 26 | if(is.null(ramclustObj)) { 27 | stop("must supply ramclustObj as input. i.e. ramclustObj = RC", '\n') 28 | } 29 | 30 | if(is.null(ramclustObj$qc)) { 31 | stop("No qc slot present in ramclustObj.", '\n') 32 | } 33 | 34 | do.sets <- c("MSdata", "MSMSdata", "SpecAbund") 35 | if(is.null(ramclustObj$MSMSdata)) { 36 | do.sets <- do.sets[!(do.sets %in% "MSMSdata")] 37 | } 38 | if(is.null(ramclustObj$SpecAbund)) { 39 | do.sets <- do.sets[!(do.sets %in% "SpecAbund")] 40 | } 41 | 42 | do.sets.rows <- sapply( 43 | c(do.sets, "phenoData", "sample_names"), 44 | FUN = function(x) { 45 | NROW(ramclustObj[[x]]) 46 | }) 47 | 48 | if(!all.equal( 49 | do.sets.rows, do.sets.rows) 50 | ) { 51 | stop("number of rows in sample sets are not identical.") 52 | } 53 | 54 | do.sets <- names(ramclustObj$qc) 55 | for(x in c(do.sets)) { 56 | if(is.vector(ramclustObj[[x]])){ 57 | ramclustObj[[x]] <- append(ramclustObj[[x]], ramclustObj$qc[[x]]) 58 | } else { 59 | ramclustObj[[x]] <- rbind(ramclustObj[[x]], ramclustObj$qc[[x]]) 60 | } 61 | } 62 | 63 | ramclustObj$qc <- NULL 64 | 65 | ord.pheno <- order(as.numeric(row.names(ramclustObj$phenoData))) 66 | for(x in c(do.sets)) { 67 | if (is.vector(ramclustObj[[x]])) { 68 | ramclustObj[[x]] <- ramclustObj[[x]][ord.pheno] 69 | } else { 70 | ramclustObj[[x]] <- ramclustObj[[x]][ord.pheno, ] 71 | } 72 | } 73 | return(ramclustObj) 74 | } 75 | -------------------------------------------------------------------------------- /R/write.gcei.mat.R: -------------------------------------------------------------------------------- 1 | #' write.gcei.mat 2 | #' 3 | #' Export GC-MS EI spectra for spectral searching in MSFinder 4 | #' 5 | #' @param ramclustObj ramclustR object to annotate. 6 | #' @details exports files to a directory called 'spectra'. a new directory 'spectra/mat' is created to hold the individual mat files. 7 | #' @return nothing, just exports files to the working directory 8 | #' @concept ramclustR 9 | #' @concept RAMClustR 10 | #' @concept metabolomics 11 | #' @concept mass spectrometry 12 | #' @concept clustering 13 | #' @concept interpretMSSpectrum 14 | #' @concept xcms 15 | #' @author Corey Broeckling 16 | #' @importFrom methods is 17 | #' @export 18 | #' 19 | 20 | write.gcei.mat <- function( 21 | ramclustObj = NULL 22 | ) { 23 | 24 | if(!is(ramclustObj, "hclus") & 25 | ramclustObj$dist.method != "RAMClustR") { 26 | stop("this is not a RAMClustR object") 27 | } 28 | 29 | if(!dir.exists('spectra')) { 30 | dir.create('spectra') 31 | } 32 | 33 | 34 | if(!dir.exists('spectra/mat')) { 35 | dir.create('spectra/mat') 36 | } 37 | 38 | ion.mode <- "Positive" 39 | 40 | out.list <- as.list(rep(NA, length(ramclustObj$cmpd))) 41 | 42 | for(i in 1:length(ramclustObj$cmpd)) { 43 | ions <- which(ramclustObj$featclus == i) 44 | 45 | spectrum <- data.frame( 46 | 'mz' = round(0.99888*ramclustObj$fmz[ions], digits = 0), 47 | 'int' = round(ramclustObj$msint[ions], digits = 0) 48 | ) 49 | 50 | spectrum <- spectrum[order(spectrum[,"mz"], decreasing = FALSE), ] 51 | 52 | out <- paste0( 53 | "NAME: ", ramclustObj$cmpd[i], '\n', 54 | "PRECURSORTYPE: [M]+.", '\n', 55 | "IONMODE: ", ion.mode, '\n', 56 | "COLLISIONENERGY: 70", '\n', 57 | "SPECTRUMTYPE: Centroid", '\n', 58 | "RETENTIONTIME: ", round(ramclustObj$clrt[i], 2), '\n' 59 | ) 60 | 61 | if(any(names(ramclustObj)=="clri")) {paste0( 62 | out, 63 | "RETENTIONINDEX: ", round(ramclustObj$clri[i], 2), '\n' 64 | ) 65 | } 66 | 67 | out <- paste0(out, 68 | "PRECURSORMZ: ", round(max(spectrum[,1]),1), '\n' 69 | ) 70 | 71 | out <- paste0( 72 | out, 73 | "INSTRUMENTTYPE: GC-EI-Q", '\n', 74 | "INSTRUMENT: ", '\n', 75 | "Authors: ", '\n', 76 | "License: ", '\n', 77 | "FORMULA: ", '\n', 78 | "ONTOLOGY: ", '\n', 79 | "SMILES: ", '\n', 80 | "INCHIKEY: ", '\n', 81 | "INCHI: ", '\n', 82 | "METABOLITENAME: ", '\n', 83 | "SCANNUMBER: -1 ", '\n', 84 | "RETENTIONTIME: 0", '\n', 85 | "RETENTIONINDEX: 0", '\n', 86 | "CCS: 0", '\n', 87 | "INTENSITY: 0", '\n', 88 | "#Specific field for labeled experiment", '\n', 89 | "IsMarked: False", '\n' 90 | ) 91 | 92 | out <- paste0(out, 93 | "MSTYPE: MS1", '\n', "Num Peaks: 0", '\n' 94 | ) 95 | 96 | out <- paste0(out, 97 | "MSTYPE: MS2", '\n', 98 | "Num Peaks: ", nrow(spectrum), '\n' 99 | ) 100 | for(j in 1:nrow(spectrum)) { 101 | out <- paste0(out, 102 | spectrum[j,"mz"], 103 | " ", 104 | round(spectrum[j,"int"]), 105 | '\n' 106 | ) 107 | } 108 | out.list[[i]] <- out 109 | } 110 | 111 | for(i in 1:length(out.list)) { 112 | sink(paste0("spectra/mat/", ramclustObj$cmpd[[i]], ".mat")) 113 | cat(out.list[[i]], '\n') 114 | sink() 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /R/write.msp.R: -------------------------------------------------------------------------------- 1 | #' write.msp 2 | #' 3 | #' Cluster annotation function: inference of 'M' - molecular weight of the compound giving rise to each spectrum - using the InterpretMSSpectrum::findMain function 4 | #' 5 | #' @param ramclustObj ramclustR object to annotate. 6 | #' @param one.file logical, should all msp spectra be written to one file? If false, each spectrum is an individual file. 7 | #' @details exports files to a directory called 'spectra'. If one.file = FALSE, a new directory 'spectra/msp' is created to hold the individual msp files. if do.findman has been run, spectra are written as ms2 spectra, else as ms1. 8 | #' @return nothing, just exports files to the working directory 9 | #' @concept ramclustR 10 | #' @concept RAMClustR 11 | #' @concept metabolomics 12 | #' @concept mass spectrometry 13 | #' @concept clustering 14 | #' @concept interpretMSSpectrum 15 | #' @concept xcms 16 | #' @author Corey Broeckling 17 | #' @importFrom methods is 18 | #' @export 19 | #' 20 | 21 | write.msp <- function( 22 | ramclustObj = NULL, 23 | one.file = FALSE 24 | ) { 25 | 26 | if(!is(ramclustObj, "hclus") & 27 | ramclustObj$dist.method != "RAMClustR") { 28 | stop("this is not a RAMClustR object") 29 | } 30 | 31 | if(is.null(ramclustObj$precursor.mz)) { 32 | ms2 <- FALSE 33 | } else { 34 | ms2 <- TRUE 35 | } 36 | 37 | if(!dir.exists('spectra')) { 38 | dir.create('spectra') 39 | } 40 | 41 | if(!one.file) { 42 | if(!dir.exists('spectra/msp')) { 43 | dir.create('spectra/msp') 44 | } 45 | } 46 | ion.mode <- as.character(ramclustObj$ExpDes[[2]][which(row.names(ramclustObj$ExpDes[[2]]) == "msmode"),1]) 47 | if(toupper(substring(ion.mode, 1, 1)) == "P") { 48 | ion.mode = "Positive" 49 | } else { 50 | ion.mode = "Negative" 51 | } 52 | 53 | out.list <- as.list(rep(NA, length(ramclustObj$cmpd))) 54 | 55 | for(i in 1:length(ramclustObj$cmpd)) { 56 | ions <- which(ramclustObj$featclus == i) 57 | 58 | if(ms2) { 59 | spectrum <- data.frame( 60 | 'mz' = ramclustObj$fmz[ions], 61 | 'int' = ramclustObj$msmsint[ions] 62 | ) 63 | } else { 64 | spectrum <- data.frame( 65 | 'mz' = ramclustObj$fmz[ions], 66 | 'int' = ramclustObj$msint[ions] 67 | ) 68 | } 69 | 70 | spectrum <- spectrum[order(spectrum[,"int"], decreasing = TRUE), ] 71 | 72 | out <- paste0( 73 | "NAME:", ramclustObj$cmpd[i], '\n', 74 | "IONMODE:", ion.mode, '\n', 75 | "SPECTRUMTYPE:Centroid", '\n', 76 | "RETENTIONTIME:", round(ramclustObj$clrt[i], 2), '\n' 77 | ) 78 | 79 | ## bug fix 80 | if(any(names(ramclustObj)=="clri")) { 81 | out <- paste0( 82 | out, 83 | "RETENTIONINDEX:", round(ramclustObj$clri[i], 2), '\n' 84 | ) 85 | } 86 | 87 | if(ms2) { 88 | out <- paste0(out, 89 | "PRECURSORMZ:", ramclustObj$precursor.mz[i],'\n', 90 | "PRECURSORTYPE:", ramclustObj$precursor.type[i], '\n' 91 | ) 92 | } 93 | out <- paste0(out, 94 | "Num Peaks:", nrow(spectrum), '\n' 95 | # m/z intensity pair (tab, comma, space can be used as the delimiter.) 96 | ) 97 | for(j in 1:nrow(spectrum)) { 98 | out <- paste0(out, 99 | spectrum[j,"mz"], 100 | " ", 101 | round(spectrum[j,"int"]), 102 | '\n' 103 | ) 104 | } 105 | out.list[[i]] <- out 106 | } 107 | 108 | if(one.file) { 109 | out <- vector(mode = "character") 110 | for(i in 1:length(out.list)) { 111 | out <- paste0(out, out.list[[i]], '\n') 112 | } 113 | exp.name <- ramclustObj$ExpDes[[1]][which(row.names(ramclustObj$ExpDes[[1]]) == "Experiment"),1] 114 | if(nchar(exp.name) == 0) { 115 | exp.name <- "spectra" 116 | } 117 | sink(paste0("spectra/", exp.name, ".msp")) 118 | cat(out) 119 | sink() 120 | } else { 121 | for(i in 1:length(out.list)) { 122 | sink(paste0("spectra/msp/", ramclustObj$cmpd[[i]], ".msp")) 123 | cat(out.list[[i]], '\n') 124 | sink() 125 | } 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Codecov](https://img.shields.io/codecov/c/github/cbroeckl/RAMClustR) 2 | 3 | # RAMClustR: Mass Spectrometry Metabolomics Feature Clustering and Interpretation 4 | A feature clustering algorithm for non-targeted mass spectrometric metabolomics data. This method is compatible with gas and liquid chromatography coupled mass spectrometry, including indiscriminant tandem mass spectrometry data. 5 | 6 | ## Documentation for users 7 | 8 | ### Installation 9 | The newest version of the package can be installed through conda from the [bioconda](https://anaconda.org/bioconda/r-ramclustr) channel: 10 | 11 | ```bash 12 | conda install -c bioconda r-ramclustr 13 | ``` 14 | 15 | Or you can alternatively Install from R console: 16 | 17 | install.packages("devtools", repos="http://cran.us.r-project.org", dependencies=TRUE) 18 | 19 | library(devtools) 20 | 21 | install_github("cbroeckl/RAMClustR", build_vignettes = TRUE, dependencies = TRUE) 22 | 23 | library(RAMClustR) 24 | 25 | vignette("RAMClustR") 26 | 27 | ### Introduction 28 | Main clustering function output - see citation for algorithm description or vignette('RAMClustR') for a walk through. batch.qc. normalization requires input of three vectors (1) batch (2) order (3) qc. This is a feature centric normalization approach which adjusts signal intensities first by comparing batch median intensity of each feature (one feature at a time) QC signal intensity to full dataset median to correct for systematic batch effects and then secondly to apply a local QC median vs global median sample correction to correct for run order effects. 29 | 30 | There are two pathways for using RAMClustR; You can use either use the main ramclustR function or the individual stepwise workflow. 31 | 32 | Below is a small example of using main ramclustR function. 33 | ```R 34 | ## Choose input file with feature column names `mz_rt` (expected by default). 35 | ## Column with sample name is expected to be first (by default). 36 | ## These can be adjusted with the `featdelim` and `sampNameCol` parameters. 37 | wd <- getwd() 38 | filename <- file.path(wd, "testdata/peaks.csv") 39 | pheno <- file.path(wd, "testdata/phenoData.csv") 40 | print(filename) 41 | head(data.frame(read.csv(filename)), c(6L, 5L)) 42 | 43 | ## If the file contains features from MS1, assign those to the `ms` parameter. 44 | ## If the file contains features from MS2, assign those to the `idmsms` parameter. 45 | ## If you ran `xcms` for the feature detection, the assign the output to the `xcmsObj` parameter. 46 | ## In this example we use a MS1 feature table stored in a `csv` file. 47 | setwd(tempdir()) 48 | ramclustobj <- ramclustR( 49 | ms = filename, 50 | pheno_csv = pheno, 51 | st = 5, 52 | maxt = 1, 53 | blocksize = 1000 54 | ) 55 | 56 | ## Investigate the deconvoluted features in the `spectra` folder in MSP format 57 | ## or inspect the `ramclustobj` for feature retention times, annotations etc. 58 | print(ramclustobj$ann) 59 | print(ramclustobj$nfeat) 60 | print(ramclustobj$SpecAbund[,1:6]) 61 | setwd(wd) 62 | ``` 63 | 64 | #### Individual stepwise workflow 65 | ![alt text](https://github.com/zargham-ahmad/RAMClustR/blob/issue_14/docs/ramclustR.png) 66 | 67 | Below is a small example of using Individual stepwise workflow. 68 | ```R 69 | set.seed(123) # to get reproducible results with jitters 70 | wd <- getwd() 71 | tmp <- tempdir() 72 | load(file.path("testdata", "test.rc.ramclustr.fillpeaks")) 73 | 74 | setwd(tmp) 75 | 76 | ramclustObj <- rc.get.xcms.data(xcmsObj = xdata) 77 | ramclustObj <- rc.expand.sample.names(ramclustObj = ramclustObj) 78 | ramclustObj <- rc.feature.replace.na(ramclustObj = ramclustObj) 79 | ramclustObj <- rc.feature.filter.blanks(ramclustObj = ramclustObj, blank.tag = "Blanc") 80 | ramclustObj <- rc.feature.normalize.qc(ramclustObj = ramclustObj, qc.tag = "QC") 81 | ramclustObj <- rc.feature.filter.cv(ramclustObj = ramclustObj) 82 | ramclustObj <- rc.ramclustr(ramclustObj = ramclustObj) 83 | ramclustObj <- rc.qc(ramclustObj = ramclustObj) 84 | ramclustObj <- do.findmain(ramclustObj = ramclustObj) 85 | 86 | ## Investigate the deconvoluted features in the `spectra` folder in MSP format 87 | ## or inspect the `ramclustobj` for feature retention times, annotations etc. 88 | print(ramclustobj$ann) 89 | print(ramclustobj$nfeat) 90 | print(ramclustobj$SpecAbund[,1:6]) 91 | setwd(wd) 92 | ``` 93 | 94 | ## Documentation for developers 95 | 96 | ### Installation 97 | 98 | #### Developing with conda 99 | ```bash 100 | git clone https://github.com/cbroeckl/RAMClustR.git 101 | cd RAMClustR 102 | conda env create -n ramclustr-dev -f=conda/environment-dev.yaml 103 | conda activate ramclustr-dev 104 | ``` 105 | 106 | #### Developing with docker 107 | ```bash 108 | git clone https://github.com/cbroeckl/RAMClustR.git 109 | cd RAMClustR 110 | docker-compose build # To build the container 111 | docker-compose up -d # To start the container in detached mode 112 | docker exec -it ramclustr_container /bin/bash # To ssh into the container 113 | docker-compose down # To stop and remove the container along with its network 114 | ``` 115 | 116 | ### Testing 117 | ```R 118 | # Activate the ramclustr-dev environment 119 | # Run the below command on R console 120 | devtools::test() 121 | ``` 122 | 123 | ## References 124 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 125 | 126 | Broeckling CD, Ganna A, Layer M, Brown K, Sutton B, Ingelsson E, Peers G, Prenni JE. Enabling Efficient and Confident Annotation of LC-MS Metabolomics Data through MS1 Spectrum and Time Prediction. Anal Chem. 2016 Sep 20;88(18):9226-34. doi: 10.1021/acs.analchem.6b02479. Epub 2016 Sep 8. PubMed PMID: 7560453. 127 | 128 | -------------------------------------------------------------------------------- /conda/environment-dev.yaml: -------------------------------------------------------------------------------- 1 | name: ramclustr-dev 2 | channels: 3 | - conda-forge 4 | - bioconda 5 | - defaults 6 | dependencies: 7 | - r-base >=4.1 8 | - r-rlang >=1.1.0 9 | - r-devtools 10 | - r-biocmanager 11 | - r-dynamictreecut 12 | - r-fastcluster 13 | - r-gplots 14 | - r-ggplot2 15 | - bioconductor-msnbase 16 | - bioconductor-xcms 17 | - r-curl 18 | - r-stringi 19 | - r-jsonlite 20 | - r-xml2 21 | - r-e1071 22 | - r-interpretmsspectrum >=1.3.8 23 | - r-languageserver 24 | - r-testthat 25 | - r-readxl 26 | - radian 27 | - r-rmarkdown 28 | - qpdf 29 | - r-rhub 30 | - r-rentrez 31 | - r-covr 32 | - r-patrick -------------------------------------------------------------------------------- /conda/environment-test.yaml: -------------------------------------------------------------------------------- 1 | name: ramclustr-test 2 | channels: 3 | - conda-forge 4 | - bioconda 5 | - defaults 6 | dependencies: 7 | - r-base >=4.1 8 | - r-devtools 9 | - r-dynamictreecut 10 | - r-fastcluster 11 | - r-gplots 12 | - r-ggplot2 13 | - bioconductor-msnbase 14 | - bioconductor-xcms 15 | - r-curl 16 | - r-stringi 17 | - r-jsonlite 18 | - r-xml2 19 | - r-e1071 20 | - r-interpretmsspectrum >=1.3.8 21 | - r-testthat 22 | - r-readxl 23 | - r-rentrez 24 | - r-covr 25 | - r-patrick 26 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "cran-comments" 3 | output: html_document 4 | --- 5 | 6 | ```{r setup, include=FALSE} 7 | knitr::opts_chunk$set(echo = TRUE) 8 | ``` 9 | 10 | ## This document enables CRAN checks and describes results for record 11 | ```{cran check} 12 | 13 | ``` 14 | 15 | ## pasted output 16 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | services: 4 | ramclustr: 5 | build: 6 | context: . 7 | dockerfile: Dockerfile 8 | image: ramclustr:latest 9 | container_name: ramclustr_container 10 | volumes: 11 | - ./:/RAMClustR # Mount the local directory into the container 12 | working_dir: /RAMClustR 13 | stdin_open: true 14 | tty: true -------------------------------------------------------------------------------- /docs/ramclustR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/docs/ramclustR.png -------------------------------------------------------------------------------- /inst/extdata/featDefinition.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/inst/extdata/featDefinition.rds -------------------------------------------------------------------------------- /inst/extdata/featValues.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/inst/extdata/featValues.rds -------------------------------------------------------------------------------- /inst/extdata/phenoData.csv: -------------------------------------------------------------------------------- 1 | sample_name,class 2 | dataset_10908,sample 3 | dataset_10909,sample 4 | dataset_10910,sample 5 | -------------------------------------------------------------------------------- /inst/extdata/phenoData_df.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/inst/extdata/phenoData_df.rds -------------------------------------------------------------------------------- /inst/params/defparamsets.Rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/inst/params/defparamsets.Rdata -------------------------------------------------------------------------------- /inst/params/greek.csv: -------------------------------------------------------------------------------- 1 | english,greek 2 | Alpha,Α 3 | Beta,Β 4 | Gamma,Γ 5 | Delta,Δ 6 | Epsilon,Ε 7 | Zeta,Ζ 8 | Eta,Η 9 | Theta,Θ 10 | Iota,Ι 11 | Kappa,Κ 12 | Lambda,Λ 13 | Mu,Μ 14 | Nu,Ν 15 | Xi,Ξ 16 | Omicron,Ο 17 | Pi,Π 18 | Rho,Ρ 19 | Sigma,Σ 20 | Tau,Τ 21 | Upsilon,Υ 22 | Phi,Φ 23 | Chi,Χ 24 | Psi,Ψ 25 | Omega,Ω 26 | Alpha,α 27 | Beta,β 28 | Gamma,γ 29 | Delta,δ 30 | Epsilon,ε 31 | Zeta,ζ 32 | Eta,η 33 | Theta,θ 34 | Iota,ι 35 | Kappa,κ 36 | Lambda,λ 37 | Mu,μ 38 | Nu,ν 39 | Xi,ξ 40 | Omicron,ο 41 | Pi,π 42 | Rho,ρ 43 | Sigma,σ 44 | Tau,τ 45 | Upsilon,υ 46 | Phi,φ 47 | Chi,χ 48 | Psi,ψ 49 | Omega,ω 50 | Beta,ß 51 | , 52 | , 53 | -------------------------------------------------------------------------------- /inst/params/params.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/inst/params/params.csv -------------------------------------------------------------------------------- /inst/params/paramsets.Rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/inst/params/paramsets.Rdata -------------------------------------------------------------------------------- /man/RCQC.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RCQC.R 3 | \name{RCQC} 4 | \alias{RCQC} 5 | \title{RCQC} 6 | \usage{ 7 | RCQC( 8 | ramclustObj = NULL, 9 | qctag = "QC", 10 | npc = 4, 11 | scale = "pareto", 12 | which.data = "SpecAbund", 13 | outfile = "ramclustQC.pdf" 14 | ) 15 | } 16 | \arguments{ 17 | \item{ramclustObj}{ramclustR object to analyze} 18 | 19 | \item{qctag}{"QC" by default - rowname tag to identify QC samples} 20 | 21 | \item{npc}{number of Principle components to calcuate and plot} 22 | 23 | \item{scale}{"pareto" by default: PCA scaling method used} 24 | 25 | \item{which.data}{which dataset to use. "SpecAbund" by default} 26 | 27 | \item{outfile}{name of output pdf file.} 28 | } 29 | \value{ 30 | new RC object, with QC samples moved to new slot. prints output summary plots to pdf. 31 | } 32 | \description{ 33 | filter RC object and summarize quality control sample variation 34 | } 35 | \details{ 36 | plots a ramclustR summary plot. first page represents the correlation of each cluster to all other clusters, sorted by retention time. large blocks of yellow along the diaganol indicate either poor clustering or a group of coregulated metabolites with similar retention time. It is an imperfect diagnostic, particularly with lipids on reverse phase LC or sugars on HILIC LC systems. Page 2: histogram of r values from page 1 - only r values one position from the diagonal are used. Pages 3:5 - PCA results, with QC samples colored red. relative standard deviation calculated as sd(QC PC scores) / sd(all PC scores). Page 6: histogram of CV values for each compound int he dataset, QC samples only. 37 | } 38 | \references{ 39 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 40 | 41 | Broeckling CD, Ganna A, Layer M, Brown K, Sutton B, Ingelsson E, Peers G, Prenni JE. Enabling Efficient and Confident Annotation of LC-MS Metabolomics Data through MS1 Spectrum and Time Prediction. Anal Chem. 2016 Sep 20;88(18):9226-34. doi: 10.1021/acs.analchem.6b02479. Epub 2016 Sep 8. PubMed PMID: 7560453. 42 | } 43 | \author{ 44 | Corey Broeckling 45 | } 46 | \concept{MSFinder} 47 | \concept{RAMClustR} 48 | \concept{clustering} 49 | \concept{feature} 50 | \concept{mass spectrometry} 51 | \concept{metabolomics} 52 | \concept{ramclustR} 53 | \concept{xcms} 54 | -------------------------------------------------------------------------------- /man/add_params.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.replace.na.R 3 | \name{add_params} 4 | \alias{add_params} 5 | \title{add_params} 6 | \usage{ 7 | add_params(ramclustObj, params, param_name) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | 12 | \item{params}{vector containing parameters to add} 13 | 14 | \item{param_name}{name of the parameter/step} 15 | } 16 | \value{ 17 | ramclustR object with rc.feature.replace.na params added. 18 | } 19 | \description{ 20 | add rc.feature.replace.na params in ramclustObj 21 | } 22 | -------------------------------------------------------------------------------- /man/check_arguments_filter.blanks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.filter.blanks.R 3 | \name{check_arguments_filter.blanks} 4 | \alias{check_arguments_filter.blanks} 5 | \title{check_arguments_filter.blanks} 6 | \usage{ 7 | check_arguments_filter.blanks(ramclustObj, sn) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | 12 | \item{sn}{numeric defines the ratio for 'signal'. i.e. sn = 3 indicates that signal intensity must be 3 fold higher in sample than in blanks, on average, to be retained.} 13 | } 14 | \description{ 15 | check provided arguments 16 | } 17 | -------------------------------------------------------------------------------- /man/check_arguments_filter.cv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.filter.cv.R 3 | \name{check_arguments_filter.cv} 4 | \alias{check_arguments_filter.cv} 5 | \title{check_arguments_filter.cv} 6 | \usage{ 7 | check_arguments_filter.cv(ramclustObj, qc.tag) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | 12 | \item{qc.tag}{character vector of length one or two. If length is two, enter search string and factor name in $phenoData slot (i.e. c("QC", "sample.type"). If length one (i.e. "QC"), will search for this string in the 'sample.names' slot by default.} 13 | } 14 | \description{ 15 | check provided arguments 16 | } 17 | -------------------------------------------------------------------------------- /man/check_arguments_replace.na.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.replace.na.R 3 | \name{check_arguments_replace.na} 4 | \alias{check_arguments_replace.na} 5 | \title{check_arguments_replace.na} 6 | \usage{ 7 | check_arguments_replace.na( 8 | ramclustObj, 9 | replace.int, 10 | replace.noise, 11 | replace.zero 12 | ) 13 | } 14 | \arguments{ 15 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 16 | 17 | \item{replace.int}{default = 0.1. proportion of minimum feature value to replace NA (or zero) values with} 18 | 19 | \item{replace.noise}{default = 0.1. proportion ofreplace.int value by which noise is added via 'jitter'} 20 | 21 | \item{replace.zero}{logical if TRUE, any zero values are replaced with noise as if they were NA values} 22 | } 23 | \description{ 24 | check provided arguments 25 | } 26 | -------------------------------------------------------------------------------- /man/checks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.get.df.data.R 3 | \name{checks} 4 | \alias{checks} 5 | \title{checks} 6 | \usage{ 7 | checks( 8 | ms1_featureDefinitions = NULL, 9 | ms1_featureValues = NULL, 10 | ms2_featureValues = NULL, 11 | feature_names = NULL 12 | ) 13 | } 14 | \arguments{ 15 | \item{ms1_featureDefinitions}{dataframe with metadata with columns: mz, rt, feature names containing MS data} 16 | 17 | \item{ms1_featureValues}{dataframe with rownames = sample names, colnames = feature names containing MS data} 18 | 19 | \item{ms2_featureValues}{dataframe with rownames = sample names, colnames = feature names containing MSMS data} 20 | 21 | \item{feature_names}{feature names extracted from the data} 22 | } 23 | \description{ 24 | check if MS data contains mz and rt, and if MSMS data is present feature names and sample names are identical 25 | } 26 | -------------------------------------------------------------------------------- /man/compute_SpecAbundAve.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ramclustR.R 3 | \name{compute_SpecAbundAve} 4 | \alias{compute_SpecAbundAve} 5 | \title{compute_SpecAbundAve} 6 | \usage{ 7 | compute_SpecAbundAve(ramclustObj = NULL) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | } 12 | \value{ 13 | ramclustR object with aggregate by sample names for 'SpecAbundAve' dataset 14 | } 15 | \description{ 16 | further aggregate by sample names for 'SpecAbundAve' dataset 17 | } 18 | -------------------------------------------------------------------------------- /man/compute_do.sets.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.filter.cv.R 3 | \name{compute_do.sets} 4 | \alias{compute_do.sets} 5 | \title{compute_do.sets} 6 | \usage{ 7 | compute_do.sets(ramclustObj) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | } 12 | \value{ 13 | vector which is used to select data frame to use in ramclustObj 14 | } 15 | \description{ 16 | compute data frame to use in ramclustObj 17 | } 18 | -------------------------------------------------------------------------------- /man/compute_wt_mean.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.get.csv.data.R 3 | \name{compute_wt_mean} 4 | \alias{compute_wt_mean} 5 | \title{compute_wt_mean} 6 | \usage{ 7 | compute_wt_mean(data, global.min, fmz, ensure.no.na) 8 | } 9 | \arguments{ 10 | \item{data}{feature in ms/msms level data} 11 | 12 | \item{global.min}{minimum intensity in ms/msms level data} 13 | 14 | \item{fmz}{feature retention time} 15 | 16 | \item{ensure.no.na}{logical: if TRUE, any 'NA' values in msint and/or msmsint are replaced with numerical values based on 10 percent of feature min plus noise. Used to ensure that spectra are not written with NA values.} 17 | } 18 | \value{ 19 | weighted.mean intensity of feature in ms/msms level data 20 | } 21 | \description{ 22 | compute weighted.mean intensity of feature in ms/msms level data 23 | } 24 | -------------------------------------------------------------------------------- /man/create_ramclustObj.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.get.df.data.R 3 | \name{create_ramclustObj} 4 | \alias{create_ramclustObj} 5 | \title{create_ramclustObj} 6 | \usage{ 7 | create_ramclustObj( 8 | ExpDes = NULL, 9 | input_history = NULL, 10 | MSdata = NULL, 11 | MSMSdata = NULL, 12 | frt = NULL, 13 | fmz = NULL, 14 | st = NULL, 15 | phenoData = NULL, 16 | feature_names = NULL, 17 | sample_names = NULL, 18 | xcmsOrd = NULL, 19 | ensure.no.na = TRUE 20 | ) 21 | } 22 | \arguments{ 23 | \item{ExpDes}{either an R object created by R ExpDes object: data used for record keeping and labelling msp spectral output} 24 | 25 | \item{input_history}{input history} 26 | 27 | \item{MSdata}{dataframe containing MS Data} 28 | 29 | \item{MSMSdata}{dataframe containing MSMS Data} 30 | 31 | \item{frt}{feature retention time, in whatever units were fed in} 32 | 33 | \item{fmz}{feature retention time} 34 | 35 | \item{st}{numeric: sigma t - time similarity decay value} 36 | 37 | \item{phenoData}{dataframe containing phenoData} 38 | 39 | \item{feature_names}{feature names extracted from the data} 40 | 41 | \item{sample_names}{sample names extracted from the data} 42 | 43 | \item{xcmsOrd}{original xcms order of features, for back-referencing when necessary} 44 | 45 | \item{ensure.no.na}{logical: if TRUE, any 'NA' values in msint and/or msmsint are replaced with numerical values based on 10 percent of feature min plus noise. Used to ensure that spectra are not written with NA values.} 46 | } 47 | \value{ 48 | an ramclustR object. this object is formatted as an hclust object with additional slots for holding feature and compound data. 49 | } 50 | \description{ 51 | create ramclustr Object 52 | } 53 | -------------------------------------------------------------------------------- /man/defineExperiment.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/defineExperiment.R 3 | \name{defineExperiment} 4 | \alias{defineExperiment} 5 | \title{defineExperiment} 6 | \usage{ 7 | defineExperiment(csv = FALSE, force.skip = FALSE) 8 | } 9 | \arguments{ 10 | \item{csv}{logical or filepath. If csv = TRUE , csv template called "ExpDes.csv" will be written to your working directory. you will fill this in manually, ensuring that when you save you retain csv format. ramclustR will then read this file in and and format appropriately. If csv = FALSE, a pop up window will appear (in windows, at least) asking for input. If a character string with full path (and file name) to a csv file is given, this will allow you to read in a previously edited csv file.} 11 | 12 | \item{force.skip}{logical. If TRUE, ramclustR creates a pseudo-filled ExpDes object to enable testing of functionality. Not recommended for real data, as your exported spectra will be improperly labelled.} 13 | } 14 | \value{ 15 | an Exp Des R object which will be used for record keeping and writing spectra data. 16 | } 17 | \description{ 18 | Create an Experimental Design R object for record-keeping and msp output 19 | } 20 | \references{ 21 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 22 | 23 | Broeckling CD, Ganna A, Layer M, Brown K, Sutton B, Ingelsson E, Peers G, Prenni JE. Enabling Efficient and Confident Annotation of LC-MS Metabolomics Data through MS1 Spectrum and Time Prediction. Anal Chem. 2016 Sep 20;88(18):9226-34. doi: 10.1021/acs.analchem.6b02479. Epub 2016 Sep 8. PubMed PMID: 7560453. 24 | } 25 | \author{ 26 | Corey Broeckling 27 | } 28 | \concept{MSFinder} 29 | \concept{RAMClustR} 30 | \concept{clustering} 31 | \concept{feature} 32 | \concept{mass spectrometry} 33 | \concept{metabolomics} 34 | \concept{ramlclustR} 35 | \concept{xcms} 36 | -------------------------------------------------------------------------------- /man/define_samples.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.filter.cv.R 3 | \name{define_samples} 4 | \alias{define_samples} 5 | \title{define_samples} 6 | \usage{ 7 | define_samples(ramclustObj, tag, return.logical = FALSE) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | 12 | \item{tag}{character vector of length one or two. If length is two, enter search string and factor name in $phenoData slot (i.e. c("QC", "sample.type"). If length one (i.e. "QC"), will search for this string in the 'sample.names' slot by default.} 13 | 14 | \item{return.logical}{optionally convert numeric vector with length equal to the number of matched samples to a logical vector of length equal to number of samples, with TRUE representing matching samples.} 15 | } 16 | \value{ 17 | samples found using the tag 18 | } 19 | \description{ 20 | define samples in each set 21 | } 22 | -------------------------------------------------------------------------------- /man/do.findmain.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/do.findmain.R 3 | \name{do.findmain} 4 | \alias{do.findmain} 5 | \title{do.findmain} 6 | \usage{ 7 | do.findmain( 8 | ramclustObj = NULL, 9 | cmpd = NULL, 10 | mode = "positive", 11 | mzabs.error = 0.005, 12 | ppm.error = 10, 13 | ads = NULL, 14 | nls = NULL, 15 | scoring = "auto", 16 | plot.findmain = TRUE, 17 | writeMat = TRUE, 18 | writeMS = TRUE, 19 | use.z = TRUE 20 | ) 21 | } 22 | \arguments{ 23 | \item{ramclustObj}{ramclustR object to annotate.} 24 | 25 | \item{cmpd}{integer: vector defining compound numbers to annotated. if NULL (default), all compounds} 26 | 27 | \item{mode}{character: "positive" or "negative"} 28 | 29 | \item{mzabs.error}{numeric: absolute mass deviation allowd, default = 0.01} 30 | 31 | \item{ppm.error}{numeric: ppm mass error _added_ to mzabs.error, default = 10} 32 | 33 | \item{ads}{character: vector of allowed adducts, i.e. c("[M+H]+"). if NULL, default positive mode values of H+, Na+, K+, and NH4+, as monomer, dimer, and trimer, are assigned. Negative mode include "[M-H]-", "[M+Na-2H]-", "[M+K-2H]-", "[M+CH2O2-H]-" as monomer, dimer, and trimer.} 34 | 35 | \item{nls}{character: vector of allowed neutral losses, i.e. c("[M+H-H2O]+"). if NULL, an extensive list derived from CAMERA's will be used.} 36 | 37 | \item{scoring}{character: one of 'imss' , 'ramclustr', or 'auto'. default = 'auto'. see details.} 38 | 39 | \item{plot.findmain}{logical: should pdf polts be generated for evaluation? detfault = TRUE. PDF saved to working.directory/spectra} 40 | 41 | \item{writeMat}{logical: should individual .mat files (for MSFinder) be generated in a 'mat' subdirectory in the 'spectra' folder? default = TRUE.} 42 | 43 | \item{writeMS}{logical: should individual .ms files (for Sirius) be generated in a 'ms' subdirectory in the 'spectra' folder? default = TRUE. Note that no import functions are yet written for Sirius output.} 44 | 45 | \item{use.z}{logical: if you have previously run the 'assign.z' function from ramclustR, there will be a slot reflecting the feature mass after accounting for charge (fm) - if TRUE this is used instead of feature m/z (fmz) in interpreting MS data and exporting spectra for annotation.} 46 | } 47 | \value{ 48 | $M: The inferred molecular weight of the compound giving rise to the each spectrum 49 | 50 | $M.ppm: The ppm error of all the MS signals annotated, high error values should be considered 'red flags'. 51 | 52 | $M.ann: The annotated spectrum supporting the interpretation of M 53 | 54 | $use.findmain: Logical vector indicating whether findmain scoring (TRUE) or ramclustR scoring (FALSE) was used to support inference of M. By default, findmain scoring is used. When ramclustR scoring differs from findmain scoring, the scoring metric which predicts higher M is selected. 55 | 56 | $M.ramclustr: M selected using ramclustR scoring 57 | 58 | $M.ppm.ramclustr: ppm error of M selected using ramclustR scoring. Used to resolve concflicts between ramclustR and findmain M assignment when scoring = auto. 59 | 60 | $M.ann.ramclustr: annotated spectrum supporting M using ramclustR scoring 61 | 62 | $M.nann.ramclustr: number of masses annotated using ramclustR scoring. Used to resolve concflicts between ramclustR and findmain M assignment when scoring = auto. 63 | 64 | $M.space.ramclustr: the 'space' of scores between the best and second best ramclustR scores. Calculated as a ratio. Used to resolve concflicts between ramclustR and findmain M assignment when scoring = auto. 65 | 66 | $M.findmain: M selected using findmain scoring 67 | 68 | $M.ppm.findmain: ppm error of M selected using findmain scoring. Used to resolve concflicts between ramclustR and findmain M assignment when scoring = auto. 69 | 70 | $M.ann.findmain: annotated spectrum supporting M using findmain scoring 71 | 72 | $M.nann.findmain: number of masses annotated using findmain scoring. Used to resolve concflicts between ramclustR and findmain M assignment when scoring = auto. 73 | 74 | $M.space.findmain: the 'space' of scores between the best and second best findmain scores. Calculated as a ratio. Used to resolve concflicts between ramclustR and findmain M assignment when scoring = auto. 75 | } 76 | \description{ 77 | Cluster annotation function: inference of 'M' - molecular weight of the compound giving rise to each spectrum - using the InterpretMSSpectrum::findMain function 78 | } 79 | \details{ 80 | a partially annotated ramclustR object. base structure is that of a standard R heirarchical clustering output, with additional slots described in ramclustR documentation (?ramclustR). New slots added after using the interpretMSSpectrum functionality include those described below. 81 | } 82 | \references{ 83 | Jaeger C, ... Lisec J. Compound annotation in liquid chromatography/high-resolution mass spectrometry based metabolomics: robust adduct ion determination as a prerequisite to structure prediction in electrospray ionization mass spectra. Rapid Commun Mass Spectrom. 2017 Aug 15;31(15):1261-1266. doi: 10.1002/rcm.7905. PubMed PMID: 28499062. 84 | 85 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 86 | 87 | Broeckling CD, Ganna A, Layer M, Brown K, Sutton B, Ingelsson E, Peers G, Prenni JE. Enabling Efficient and Confident Annotation of LC-MS Metabolomics Data through MS1 Spectrum and Time Prediction. Anal Chem. 2016 Sep 20;88(18):9226-34. doi: 10.1021/acs.analchem.6b02479. Epub 2016 Sep 8. PubMed PMID: 7560453. 88 | } 89 | \author{ 90 | Corey Broeckling 91 | } 92 | \concept{RAMClustR} 93 | \concept{clustering} 94 | \concept{feature} 95 | \concept{findMain} 96 | \concept{interpretMSSpectrum} 97 | \concept{mass spectrometry} 98 | \concept{metabolomics} 99 | \concept{ramclustR} 100 | \concept{xcms} 101 | -------------------------------------------------------------------------------- /man/exportDataset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/exportDataset.R 3 | \name{exportDataset} 4 | \alias{exportDataset} 5 | \title{exportDataset} 6 | \usage{ 7 | exportDataset( 8 | ramclustObj = NULL, 9 | which.data = "SpecAbund", 10 | label.by = "cmpd", 11 | appendFactors = TRUE 12 | ) 13 | } 14 | \arguments{ 15 | \item{ramclustObj}{ramclustR object to export from} 16 | 17 | \item{which.data}{name of dataset to export. SpecAbund, SpecAbundAve, MSdata, or MSMSdata} 18 | 19 | \item{label.by}{either 'ann' or 'cmpd', generally. name of ramclustObj slot used as csv header for each column (compound)} 20 | 21 | \item{appendFactors}{logical. If TRUE (default) the factor data frame is appended to the left side of the dataset.} 22 | } 23 | \value{ 24 | nothing is returned. file exported as csf to 'datasets/*.csv' 25 | } 26 | \description{ 27 | export one of 'SpecAbund', 'SpecAbundAve', 'MSdata' or 'MSMSdata' from an RC object to csv 28 | } 29 | \details{ 30 | Useful for exporting the processed signal intensity matrix to csv for analysis elsewhere. 31 | } 32 | \references{ 33 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 34 | } 35 | \author{ 36 | Corey Broeckling 37 | } 38 | \concept{RAMClustR} 39 | \concept{ramclustR} 40 | -------------------------------------------------------------------------------- /man/filter_blanks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.filter.blanks.R 3 | \name{filter_blanks} 4 | \alias{filter_blanks} 5 | \title{filter_blanks} 6 | \usage{ 7 | filter_blanks(ramclustObj, keep, d1) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | 12 | \item{keep}{union of which signal is at least 3x larger, output of filter_signal()} 13 | 14 | \item{d1}{MS Data} 15 | } 16 | \value{ 17 | ramclustObj object with feature.filter.blanks 18 | } 19 | \description{ 20 | filter blanks 21 | } 22 | -------------------------------------------------------------------------------- /man/filter_good_features.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.filter.cv.R 3 | \name{filter_good_features} 4 | \alias{filter_good_features} 5 | \title{filter_good_features} 6 | \usage{ 7 | filter_good_features(ramclustObj, keep) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | 12 | \item{keep}{features to keep. output of find_good_features().} 13 | } 14 | \value{ 15 | ramclustR object filtered to keep only 'good' features 16 | } 17 | \description{ 18 | filter to keep only 'good' features 19 | } 20 | -------------------------------------------------------------------------------- /man/filter_signal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.filter.blanks.R 3 | \name{filter_signal} 4 | \alias{filter_signal} 5 | \title{filter_signal} 6 | \usage{ 7 | filter_signal(ms.qc.mean, ms.blank.mean, sn) 8 | } 9 | \arguments{ 10 | \item{ms.qc.mean}{ms qc mean signal intensities} 11 | 12 | \item{ms.blank.mean}{ms blank mean signal intensities} 13 | 14 | \item{sn}{numeric defines the ratio for 'signal'. i.e. sn = 3 indicates that signal intensity must be 3 fold higher in sample than in blanks, on average, to be retained.} 15 | } 16 | \value{ 17 | union of which signal is at least 3x larger 18 | } 19 | \description{ 20 | filter signal 21 | } 22 | -------------------------------------------------------------------------------- /man/find_good_features.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.filter.cv.R 3 | \name{find_good_features} 4 | \alias{find_good_features} 5 | \title{find_good_features} 6 | \usage{ 7 | find_good_features(ramclustObj, do.sets, max.cv, qc) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | 12 | \item{do.sets}{select data frame to use.} 13 | 14 | \item{max.cv}{numeric maximum allowable cv for any feature. default = 0.5} 15 | 16 | \item{qc}{QC samples found by define_samples} 17 | } 18 | \value{ 19 | ramclustR object 20 | 21 | features to keep 22 | } 23 | \description{ 24 | find 'good' features, acceptable CV at either MS or MSMS level results in keeping 25 | } 26 | -------------------------------------------------------------------------------- /man/findfeature.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findfeature.R 3 | \name{findfeature} 4 | \alias{findfeature} 5 | \title{findfeature} 6 | \usage{ 7 | findfeature( 8 | ramclustObj = NULL, 9 | mz = NULL, 10 | mztol = 0.02, 11 | rt = NULL, 12 | rttol = 2, 13 | iso.rttol = 2, 14 | zmax = 6, 15 | m.check = TRUE 16 | ) 17 | } 18 | \arguments{ 19 | \item{ramclustObj}{R object: the ramclustR object to explore} 20 | 21 | \item{mz}{numeric: mz value to search for} 22 | 23 | \item{mztol}{numeric: absolute mass tolerance around mz} 24 | 25 | \item{rt}{numeric: optional rt value to search for (generally in seconds, though use whatever units your data is in)} 26 | 27 | \item{rttol}{numeric: absolute retention time tolerance around rt.} 28 | 29 | \item{iso.rttol}{numeric: when examining isotope patterns, feature retention time tolerance around features matching mz +- mztol} 30 | 31 | \item{zmax}{integer: maximum charge state to consider. default is 6.} 32 | 33 | \item{m.check}{logical: check whether the matching masses are plausibly M0. That is, we look for ions 1 proton mass (from charge state 1:zmax) below the target m/z at the same time that have intensities consistent with target ion being a non-M0 isotope.} 34 | } 35 | \value{ 36 | returns a table to the console listing masses which match, their retention time and intensity, and whether it appears to be plausible as M0 37 | } 38 | \description{ 39 | see if any features match a given mass, and whether they are plausibly M0 40 | } 41 | \details{ 42 | a convenience function to perform a targeted search of all features for a mass of interest. Also performs a crude plausibility check as to whether the matched feature could be M0, based on the assumption of approximately 1 carbon per 17 m/z units and natural isotopic abundance of 1.1% 13C. Note that this function returns the cluster to which the feature is assigned, but that the M0_plausibility is independent of cluster membership. 43 | } 44 | \author{ 45 | Corey Broeckling 46 | } 47 | \concept{MSFinder} 48 | \concept{RAMClustR} 49 | \concept{clustering} 50 | \concept{feature} 51 | \concept{mass spectrometry} 52 | \concept{metabolomics} 53 | \concept{ramclustR} 54 | \concept{xcms} 55 | -------------------------------------------------------------------------------- /man/findmass.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/findmass.R 3 | \name{findmass} 4 | \alias{findmass} 5 | \title{findmass} 6 | \usage{ 7 | findmass( 8 | ramclustObj = NULL, 9 | mz = NULL, 10 | mztol = 0.02, 11 | rttol = 2, 12 | zmax = 6, 13 | m.check = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{ramclustObj}{R object: the ramclustR object to explore} 18 | 19 | \item{mz}{numeric: mz value to search for} 20 | 21 | \item{mztol}{numeric: absolute mass tolerance around mz} 22 | 23 | \item{rttol}{numeric: when examining isotope patterns, feature retention time tolerance around features matching mz +- mztol} 24 | 25 | \item{zmax}{integer: maximum charge state to consider. default is 6.} 26 | 27 | \item{m.check}{logical: check whether the matching masses are plausibly M0. That is, we look for ions 1 proton mass (from charge state 1:zmax) below the target m/z at the same time that have intensities consistent with target ion being a non-M0 isotope.} 28 | } 29 | \value{ 30 | returns a table to the console listing masses which match, their retention time and intensity, and whether it appears to be plausible as M0 31 | } 32 | \description{ 33 | see if any features match a given mass, and whether they are plausibly M0 34 | } 35 | \details{ 36 | a convenience function to perform a targeted search of all feaures for a mass of interest. Also performs a crude plausibility check as to whether the matched feature could be M0, based on the assumption of approximately 1 carbon per 17 m/z units and natural isotopic abundance of 1.1% 13C. Note that this function returns the cluster to which the feature is assigned, but that the M0_plausibility is independent of cluster membership. 37 | } 38 | \author{ 39 | Corey Broeckling 40 | } 41 | \concept{MSFinder} 42 | \concept{RAMClustR} 43 | \concept{clustering} 44 | \concept{feature} 45 | \concept{mass spectrometry} 46 | \concept{metabolomics} 47 | \concept{ramclustR} 48 | \concept{xcms} 49 | -------------------------------------------------------------------------------- /man/getData.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/getData.R 3 | \name{getData} 4 | \alias{getData} 5 | \title{getData} 6 | \usage{ 7 | getData( 8 | ramclustObj = NULL, 9 | which.data = "SpecAbund", 10 | delim = "-", 11 | cmpdlabel = "cmpd", 12 | filter = FALSE 13 | ) 14 | } 15 | \arguments{ 16 | \item{ramclustObj}{ramclustR object to retrieve data from} 17 | 18 | \item{which.data}{character; which dataset (SpecAbund or SpecAbundAve) to reference} 19 | 20 | \item{delim}{character; "-" by default - the delimiter for parsing sample names to factors} 21 | 22 | \item{cmpdlabel}{= "cmpd"; label the data with the annotation. can also be set to 'ann' for column names assigned as annotatins.} 23 | 24 | \item{filter}{= TRUE; logical, if TRUE, checks for $cmpd.use slot generated by rc.cmpd.cv.filter() function, and only gets acceptable compounds.} 25 | } 26 | \value{ 27 | returns a list of length 3: $design is the experimental sample factors after parsing by the delim, $data is the dataset, $full.data is merged $des and $data data.frames. 28 | } 29 | \description{ 30 | retrieve and parse sample names, retrieve metabolite data. returns as list of two data frames 31 | } 32 | \details{ 33 | convenience function for parsing sample names and returning a dataset. 34 | } 35 | \author{ 36 | Corey Broeckling 37 | } 38 | \concept{RAMClustR} 39 | -------------------------------------------------------------------------------- /man/getSampleMetadata.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.get.xmcs.data.R 3 | \name{getSampleMetadata} 4 | \alias{getSampleMetadata} 5 | \title{Extract Sample Metadata from an xcms Object} 6 | \usage{ 7 | getSampleMetadata(xcmsObj) 8 | } 9 | \arguments{ 10 | \item{xcmsObj}{An xcms object containing chromatographic and metadata information. 11 | This object is typically generated during preprocessing of 12 | metabolomics data using the xcms package.} 13 | } 14 | \value{ 15 | A data frame or list containing the sample metadata extracted from the xcms object. 16 | The structure and content of the returned metadata depend on the input xcms object. 17 | } 18 | \description{ 19 | This function retrieves sample metadata from a provided xcms object. 20 | } 21 | \details{ 22 | This function is designed to facilitate the extraction of metadata 23 | associated with samples in an xcms object. The metadata may include 24 | information such as sample names, injection order, batch information, 25 | and other experimental details. 26 | } 27 | \concept{xcms} 28 | -------------------------------------------------------------------------------- /man/get_ExpDes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/defineExperiment.R 3 | \name{get_ExpDes} 4 | \alias{get_ExpDes} 5 | \title{get_ExpDes} 6 | \usage{ 7 | get_ExpDes(csv.in) 8 | } 9 | \arguments{ 10 | \item{csv.in}{Experimental Design read from csv} 11 | } 12 | \value{ 13 | list containing design and instrument 14 | } 15 | \description{ 16 | get Experimental Design 17 | } 18 | -------------------------------------------------------------------------------- /man/get_instrument_platform.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/defineExperiment.R 3 | \name{get_instrument_platform} 4 | \alias{get_instrument_platform} 5 | \title{get_instrument_platform} 6 | \usage{ 7 | get_instrument_platform(design) 8 | } 9 | \arguments{ 10 | \item{design}{data frame containing Experimental Design} 11 | } 12 | \value{ 13 | instrument platform 14 | } 15 | \description{ 16 | get instrument platform 17 | } 18 | -------------------------------------------------------------------------------- /man/mean_signal_intensities.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.filter.blanks.R 3 | \name{mean_signal_intensities} 4 | \alias{mean_signal_intensities} 5 | \title{mean_signal_intensities} 6 | \usage{ 7 | mean_signal_intensities(data, sample) 8 | } 9 | \arguments{ 10 | \item{data}{MS/MSMS data} 11 | 12 | \item{sample}{sample found using the tag, output of define_samples()} 13 | } 14 | \value{ 15 | mean signal intensities 16 | } 17 | \description{ 18 | calculate MS mean signal intensities 19 | } 20 | -------------------------------------------------------------------------------- /man/mergeRCobjects.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mergeRCobjects.R 3 | \name{mergeRCobjects} 4 | \alias{mergeRCobjects} 5 | \title{mergeRCobjects} 6 | \usage{ 7 | mergeRCobjects( 8 | ramclustObj.1 = NULL, 9 | ramclustObj.2 = NULL, 10 | mztol = 0.02, 11 | rttol = 30, 12 | course.rt.adj = NULL, 13 | mzwt = 2, 14 | rtwt = 1, 15 | intwt = 3 16 | ) 17 | } 18 | \arguments{ 19 | \item{ramclustObj.1}{ramclustR object 1: this object will be the base for the new object. That is all the features from ramclustObj.1 will be retained.} 20 | 21 | \item{ramclustObj.2}{ramclustR object 2: this object will mapped and appended to racmlustObj1. That is only features which appear consistent with those from ramclustObj.1 will be retained.} 22 | 23 | \item{mztol}{numeric: absolute mass tolerance around mz} 24 | 25 | \item{rttol}{numeric: feature retention time tolerance. Value set by this option will be used during the initial anchor mapping phase. Two times the standard error of the rt loess correction will be used for the full mapping.} 26 | 27 | \item{course.rt.adj}{numeric: default = NULL. optional approximate retention time shift between ramclustObj.1 and ramclustObj.2. i.e if the retention time of ramclustObj.1 is on average 15 seconds longer than that of ramclustobj.2, enter '15'. if 1 is less than 2, enter a negative number. This is applied before mapping to enable a smaller 'rttol' value to be used.} 28 | 29 | \item{mzwt}{numeric: when mapping features, weighting value used for similarities between feature mass values (see rtwt, intwt)} 30 | 31 | \item{rtwt}{numeric: when mapping features, weighting value used for similarities between feature retention time values (see mzwt, intwt)} 32 | 33 | \item{intwt}{numeric: when mapping features, weighting value used for similarities between ranked signal intensity values (see rtwt, mzwt)} 34 | } 35 | \value{ 36 | returns a ramclustR object. All values from ramclustObj.1 are retained. SpecAbund dataset from ramclustObj.1 is moved to RC$SpecAbund.1, where RC is the new ramclustObj. 37 | } 38 | \description{ 39 | merge two ramclustR objects 40 | } 41 | \details{ 42 | Two ramclustR objects are merged with this function, mapping features between them. The first (ramclustObj.1) object use used as the template - all data in it is retained. ramclustObj.2 is mapped to ramclustObj.1 feature by feature - only mapped features are retained. A new ramlcustObj is returned, with a new SpecAbund dataset with the same column number as the ramclustObj.1$SpecAbund set. 43 | } 44 | \author{ 45 | Corey Broeckling 46 | } 47 | \concept{RAMClustR} 48 | \concept{clustering} 49 | \concept{feature} 50 | \concept{mass spectrometry} 51 | \concept{metabolomics} 52 | \concept{ramclustR} 53 | -------------------------------------------------------------------------------- /man/normalized_data_batch_qc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.normalize.batch.qc.R 3 | \name{normalized_data_batch_qc} 4 | \alias{normalized_data_batch_qc} 5 | \title{normalized_data_batch_qc} 6 | \usage{ 7 | normalized_data_batch_qc( 8 | data = NULL, 9 | batch = NULL, 10 | order = NULL, 11 | qc = NULL, 12 | qc.inj.range = 20, 13 | output.plot = FALSE 14 | ) 15 | } 16 | \arguments{ 17 | \item{data}{feature in ms/msms level data} 18 | 19 | \item{batch}{integer vector with length equal to number of injections in xset or csv file or dataframe} 20 | 21 | \item{order}{integer vector with length equal to number of injections in xset or csv file or dataframe} 22 | 23 | \item{qc}{logical vector with length equal to number of injections in xset or csv file or dataframe} 24 | 25 | \item{qc.inj.range}{integer: how many injections around each injection are to be scanned for presence of QC samples when using batch.qc normalization? A good rule of thumb is between 1 and 3 times the typical injection span between QC injections. i.e. if you inject QC ever 7 samples, set this to between 7 and 21. smaller values provide more local precision but make normalization sensitive to individual poor outliers (though these are first removed using the boxplot function outlier detection), while wider values provide less local precision in normalization but better stability to individual peak areas.} 26 | 27 | \item{output.plot}{logical set to TRUE to store plots} 28 | } 29 | \value{ 30 | normalized data. 31 | } 32 | \description{ 33 | normalize data using batch.qc 34 | } 35 | -------------------------------------------------------------------------------- /man/normalized_data_tic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.normalize.tic.R 3 | \name{normalized_data_tic} 4 | \alias{normalized_data_tic} 5 | \title{normalized_data_tic} 6 | \usage{ 7 | normalized_data_tic(ramclustObj = NULL) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | } 12 | \value{ 13 | ramclustR object with total extracted ion normalized data. 14 | } 15 | \description{ 16 | normalize data using TIC 17 | } 18 | -------------------------------------------------------------------------------- /man/order_datasets.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.normalize.batch.qc.R 3 | \name{order_datasets} 4 | \alias{order_datasets} 5 | \title{order_datasets} 6 | \usage{ 7 | order_datasets(order = NULL, batch = NULL, qc = NULL, data = NULL) 8 | } 9 | \arguments{ 10 | \item{order}{integer vector with length equal to number of injections in xset or csv file or dataframe} 11 | 12 | \item{batch}{integer vector with length equal to number of injections in xset or csv file or dataframe} 13 | 14 | \item{qc}{logical vector with length equal to number of injections in xset or csv file or dataframe} 15 | 16 | \item{data}{feature in ms/msms level data} 17 | } 18 | \value{ 19 | ordered feature in ms/msms level data, order, batch, qc 20 | } 21 | \description{ 22 | order the datasets first by batch and run order 23 | } 24 | -------------------------------------------------------------------------------- /man/rc.calibrate.ri.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.calibrate.ri.R 3 | \name{rc.calibrate.ri} 4 | \alias{rc.calibrate.ri} 5 | \title{rc.calibrate.ri} 6 | \usage{ 7 | rc.calibrate.ri(ramclustObj = NULL, calibrant.data = "", poly.order = 3) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | 12 | \item{calibrant.data}{character vector defining the file path/name to a csv file containing columns including 'rt', and 'ri'. Alternatively, a data.frame with those columnn names (case sensitive)} 13 | 14 | \item{poly.order}{integer default = 3. polynomical order used to fit rt vs ri data, and calculate ri for all feature and metabolite rt values. poly.order should be apprciably smaller than the number of calibrant points.} 15 | } 16 | \value{ 17 | ramclustR object with retention index assigned for features ($fri) and compounds ($clri). 18 | } 19 | \description{ 20 | extractor for xcms objects in preparation for clustering 21 | } 22 | \details{ 23 | This function generates a new slot in the ramclustR object for retention index. Calibration is performed using a polynomial fit of order poly.order. It is the user's responsibility to ensure that the number and span of calibrant points is sufficient to calibrate the full range of feature and compound retention times. i.e. if the last calibration point is at 1000 seconds, but the last eluting peak is at 1300 seconds, the calibration will be very poor for the late eluting compound. 24 | } 25 | \references{ 26 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 27 | } 28 | \author{ 29 | Corey Broeckling 30 | } 31 | \concept{MSFinder} 32 | \concept{RAMClustR} 33 | \concept{clustering} 34 | \concept{feature} 35 | \concept{mass spectrometry} 36 | \concept{metabolomics} 37 | \concept{ramclustR} 38 | \concept{xcms} 39 | -------------------------------------------------------------------------------- /man/rc.cmpd.filter.blanks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.cmpd.filter.blanks.R 3 | \name{rc.cmpd.filter.blanks} 4 | \alias{rc.cmpd.filter.blanks} 5 | \title{rc.cmpd.filter.blanks} 6 | \usage{ 7 | rc.cmpd.filter.blanks( 8 | ramclustObj = NULL, 9 | qc.tag = "QC", 10 | blank.tag = "blank", 11 | sn = 3, 12 | remove.blanks = TRUE 13 | ) 14 | } 15 | \arguments{ 16 | \item{ramclustObj}{ramclustObj containing SpecAbund dataframe.} 17 | 18 | \item{qc.tag}{character vector of length one or two. If length is two, enter search string and factor name in $phenoData slot (i.e. c("QC", "sample.type"). If length one (i.e. "QC"), will search for this string in the 'sample.names' slot by default.} 19 | 20 | \item{blank.tag}{see 'qc.tag' , but for blanks to use as background.} 21 | 22 | \item{sn}{numeric defines the ratio for 'signal'. i.e. sn = 3 indicates that signal intensity must be 3 fold higher in sample than in blanks, on average, to be retained.} 23 | 24 | \item{remove.blanks}{logical. TRUE by default. this removes any recognized blanks samples from the SpecAbund sets after they are used to filter contaminant compounds} 25 | } 26 | \value{ 27 | ramclustR object with normalized data. 28 | } 29 | \description{ 30 | used to remove compounds which are found at similar intensity in blank samples. Only applied after clustering. see also rc.feature.filter.blanks for filtering at the feature level (only done before clustering). 31 | } 32 | \details{ 33 | This function removes compounds which contain signal in QC samples comparable to blanks. 34 | } 35 | \references{ 36 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 37 | } 38 | \author{ 39 | Corey Broeckling 40 | } 41 | \concept{MSFinder} 42 | \concept{RAMClustR} 43 | \concept{clustering} 44 | \concept{feature} 45 | \concept{mass spectrometry} 46 | \concept{metabolomics} 47 | \concept{ramclustR} 48 | \concept{xcms} 49 | -------------------------------------------------------------------------------- /man/rc.cmpd.filter.cv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.cmpd.cv.filter.R 3 | \name{rc.cmpd.filter.cv} 4 | \alias{rc.cmpd.filter.cv} 5 | \title{rc.cmpd.filter.cv} 6 | \usage{ 7 | rc.cmpd.filter.cv(ramclustObj = NULL, qc.tag = "QC", max.cv = 0.5) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | 12 | \item{qc.tag}{character vector of length one or two. If length is two, enter search string and factor name in $phenoData slot (i.e. c("QC", "sample.type"). If length one (i.e. "QC"), will search for this string in the 'sample.names' slot by default.} 13 | 14 | \item{max.cv}{numeric maximum allowable cv for any feature. default = 0.3} 15 | } 16 | \value{ 17 | ramclustR object with total extracted ion normalized data. 18 | } 19 | \description{ 20 | extractor for xcms objects in preparation for clustering 21 | } 22 | \details{ 23 | This function offers normalization by total extracted ion signal. it is recommended to first run 'rc.feature.filter.blanks' to remove non-sample derived signal. 24 | } 25 | \references{ 26 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 27 | } 28 | \author{ 29 | Corey Broeckling 30 | } 31 | \concept{MSFinder} 32 | \concept{RAMClustR} 33 | \concept{clustering} 34 | \concept{feature} 35 | \concept{mass spectrometry} 36 | \concept{metabolomics} 37 | \concept{ramclustR} 38 | \concept{xcms} 39 | -------------------------------------------------------------------------------- /man/rc.cmpd.replace.na.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.cmpd.replace.na.R 3 | \name{rc.cmpd.replace.na} 4 | \alias{rc.cmpd.replace.na} 5 | \title{rc.cmpd.replace.na} 6 | \usage{ 7 | rc.cmpd.replace.na( 8 | ramclustObj = NULL, 9 | replace.int = 0.1, 10 | replace.noise = 0.1, 11 | replace.zero = TRUE 12 | ) 13 | } 14 | \arguments{ 15 | \item{ramclustObj}{ramclustObj containing SpecAbund dataset} 16 | 17 | \item{replace.int}{default = 0.2. proportion of minimum feature value to replace NA (or zero) values with} 18 | 19 | \item{replace.noise}{default = 0.2. proportion ofreplace.int value by which noise is added via 'jitter'} 20 | 21 | \item{replace.zero}{logical if TRUE, any zero values are replaced with noise as if they were NA values} 22 | } 23 | \value{ 24 | ramclustR object with NA and zero values removed. 25 | } 26 | \description{ 27 | replaces any NA (and optionally zero) values with small signal (20% of minimum feature signal value + 20% random noise) 28 | } 29 | \details{ 30 | noise is added by finding for each feature the minimum detected value, multiplying that value by replace.int, then adding (replace.int*replace.noise) noise. abs() is used to ensure no negative values result. 31 | } 32 | \references{ 33 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 34 | } 35 | \author{ 36 | Corey Broeckling 37 | } 38 | \concept{MSFinder} 39 | \concept{RAMClustR} 40 | \concept{clustering} 41 | \concept{feature} 42 | \concept{mass spectrometry} 43 | \concept{metabolomics} 44 | \concept{ramclustR} 45 | \concept{xcms} 46 | -------------------------------------------------------------------------------- /man/rc.expand.sample.names.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.expand.sample.names.R 3 | \name{rc.expand.sample.names} 4 | \alias{rc.expand.sample.names} 5 | \title{rc.expand.sample.names} 6 | \usage{ 7 | rc.expand.sample.names( 8 | ramclustObj = NULL, 9 | delim = "-", 10 | factor.names = TRUE, 11 | quiet = FALSE 12 | ) 13 | } 14 | \arguments{ 15 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 16 | 17 | \item{delim}{what delimiter should be used to separate names into factors? '-' by default} 18 | 19 | \item{factor.names}{logical or character vector. if TRUE, user will enter names one by on in console. If character vector (i.e. c("trt", "time")) names are assigned to table} 20 | 21 | \item{quiet}{logical . if TRUE, user will not be prompted to enter names one by on in console.} 22 | } 23 | \value{ 24 | ramclustR object with normalized data. 25 | } 26 | \description{ 27 | turn concatenated sample names into factors 28 | } 29 | \details{ 30 | THis function only works on newer format ramclustObjects with a $phenoData slot. 31 | 32 | This function will split sample names by a delimiter, and enable users to name factors 33 | } 34 | \references{ 35 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 36 | } 37 | \author{ 38 | Corey Broeckling 39 | } 40 | \concept{MSFinder} 41 | \concept{RAMClustR} 42 | \concept{clustering} 43 | \concept{feature} 44 | \concept{mass spectrometry} 45 | \concept{metabolomics} 46 | \concept{ramclustR} 47 | \concept{xcms} 48 | -------------------------------------------------------------------------------- /man/rc.export.msp.rc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.export.msp.rc.R 3 | \name{rc.export.msp.rc} 4 | \alias{rc.export.msp.rc} 5 | \title{rc.export.msp.rc} 6 | \usage{ 7 | rc.export.msp.rc(ramclustObj = NULL, one.file = TRUE, mzdec = 1) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustR object to annotate.} 11 | 12 | \item{one.file}{logical, should all msp spectra be written to one file? If false, each spectrum is an individual file.} 13 | 14 | \item{mzdec}{integer. Number of decimal points to export mass values with.} 15 | } 16 | \value{ 17 | nothing, just exports files to the working directory 18 | } 19 | \description{ 20 | Cluster annotation function: inference of 'M' - molecular weight of the compound giving rise to each spectrum - using the InterpretMSSpectrum::findMain function 21 | } 22 | \details{ 23 | exports files to a directory called 'spectra'. If one.file = FALSE, a new directory 'spectra/msp' is created to hold the individual msp files. if do.findman has been run, spectra are written as ms2 spectra, else as ms1. 24 | } 25 | \author{ 26 | Corey Broeckling 27 | } 28 | \concept{RAMClustR} 29 | \concept{clustering} 30 | \concept{interpretMSSpectrum} 31 | \concept{mass spectrometry} 32 | \concept{metabolomics} 33 | \concept{ramclustR} 34 | \concept{xcms} 35 | -------------------------------------------------------------------------------- /man/rc.feature.filter.blanks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.filter.blanks.R 3 | \name{rc.feature.filter.blanks} 4 | \alias{rc.feature.filter.blanks} 5 | \title{rc.feature.filter.blanks} 6 | \usage{ 7 | rc.feature.filter.blanks( 8 | ramclustObj = NULL, 9 | qc.tag = "QC", 10 | blank.tag = "blank", 11 | sn = 3, 12 | remove.blanks = TRUE 13 | ) 14 | } 15 | \arguments{ 16 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 17 | 18 | \item{qc.tag}{character vector of length one or two. If length is two, enter search string and factor name in $phenoData slot (i.e. c("QC", "sample.type"). If length one (i.e. "QC"), will search for this string in the 'sample.names' slot by default.} 19 | 20 | \item{blank.tag}{see 'qc.tag' , but for blanks to use as background.} 21 | 22 | \item{sn}{numeric defines the ratio for 'signal'. i.e. sn = 3 indicates that signal intensity must be 3 fold higher in sample than in blanks, on average, to be retained.} 23 | 24 | \item{remove.blanks}{logical. TRUE by default. this removes any recognized blanks samples from the MSdata and MSMSdata sets after they are used to filter contaminant features.} 25 | } 26 | \value{ 27 | ramclustR object with normalized data. 28 | } 29 | \description{ 30 | used to remove features which are found at similar intensity in blank samples 31 | } 32 | \details{ 33 | This function offers normalization by run order, batch number, and QC sample signal intensity. 34 | 35 | Each input vector should be the same length, and equal to the number of samples in the $MSdata set. 36 | 37 | Input vector order is assumed to be the same as the sample order in the $MSdata set. 38 | } 39 | \references{ 40 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 41 | } 42 | \author{ 43 | Corey Broeckling 44 | } 45 | \concept{MSFinder} 46 | \concept{RAMClustR} 47 | \concept{clustering} 48 | \concept{feature} 49 | \concept{mass spectrometry} 50 | \concept{metabolomics} 51 | \concept{ramclustR} 52 | \concept{xcms} 53 | -------------------------------------------------------------------------------- /man/rc.feature.filter.cv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.filter.cv.R 3 | \name{rc.feature.filter.cv} 4 | \alias{rc.feature.filter.cv} 5 | \title{rc.feature.filter.cv} 6 | \usage{ 7 | rc.feature.filter.cv(ramclustObj = NULL, qc.tag = "QC", max.cv = 0.5) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | 12 | \item{qc.tag}{character vector of length one or two. If length is two, enter search string and factor name in $phenoData slot (i.e. c("QC", "sample.type"). If length one (i.e. "QC"), will search for this string in the 'sample.names' slot by default.} 13 | 14 | \item{max.cv}{numeric maximum allowable cv for any feature. default = 0.5} 15 | } 16 | \value{ 17 | ramclustR object with total extracted ion normalized data. 18 | } 19 | \description{ 20 | extractor for xcms objects in preparation for clustering 21 | } 22 | \details{ 23 | This function offers normalization by total extracted ion signal. it is recommended to first run 'rc.feature.filter.blanks' to remove non-sample derived signal. 24 | } 25 | \references{ 26 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 27 | } 28 | \author{ 29 | Corey Broeckling 30 | } 31 | \concept{MSFinder} 32 | \concept{RAMClustR} 33 | \concept{clustering} 34 | \concept{feature} 35 | \concept{mass spectrometry} 36 | \concept{metabolomics} 37 | \concept{ramclustR} 38 | \concept{xcms} 39 | -------------------------------------------------------------------------------- /man/rc.feature.normalize.batch.qc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.normalize.batch.qc.R 3 | \name{rc.feature.normalize.batch.qc} 4 | \alias{rc.feature.normalize.batch.qc} 5 | \title{rc.feature.normalize.batch.qc} 6 | \usage{ 7 | rc.feature.normalize.batch.qc( 8 | order = NULL, 9 | batch = NULL, 10 | qc = NULL, 11 | ramclustObj = NULL, 12 | qc.inj.range = 20, 13 | output.plot = FALSE 14 | ) 15 | } 16 | \arguments{ 17 | \item{order}{integer vector with length equal to number of injections in xset or csv file or dataframe} 18 | 19 | \item{batch}{integer vector with length equal to number of injections in xset or csv file or dataframe} 20 | 21 | \item{qc}{logical vector with length equal to number of injections in xset or csv file or dataframe} 22 | 23 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 24 | 25 | \item{qc.inj.range}{integer: how many injections around each injection are to be scanned for presence of QC samples when using batch.qc normalization? A good rule of thumb is between 1 and 3 times the typical injection span between QC injections. i.e. if you inject QC ever 7 samples, set this to between 7 and 21. smaller values provide more local precision but make normalization sensitive to individual poor outliers (though these are first removed using the boxplot function outlier detection), while wider values provide less local precision in normalization but better stability to individual peak areas.} 26 | 27 | \item{output.plot}{logical set to TRUE to store plots} 28 | } 29 | \value{ 30 | ramclustR object with normalized data. 31 | } 32 | \description{ 33 | normalize data using batch.qc 34 | } 35 | -------------------------------------------------------------------------------- /man/rc.feature.normalize.qc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.normalize.qc.R 3 | \name{rc.feature.normalize.qc} 4 | \alias{rc.feature.normalize.qc} 5 | \title{rc.feature.normalize.qc} 6 | \usage{ 7 | rc.feature.normalize.qc( 8 | ramclustObj = NULL, 9 | order = NULL, 10 | batch = NULL, 11 | qc = NULL, 12 | output.plot = FALSE, 13 | p.cut = 0.05, 14 | rsq.cut = 0.1, 15 | p.adjust = "none" 16 | ) 17 | } 18 | \arguments{ 19 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 20 | 21 | \item{order}{integer vector with length equal to number of injections in xset or csv file} 22 | 23 | \item{batch}{integer vector with length equal to number of injections in xset or csv file} 24 | 25 | \item{qc}{logical vector with length equal to number of injections in xset or csv file or dataframe} 26 | 27 | \item{output.plot}{logical: if TRUE (default), plots are output to PDF.} 28 | 29 | \item{p.cut}{numeric when run order correction is applied, only features showing a run order vs signal with a linear p-value (after FDR correction) < p.cut will be adjusted. also requires r-squared < rsq.cut.} 30 | 31 | \item{rsq.cut}{numeric when run order correction is applied, only features showing a run order vs signal with a linear r-squared > rsq.cut will be adjusted. also requires p values < p.cut.} 32 | 33 | \item{p.adjust}{which p-value adjustment should be used? default = "none", see ?p.adjust} 34 | } 35 | \value{ 36 | ramclustR object with normalized data. 37 | } 38 | \description{ 39 | extractor for xcms objects in preparation for clustering 40 | } 41 | \details{ 42 | This function offers normalization by run order, batch number, and QC sample signal intensity. 43 | 44 | Each input vector should be the same length, and equal to the number of samples in the $MSdata set. 45 | 46 | Input vector order is assumed to be the same as the sample order in the $MSdata set. 47 | } 48 | \references{ 49 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 50 | } 51 | \author{ 52 | Corey Broeckling 53 | } 54 | \concept{MSFinder} 55 | \concept{RAMClustR} 56 | \concept{clustering} 57 | \concept{feature} 58 | \concept{mass spectrometry} 59 | \concept{metabolomics} 60 | \concept{ramclustR} 61 | \concept{xcms} 62 | -------------------------------------------------------------------------------- /man/rc.feature.normalize.quantile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.normalize.quantile.R 3 | \name{rc.feature.normalize.quantile} 4 | \alias{rc.feature.normalize.quantile} 5 | \title{rc.feature.normalize.quantile} 6 | \usage{ 7 | rc.feature.normalize.quantile(ramclustObj = NULL) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | } 12 | \value{ 13 | ramclustR object with normalized data. 14 | } 15 | \description{ 16 | normalize data using quantile 17 | } 18 | -------------------------------------------------------------------------------- /man/rc.feature.normalize.tic.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.normalize.tic.R 3 | \name{rc.feature.normalize.tic} 4 | \alias{rc.feature.normalize.tic} 5 | \title{rc.feature.normalize.tic} 6 | \usage{ 7 | rc.feature.normalize.tic(ramclustObj = NULL) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | } 12 | \value{ 13 | ramclustR object with total extracted ion normalized data. 14 | } 15 | \description{ 16 | extractor for xcms objects in preparation for clustering 17 | } 18 | \details{ 19 | This function offers normalization by total extracted ion signal. it is recommended to first run 'rc.feature.filter.blanks' to remove non-sample derived signal. 20 | } 21 | \references{ 22 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 23 | } 24 | \author{ 25 | Corey Broeckling 26 | } 27 | \concept{MSFinder} 28 | \concept{RAMClustR} 29 | \concept{clustering} 30 | \concept{feature} 31 | \concept{mass spectrometry} 32 | \concept{metabolomics} 33 | \concept{ramclustR} 34 | \concept{xcms} 35 | -------------------------------------------------------------------------------- /man/rc.feature.replace.na.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.replace.na.R 3 | \name{rc.feature.replace.na} 4 | \alias{rc.feature.replace.na} 5 | \title{rc.feature.replace.na} 6 | \usage{ 7 | rc.feature.replace.na( 8 | ramclustObj = NULL, 9 | replace.int = 0.1, 10 | replace.noise = 0.1, 11 | replace.zero = TRUE, 12 | which.data = c("MSdata", "MSMSdata") 13 | ) 14 | } 15 | \arguments{ 16 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 17 | 18 | \item{replace.int}{default = 0.1. proportion of minimum feature value to replace NA (or zero) values with} 19 | 20 | \item{replace.noise}{default = 0.1. proportion ofreplace.int value by which noise is added via 'jitter'} 21 | 22 | \item{replace.zero}{logical if TRUE, any zero values are replaced with noise as if they were NA values} 23 | 24 | \item{which.data}{name of dataset} 25 | } 26 | \value{ 27 | ramclustR object with NA and zero values removed. 28 | } 29 | \description{ 30 | replaces any NA (and optionally zero) values with small signal (20% of minimum feature signal value + 20% random noise) 31 | } 32 | \details{ 33 | noise is added by finding for each feature the minimum detected value, multiplying that value by replace.int, then adding (replace.int*replace.noise) noise. abs() is used to ensure no negative values result. 34 | } 35 | \references{ 36 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 37 | } 38 | \author{ 39 | Corey Broeckling 40 | } 41 | \concept{MSFinder} 42 | \concept{RAMClustR} 43 | \concept{clustering} 44 | \concept{feature} 45 | \concept{mass spectrometry} 46 | \concept{metabolomics} 47 | \concept{ramclustR} 48 | \concept{xcms} 49 | -------------------------------------------------------------------------------- /man/rc.get.csv.data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.get.csv.data.R 3 | \name{rc.get.csv.data} 4 | \alias{rc.get.csv.data} 5 | \title{rc.get.csv.data} 6 | \usage{ 7 | rc.get.csv.data( 8 | csv = NULL, 9 | phenoData = NULL, 10 | idmsms = NULL, 11 | ExpDes = NULL, 12 | sampNameCol = 1, 13 | st = NULL, 14 | timepos = 2, 15 | featdelim = "_", 16 | ensure.no.na = TRUE 17 | ) 18 | } 19 | \arguments{ 20 | \item{csv}{filepath: csv input. Features as columns, rows as samples. Column header mz_rt} 21 | 22 | \item{phenoData}{character: character string in 'taglocation' to designate files as either MS / DIA(MSe, MSall, AIF, etc) e.g. "01.mzML"} 23 | 24 | \item{idmsms}{filepath: optional idMSMS / MSe csv data. same dim and names as ms required} 25 | 26 | \item{ExpDes}{either an R object created by R ExpDes object: data used for record keeping and labelling msp spectral output} 27 | 28 | \item{sampNameCol}{integer: which column from the csv file contains sample names?} 29 | 30 | \item{st}{numeric: sigma t - time similarity decay value} 31 | 32 | \item{timepos}{integer: which position in delimited column header represents the retention time} 33 | 34 | \item{featdelim}{character: how feature mz and rt are delimited in csv import column header e.g. ="-"} 35 | 36 | \item{ensure.no.na}{logical: if TRUE, any 'NA' values in msint and/or msmsint are replaced with numerical values based on 10 percent of feature min plus noise. Used to ensure that spectra are not written with NA values.} 37 | } 38 | \value{ 39 | an empty ramclustR object. this object is formatted as an hclust object with additional slots for holding feature and compound data. details on these found below. 40 | 41 | $frt: feature retention time, in whatever units were fed in 42 | 43 | $fmz: feature retention time, reported in number of decimal points selected in ramclustR function 44 | 45 | $ExpDes: the experimental design object used when running ramclustR. List of two dataframes. 46 | 47 | $MSdata: the MSdataset provided by either xcms or csv input 48 | 49 | $MSMSdata: the (optional) DIA(MSe, MSall, AIF etc) dataset 50 | 51 | $xcmsOrd: original xcms order of features, for back-referencing when necessary 52 | 53 | $msint: weighted.mean intensity of feature in ms level data 54 | 55 | $msmsint:weighted.mean intensity of feature in msms level data 56 | } 57 | \description{ 58 | extractor for csv objects in preparation for normalization and clustering 59 | } 60 | \details{ 61 | This function creates a ramclustObj which will be used as input for clustering. 62 | } 63 | \examples{ 64 | ## Choose csv input file. Features as columns, rows as samples 65 | ## Choose csv input file phenoData 66 | filename <- system.file("extdata", "peaks.csv", package = "RAMClustR", mustWork = TRUE) 67 | phenoData <- system.file("extdata", "phenoData.csv", package = "RAMClustR", mustWork = TRUE) 68 | 69 | ramclustobj <- rc.get.csv.data(csv = filename, phenoData = phenoData, st = 5) 70 | 71 | } 72 | \references{ 73 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 74 | 75 | Broeckling CD, Ganna A, Layer M, Brown K, Sutton B, Ingelsson E, Peers G, Prenni JE. Enabling Efficient and Confident Annotation of LC-MS Metabolomics Data through MS1 Spectrum and Time Prediction. Anal Chem. 2016 Sep 20;88(18):9226-34. doi: 10.1021/acs.analchem.6b02479. Epub 2016 Sep 8. PubMed PMID: 7560453. 76 | } 77 | \author{ 78 | Corey Broeckling 79 | } 80 | \concept{MSFinder} 81 | \concept{RAMClustR} 82 | \concept{clustering} 83 | \concept{feature} 84 | \concept{mass spectrometry} 85 | \concept{metabolomics} 86 | \concept{ramclustR} 87 | \concept{xcms} 88 | -------------------------------------------------------------------------------- /man/rc.get.df.data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.get.df.data.R 3 | \name{rc.get.df.data} 4 | \alias{rc.get.df.data} 5 | \title{rc.get.df.data} 6 | \usage{ 7 | rc.get.df.data( 8 | ms1_featureDefinitions = NULL, 9 | ms1_featureValues = NULL, 10 | ms2_featureDefinitions = NULL, 11 | ms2_featureValues = NULL, 12 | phenoData = NULL, 13 | ExpDes = NULL, 14 | featureNamesColumnIndex = 1, 15 | st = NULL, 16 | ensure.no.na = TRUE 17 | ) 18 | } 19 | \arguments{ 20 | \item{ms1_featureDefinitions}{dataframe with metadata with columns: mz, rt, feature names containing MS data} 21 | 22 | \item{ms1_featureValues}{dataframe with rownames = sample names, colnames = feature names containing MS data} 23 | 24 | \item{ms2_featureDefinitions}{dataframe with metadata with columns: mz, rt, feature names containing MSMS data} 25 | 26 | \item{ms2_featureValues}{dataframe with rownames = sample names, colnames = feature names containing MSMS data} 27 | 28 | \item{phenoData}{dataframe containing phenoData} 29 | 30 | \item{ExpDes}{either an R object created by R ExpDes object: data used for record keeping and labelling msp spectral output} 31 | 32 | \item{featureNamesColumnIndex}{integer: which column in `ms1_featureDefinitions` contains feature names?} 33 | 34 | \item{st}{numeric: sigma t - time similarity decay value} 35 | 36 | \item{ensure.no.na}{logical: if TRUE, any 'NA' values in msint and/or msmsint are replaced with numerical values based on 10 percent of feature min plus noise. Used to ensure that spectra are not written with NA values.} 37 | } 38 | \value{ 39 | an empty ramclustR object. this object is formatted as an hclust object with additional slots for holding feature and compound data. details on these found below. 40 | 41 | $frt: feature retention time, in whatever units were fed in 42 | 43 | $fmz: feature retention time, reported in number of decimal points selected in ramclustR function 44 | 45 | $ExpDes: the experimental design object used when running ramclustR. List of two dataframes. 46 | 47 | $MSdata: the MSdataset provided by either xcms or csv input 48 | 49 | $MSMSdata: the (optional) DIA(MSe, MSall, AIF etc) dataset 50 | 51 | $xcmsOrd: original xcms order of features, for back-referencing when necessary 52 | 53 | $msint: weighted.mean intensity of feature in ms level data 54 | 55 | $msmsint:weighted.mean intensity of feature in msms level data 56 | } 57 | \description{ 58 | extractor for dataframe input in preparation for normalization and clustering 59 | } 60 | \details{ 61 | This function creates a ramclustObj which will be used as input for clustering. 62 | } 63 | \examples{ 64 | ## Choose dataframe with metadata with columns: mz, rt, feature names containing MS data 65 | ## Choose dataframe with rownames = sample names, colnames = feature names containing MS data 66 | ## Choose dataframe containing phenoData 67 | df1 <- readRDS(system.file("extdata", "featDefinition.rds", package = "RAMClustR", mustWork = TRUE)) 68 | df2 <- readRDS(system.file("extdata", "featValues.rds", package = "RAMClustR", mustWork = TRUE)) 69 | df3 <- readRDS(system.file("extdata", "phenoData_df.rds", package = "RAMClustR", mustWork = TRUE)) 70 | 71 | ramclustr <- rc.get.df.data(ms1_featureDefinitions=df1, ms1_featureValues=df2, phenoData=df3, st=5) 72 | 73 | } 74 | \references{ 75 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 76 | 77 | Broeckling CD, Ganna A, Layer M, Brown K, Sutton B, Ingelsson E, Peers G, Prenni JE. Enabling Efficient and Confident Annotation of LC-MS Metabolomics Data through MS1 Spectrum and Time Prediction. Anal Chem. 2016 Sep 20;88(18):9226-34. doi: 10.1021/acs.analchem.6b02479. Epub 2016 Sep 8. PubMed PMID: 7560453. 78 | } 79 | \author{ 80 | Zargham Ahmad, Helge Hecht, Corey Broeckling 81 | } 82 | \concept{MSFinder} 83 | \concept{RAMClustR} 84 | \concept{clustering} 85 | \concept{feature} 86 | \concept{mass spectrometry} 87 | \concept{metabolomics} 88 | \concept{ramclustR} 89 | \concept{xcms} 90 | -------------------------------------------------------------------------------- /man/rc.get.xcms.data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.get.xmcs.data.R 3 | \name{rc.get.xcms.data} 4 | \alias{rc.get.xcms.data} 5 | \title{rc.get.xcms.data} 6 | \usage{ 7 | rc.get.xcms.data( 8 | xcmsObj = NULL, 9 | taglocation = "filepaths", 10 | MStag = NULL, 11 | MSMStag = NULL, 12 | ExpDes = NULL, 13 | mzdec = 3, 14 | ensure.no.na = TRUE 15 | ) 16 | } 17 | \arguments{ 18 | \item{xcmsObj}{xcmsObject: containing grouped feature data for clustering by ramclustR} 19 | 20 | \item{taglocation}{character: "filepaths" by default, "phenoData[,1]" is another option. refers to xcms slot} 21 | 22 | \item{MStag}{character: character string in 'taglocation' to designate files as either MS / DIA(MSe, MSall, AIF, etc) e.g. "01.mzML"} 23 | 24 | \item{MSMStag}{character: character string in 'taglocation' to designate files as either MS / DIA(MSe, MSall, AIF, etc) e.g. "02.mzML"} 25 | 26 | \item{ExpDes}{either an R object created by R ExpDes object: data used for record keeping and labelling msp spectral output} 27 | 28 | \item{mzdec}{integer: number of decimal places for storing m/z values} 29 | 30 | \item{ensure.no.na}{logical: if TRUE, any 'NA' values in msint and/or msmsint are replaced with numerical values based on 10 percent of feature min plus noise. Used to ensure that spectra are not written with NA values.} 31 | } 32 | \value{ 33 | an empty ramclustR object. this object is formatted as an hclust object with additional slots for holding feature and compound data. details on these found below. 34 | 35 | $frt: feature retention time, in whatever units were fed in (xcms uses seconds, by default) 36 | 37 | $fmz: feature retention time, reported in number of decimal points selected in ramclustR function 38 | 39 | $ExpDes: the experimental design object used when running ramclustR. List of two dataframes. 40 | 41 | $MSdata: the MSdataset provided by either xcms or csv input 42 | 43 | $MSMSdata: the (optional) DIA(MSe, MSall, AIF etc) dataset provided be either xcms or csv input 44 | 45 | $xcmsOrd: original xcms order of features, for back-referencing when necessary 46 | 47 | $msint: weighted.mean intensity of feature in ms level data 48 | 49 | $msmsint:weighted.mean intensity of feature in msms level data 50 | } 51 | \description{ 52 | extractor for xcms objects in preparation for normalization and clustering 53 | } 54 | \details{ 55 | This function creates a ramclustObj which will be used as input for clustering. 56 | } 57 | \references{ 58 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 59 | 60 | Broeckling CD, Ganna A, Layer M, Brown K, Sutton B, Ingelsson E, Peers G, Prenni JE. Enabling Efficient and Confident Annotation of LC-MS Metabolomics Data through MS1 Spectrum and Time Prediction. Anal Chem. 2016 Sep 20;88(18):9226-34. doi: 10.1021/acs.analchem.6b02479. Epub 2016 Sep 8. PubMed PMID: 7560453. 61 | } 62 | \author{ 63 | Corey Broeckling 64 | } 65 | \concept{MSFinder} 66 | \concept{RAMClustR} 67 | \concept{clustering} 68 | \concept{feature} 69 | \concept{mass spectrometry} 70 | \concept{metabolomics} 71 | \concept{ramclustR} 72 | \concept{xcms} 73 | -------------------------------------------------------------------------------- /man/rc.merge.split.clusters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.merge.clusters.R 3 | \name{rc.merge.split.clusters} 4 | \alias{rc.merge.split.clusters} 5 | \title{rc.merge.split.clusters} 6 | \usage{ 7 | rc.merge.split.clusters( 8 | ramclustObj = NULL, 9 | merge.threshold = 0.7, 10 | cor.method = "spearman", 11 | rt.sd.factor = 3, 12 | cor.use = "everything", 13 | sample.name.column = "sample.ID" 14 | ) 15 | } 16 | \arguments{ 17 | \item{ramclustObj}{ramclustR object to annotate.} 18 | 19 | \item{merge.threshold}{numeric. value between -1 and 1 indicating the correlational r threshold above which two clusters will be merged} 20 | 21 | \item{cor.method}{character: which correlational method used to calculate 'r' - see ?cor 'method' option. default = "pearson"} 22 | 23 | \item{rt.sd.factor}{numeric. default = 3. clusters within rt.sd.factor * ramclustObj$rtsd (cluster retention time standard deviation) are considered for merging.} 24 | 25 | \item{cor.use}{character: which data points to use to calculate 'r' - see ?cor 'use' option. default = "pairwise.complete.obs"} 26 | 27 | \item{sample.name.column}{character. column name from ramclustObj$phenoData which should be used as row.names in new ramclustObj$SpecAbund dataset.} 28 | } 29 | \value{ 30 | new ramclustR object, with (generally) fewer clusters than the input ramclustR object. 31 | } 32 | \description{ 33 | Cluster refinement - scanning instruments (quadrupole, as in GC-MS) can display cluster splitting, possibily due to slight differences in measured peak retentiont time as a function of mass due to scan dynamics. this function enables a second pass clustering designed to merge two clusters if the second cluster is within a small retention time window and shows a sufficiently strong correlation. 34 | } 35 | \details{ 36 | exports files to a directory called 'spectra'. If one.file = FALSE, a new directory 'spectra/msp' is created to hold the individual msp files. if do.findman has been run, spectra are written as ms2 spectra, else as ms1. 37 | } 38 | \author{ 39 | Corey Broeckling 40 | } 41 | \concept{RAMClustR} 42 | \concept{clustering} 43 | \concept{mass spectrometry} 44 | \concept{metabolomics} 45 | \concept{ramclustR} 46 | \concept{xcms} 47 | -------------------------------------------------------------------------------- /man/rc.qc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.qc.R 3 | \name{rc.qc} 4 | \alias{rc.qc} 5 | \title{rc.qc} 6 | \usage{ 7 | rc.qc( 8 | ramclustObj = NULL, 9 | qc.tag = "QC", 10 | remove.qc = FALSE, 11 | npc = 4, 12 | scale = "pareto", 13 | outfile.basename = "ramclustQC", 14 | view.hist = TRUE, 15 | do.plot = TRUE 16 | ) 17 | } 18 | \arguments{ 19 | \item{ramclustObj}{ramclustR object to analyze} 20 | 21 | \item{qc.tag}{qc.tag character vector of length one or two. If length is two, enter search string and factor name in $phenoData slot (i.e. c("QC", "sample.type"). If length one (i.e. "QC"), will search for this string in the 'sample.names' slot by default.} 22 | 23 | \item{remove.qc}{logical - if TRUE (default) QC injections will be removed from the returned ramclustObj (applies to $MSdata, $MSMSdata, $SpecAbund, $phenoData, as appropriate). If FALSE, QC samples remain.} 24 | 25 | \item{npc}{number of Principle components to calcuate and plot} 26 | 27 | \item{scale}{"pareto" by default: PCA scaling method used} 28 | 29 | \item{outfile.basename}{base name of output files. Extensions added internally. default = "ramclustQC"} 30 | 31 | \item{view.hist}{logical. should histograms be plotted?} 32 | 33 | \item{do.plot}{logical should plots be shown/plotted?} 34 | } 35 | \value{ 36 | new RC object. Saves output summary plots to pdf and .csv summary tables to new 'QC' directory. If remove.qc = TRUE, moves QC samples to new $QC slot from original position. 37 | } 38 | \description{ 39 | summarize quality control for clustering and for quality control sample variation based on compound ($SpecAbund) and feature ($MSdata and $MSMSdata, if present) 40 | } 41 | \details{ 42 | plots a ramclustR summary plot. first page represents the correlation of each cluster to all other clusters, sorted by retention time. large blocks of yellow along the diaganol indicate either poor clustering or a group of coregulated metabolites with similar retention time. It is an imperfect diagnostic, particularly with lipids on reverse phase LC or sugars on HILIC LC systems. Page 2: histogram of r values from page 1 - only r values one position from the diagonal are used. Pages 3:5 - PCA results, with QC samples colored red. relative standard deviation calculated as sd(QC PC scores) / sd(all PC scores). Page 6: histogram of CV values for each compound int he dataset, QC samples only. 43 | } 44 | \references{ 45 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 46 | 47 | Broeckling CD, Ganna A, Layer M, Brown K, Sutton B, Ingelsson E, Peers G, Prenni JE. Enabling Efficient and Confident Annotation of LC-MS Metabolomics Data through MS1 Spectrum and Time Prediction. Anal Chem. 2016 Sep 20;88(18):9226-34. doi: 10.1021/acs.analchem.6b02479. Epub 2016 Sep 8. PubMed PMID: 7560453. 48 | } 49 | \author{ 50 | Corey Broeckling 51 | } 52 | \concept{MSFinder} 53 | \concept{RAMClustR} 54 | \concept{clustering} 55 | \concept{feature} 56 | \concept{mass spectrometry} 57 | \concept{metabolomics} 58 | \concept{ramclustR} 59 | \concept{xcms} 60 | -------------------------------------------------------------------------------- /man/rc.ramclustr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.ramclustr.R 3 | \name{rc.ramclustr} 4 | \alias{rc.ramclustr} 5 | \title{rc.ramclustr} 6 | \usage{ 7 | rc.ramclustr( 8 | ramclustObj = NULL, 9 | st = NULL, 10 | sr = NULL, 11 | maxt = NULL, 12 | deepSplit = FALSE, 13 | blocksize = 2000, 14 | mult = 5, 15 | hmax = NULL, 16 | collapse = TRUE, 17 | minModuleSize = 2, 18 | linkage = "average", 19 | cor.method = "pearson", 20 | cor.use = "pairwise.complete.obs", 21 | rt.only.low.n = TRUE 22 | ) 23 | } 24 | \arguments{ 25 | \item{ramclustObj}{ramclustR object: containing ungrouped features. constructed by rc.get.xcms.data, for example} 26 | 27 | \item{st}{numeric: sigma t - time similarity decay value} 28 | 29 | \item{sr}{numeric: sigma r - correlational similarity decay value} 30 | 31 | \item{maxt}{numeric: maximum time difference to calculate retention similarity for - all values beyond this are assigned similarity of zero} 32 | 33 | \item{deepSplit}{logical: controls how agressively the HCA tree is cut - see ?cutreeDynamicTree} 34 | 35 | \item{blocksize}{integer: number of features (scans?) processed in one block =1000,} 36 | 37 | \item{mult}{numeric: internal value, can be used to influence processing speed/ram usage} 38 | 39 | \item{hmax}{numeric: precut the tree at this height, default 0.3 - see ?cutreeDynamicTree} 40 | 41 | \item{collapse}{logical: if true (default), feature quantitative values are collapsed into spectra quantitative values.} 42 | 43 | \item{minModuleSize}{integer: how many features must be part of a cluster to be returned? default = 2} 44 | 45 | \item{linkage}{character: heirarchical clustering linkage method - see ?hclust} 46 | 47 | \item{cor.method}{character: which correlational method used to calculate 'r' - see ?cor 'method' option. default = "pearson"} 48 | 49 | \item{cor.use}{character: which data points to use to calculate 'r' - see ?cor 'use' option. default = "pairwise.complete.obs"} 50 | 51 | \item{rt.only.low.n}{logical: default = TRUE At low injection numbers, correlational relationships of peak intensities may be unreliable. by defualt ramclustR will simply ignore the correlational r value and cluster on retention time alone. if you wish to use correlation with at n < 5, set this value to FALSE.} 52 | } 53 | \value{ 54 | $featclus: integer vector of cluster membership for each feature 55 | 56 | $clrt: cluster retention time 57 | 58 | $clrtsd: retention time standard deviation of all the features that comprise that cluster 59 | 60 | $nfeat: number of features in the cluster 61 | 62 | $nsing: number of 'singletons' - that is the number of features which clustered with no other feature 63 | 64 | $cmpd: compound name. C#### are assigned in order of output by dynamicTreeCut. Compound with the most features is classified as C0001... 65 | 66 | $ann: annotation. By default, annotation names are identical to 'cmpd' names. This slot is a placeholder for when annotations are provided 67 | 68 | $SpecAbund: the cluster intensities after collapsing features to clusters 69 | 70 | $SpecAbundAve: the cluster intensities after averaging all samples with identical sample names 71 | } 72 | \description{ 73 | Main clustering function for grouping features based on their analytical behavior. 74 | } 75 | \details{ 76 | Main clustering function output - see citation for algorithm description or vignette('RAMClustR') for a walk through. batch.qc. normalization requires input of three vectors (1) batch (2) order (3) qc. This is a feature centric normalization approach which adjusts signal intensities first by comparing batch median intensity of each feature (one feature at a time) QC signal intensity to full dataset median to correct for systematic batch effects and then secondly to apply a local QC median vs global median sample correction to correct for run order effects. 77 | } 78 | \references{ 79 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 80 | 81 | Broeckling CD, Ganna A, Layer M, Brown K, Sutton B, Ingelsson E, Peers G, Prenni JE. Enabling Efficient and Confident Annotation of LC-MS Metabolomics Data through MS1 Spectrum and Time Prediction. Anal Chem. 2016 Sep 20;88(18):9226-34. doi: 10.1021/acs.analchem.6b02479. Epub 2016 Sep 8. PubMed PMID: 7560453. 82 | } 83 | \author{ 84 | Corey Broeckling 85 | } 86 | \concept{MSFinder} 87 | \concept{RAMClustR} 88 | \concept{clustering} 89 | \concept{feature} 90 | \concept{mass spectrometry} 91 | \concept{metabolomics} 92 | \concept{ramclustR} 93 | \concept{xcms} 94 | -------------------------------------------------------------------------------- /man/rc.remove.qc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.remove.qc.R 3 | \name{rc.remove.qc} 4 | \alias{rc.remove.qc} 5 | \title{rc.remove.qc} 6 | \usage{ 7 | rc.remove.qc(ramclustObj = NULL, qc.tag = "QC") 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustR object to analyze} 11 | 12 | \item{qc.tag}{qc.tag character vector of length one or two. If length is two, enter search string and factor name in $phenoData slot (i.e. c("QC", "sample.type"). If length one (i.e. "QC"), will search for this string in the 'sample.names' slot by default.} 13 | } 14 | \value{ 15 | new RC object. moves QC samples to new $qc slot from original position. 16 | } 17 | \description{ 18 | summarize quality control for clustering and for quality control sample variation based on compound ($SpecAbund) and feature ($MSdata and $MSMSdata, if present) 19 | } 20 | \details{ 21 | simply moves QC samples out of the way for downstream processing. moved to a $qc slot. 22 | } 23 | \references{ 24 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 25 | 26 | Broeckling CD, Ganna A, Layer M, Brown K, Sutton B, Ingelsson E, Peers G, Prenni JE. Enabling Efficient and Confident Annotation of LC-MS Metabolomics Data through MS1 Spectrum and Time Prediction. Anal Chem. 2016 Sep 20;88(18):9226-34. doi: 10.1021/acs.analchem.6b02479. Epub 2016 Sep 8. PubMed PMID: 7560453. 27 | } 28 | \author{ 29 | Corey Broeckling 30 | } 31 | \concept{MSFinder} 32 | \concept{RAMClustR} 33 | \concept{clustering} 34 | \concept{feature} 35 | \concept{mass spectrometry} 36 | \concept{metabolomics} 37 | \concept{ramclustR} 38 | \concept{xcms} 39 | -------------------------------------------------------------------------------- /man/rc.restore.qc.samples.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.restore.qc.samples.R 3 | \name{rc.restore.qc.samples} 4 | \alias{rc.restore.qc.samples} 5 | \title{rc.restore.qc.samples} 6 | \usage{ 7 | rc.restore.qc.samples(ramclustObj = NULL) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustR object to analyze} 11 | } 12 | \value{ 13 | RC object 14 | } 15 | \description{ 16 | summarize quality control for clustering and for quality control sample variation based on compound ($SpecAbund) and feature ($MSdata and $MSMSdata, if present) 17 | } 18 | \details{ 19 | moves all of $phenoData, $MSdata, $MSMSdata, $SpecAbund back to original positions from $qc slot 20 | } 21 | \references{ 22 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 23 | 24 | Broeckling CD, Ganna A, Layer M, Brown K, Sutton B, Ingelsson E, Peers G, Prenni JE. Enabling Efficient and Confident Annotation of LC-MS Metabolomics Data through MS1 Spectrum and Time Prediction. Anal Chem. 2016 Sep 20;88(18):9226-34. doi: 10.1021/acs.analchem.6b02479. Epub 2016 Sep 8. PubMed PMID: 7560453. 25 | } 26 | \author{ 27 | Corey Broeckling 28 | } 29 | \concept{MSFinder} 30 | \concept{RAMClustR} 31 | \concept{clustering} 32 | \concept{feature} 33 | \concept{mass spectrometry} 34 | \concept{metabolomics} 35 | \concept{ramclustR} 36 | \concept{xcms} 37 | -------------------------------------------------------------------------------- /man/remove_blanks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.filter.blanks.R 3 | \name{remove_blanks} 4 | \alias{remove_blanks} 5 | \title{remove_blanks} 6 | \usage{ 7 | remove_blanks(ramclustObj, blank) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustObj containing MSdata with optional MSMSdata (MSe, DIA, idMSMS)} 11 | 12 | \item{blank}{blank samples found by define_samples} 13 | } 14 | \value{ 15 | ramclustObj object with blanks removed 16 | } 17 | \description{ 18 | remove blanks 19 | } 20 | -------------------------------------------------------------------------------- /man/replace_na.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rc.feature.replace.na.R 3 | \name{replace_na} 4 | \alias{replace_na} 5 | \title{replace_na} 6 | \usage{ 7 | replace_na(data, replace.int, replace.zero, replace.noise) 8 | } 9 | \arguments{ 10 | \item{data}{selected data frame to use} 11 | 12 | \item{replace.int}{default = 0.1. proportion of minimum feature value to replace NA (or zero) values with} 13 | 14 | \item{replace.zero}{logical if TRUE, any zero values are replaced with noise as if they were NA values} 15 | 16 | \item{replace.noise}{default = 0.1. proportion ofreplace.int value by which noise is added via 'jitter'} 17 | } 18 | \value{ 19 | selected ramclustR data frame with NA and zero values removed. 20 | 21 | number of features replaced 22 | } 23 | \description{ 24 | add rc.feature.replace.na params in ramclustObj 25 | } 26 | -------------------------------------------------------------------------------- /man/write.gcei.mat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/write.gcei.mat.R 3 | \name{write.gcei.mat} 4 | \alias{write.gcei.mat} 5 | \title{write.gcei.mat} 6 | \usage{ 7 | write.gcei.mat(ramclustObj = NULL) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustR object to annotate.} 11 | } 12 | \value{ 13 | nothing, just exports files to the working directory 14 | } 15 | \description{ 16 | Export GC-MS EI spectra for spectral searching in MSFinder 17 | } 18 | \details{ 19 | exports files to a directory called 'spectra'. a new directory 'spectra/mat' is created to hold the individual mat files. 20 | } 21 | \author{ 22 | Corey Broeckling 23 | } 24 | \concept{RAMClustR} 25 | \concept{clustering} 26 | \concept{interpretMSSpectrum} 27 | \concept{mass spectrometry} 28 | \concept{metabolomics} 29 | \concept{ramclustR} 30 | \concept{xcms} 31 | -------------------------------------------------------------------------------- /man/write.methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/write.methods.R 3 | \name{write.methods} 4 | \alias{write.methods} 5 | \title{write.methods} 6 | \usage{ 7 | write.methods(ramclustObj = NULL, filename = NULL) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{R object - the ramclustR object which was used to write the .mat or .msp files} 11 | 12 | \item{filename}{define filename/path to write. uses 'ramclustr_methods.txt' and the working directory by default.} 13 | } 14 | \value{ 15 | an annotated ramclustR object 16 | 17 | nothing - new file written to working director 18 | } 19 | \description{ 20 | write RAMClustR processing methods and citations to text file 21 | } 22 | \details{ 23 | this function exports a file called ramclustr_methods.txt which contains the processing history, parameters used, and relevant citations. 24 | } 25 | \references{ 26 | Broeckling CD, Afsar FA, Neumann S, Ben-Hur A, Prenni JE. RAMClust: a novel feature clustering method enables spectral-matching-based annotation for metabolomics data. Anal Chem. 2014 Jul 15;86(14):6812-7. doi: 10.1021/ac501530d. Epub 2014 Jun 26. PubMed PMID: 24927477. 27 | } 28 | \author{ 29 | Corey Broeckling 30 | } 31 | \concept{RAMClustR} 32 | \concept{clustering} 33 | \concept{feature} 34 | \concept{mass spectrometry} 35 | \concept{metabolomics} 36 | \concept{ramclustR} 37 | \concept{xcms} 38 | -------------------------------------------------------------------------------- /man/write.msp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/write.msp.R 3 | \name{write.msp} 4 | \alias{write.msp} 5 | \title{write.msp} 6 | \usage{ 7 | write.msp(ramclustObj = NULL, one.file = FALSE) 8 | } 9 | \arguments{ 10 | \item{ramclustObj}{ramclustR object to annotate.} 11 | 12 | \item{one.file}{logical, should all msp spectra be written to one file? If false, each spectrum is an individual file.} 13 | } 14 | \value{ 15 | nothing, just exports files to the working directory 16 | } 17 | \description{ 18 | Cluster annotation function: inference of 'M' - molecular weight of the compound giving rise to each spectrum - using the InterpretMSSpectrum::findMain function 19 | } 20 | \details{ 21 | exports files to a directory called 'spectra'. If one.file = FALSE, a new directory 'spectra/msp' is created to hold the individual msp files. if do.findman has been run, spectra are written as ms2 spectra, else as ms1. 22 | } 23 | \author{ 24 | Corey Broeckling 25 | } 26 | \concept{RAMClustR} 27 | \concept{clustering} 28 | \concept{interpretMSSpectrum} 29 | \concept{mass spectrometry} 30 | \concept{metabolomics} 31 | \concept{ramclustR} 32 | \concept{xcms} 33 | -------------------------------------------------------------------------------- /man/write_csv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/defineExperiment.R 3 | \name{write_csv} 4 | \alias{write_csv} 5 | \title{write_csv} 6 | \usage{ 7 | write_csv(data) 8 | } 9 | \arguments{ 10 | \item{data}{csv template to write} 11 | } 12 | \value{ 13 | read ExpDes.csv file 14 | } 15 | \description{ 16 | write csv template called "ExpDes.csv" to your working directory. you will fill this in manually, ensuring that when you save you retain csv format. ramclustR will then read this file in and and format appropriately. 17 | } 18 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(RAMClustR) 3 | 4 | test_check("RAMClustR") 5 | -------------------------------------------------------------------------------- /tests/testthat/helper.R: -------------------------------------------------------------------------------- 1 | expect_equal_labels <- function(actual, expected) { 2 | actual_features <- split_features(actual) 3 | expected_features <- split_features(expected) 4 | 5 | expect_equal(actual_features$mz, expected_features$mz) 6 | expect_equal(actual_features$rt, expected_features$rt) 7 | } 8 | 9 | expect_equal_MSdata <- function(actual, expected, tolerance = .Machine$double.eps) { 10 | actual_labels <- colnames(actual) 11 | expected_labels <- colnames(expected) 12 | colnames(actual) <- colnames(expected) <- NULL 13 | 14 | expect_equal_labels(actual_labels, expected_labels) 15 | expect_equal(actual, expected, tolerance = tolerance) 16 | } 17 | 18 | split_features <- function(labels) { 19 | labels <- strsplit(labels, "_") 20 | mz_rt_df <- as.data.frame(do.call(rbind, labels)) 21 | mz_rt_df[, 1] <- as.numeric(mz_rt_df[, 1]) 22 | mz_rt_df[, 2] <- as.numeric(mz_rt_df[, 2]) 23 | return(mz_rt_df) 24 | } 25 | 26 | read_metadata <- function(filename) { 27 | data <- read.csv(filename, header = TRUE, stringsAsFactors = FALSE) 28 | 29 | if (!"qc" %in% colnames(data)) { 30 | if ("sampleType" %in% colnames(data)) { 31 | data$qc <- ifelse(tolower(data$sampleType) == tolower("qc"), TRUE, FALSE) 32 | } 33 | } 34 | 35 | if (!"order" %in% colnames(data)) { 36 | if ("injectionOrder" %in% colnames(data)) { 37 | names(data)[names(data) == "injectionOrder"] <- "order" 38 | } 39 | } 40 | 41 | return(data) 42 | } 43 | -------------------------------------------------------------------------------- /tests/testthat/test-do.findmain.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR do.findmain", { 2 | wd <- getwd() 3 | tmp <- tempdir() 4 | ramclustObj <- readRDS(file.path("testdata", "rc.qc.rds")) 5 | expected <- readRDS(file.path("testdata", "do.findmain.rds")) 6 | 7 | setwd(tmp) 8 | actual <- do.findmain(ramclustObj = ramclustObj) 9 | 10 | actual$history <- NA 11 | expected$history <- NA 12 | actual$params <- NA 13 | expected$params <- NA 14 | actual$phenoData <- NA 15 | expected$phenoData <- NA 16 | 17 | expect_equal(actual, expected) 18 | setwd(wd) 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.calibrate.ri.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.calibrate.ri", { 2 | calibrant.data <- file.path("testdata", "calibrant.data.csv") 3 | ramclustObj <- readRDS(file.path("testdata", "input.rc.calibrate.ri.rds")) 4 | expected <- readRDS(file.path("testdata", "rc.calibrate.ri.rds")) 5 | 6 | actual <- rc.calibrate.ri( 7 | ramclustObj = ramclustObj, 8 | calibrant.data = calibrant.data 9 | ) 10 | expect_equal(actual, expected) 11 | }) 12 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.expand.sample.names.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.expand.sample.names", { 2 | expected <- readRDS(file.path("testdata", "rc.expand.sample.names.rds")) 3 | ramclustObj <- readRDS(file.path("testdata", "rc.get.xcms.data.rds")) 4 | 5 | actual <- rc.expand.sample.names(ramclustObj = ramclustObj, quiet=TRUE) 6 | 7 | # renamed phenoData colnames as test fails in R CMD checks becuase of no user input for colnames 8 | colnames(actual$phenoData) <- colnames(expected$phenoData) 9 | 10 | expect_equal(actual, expected) 11 | }) 12 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.feature.filter.blanks.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.feature.filter.blanks", { 2 | ramclustObj <- readRDS(file.path("testdata", "rc.feature.replace.na.rds")) 3 | expected <- readRDS(file.path("testdata", "rc.feature.filter.blanks.rds")) 4 | actual <- rc.feature.filter.blanks(ramclustObj = ramclustObj, qc.tag = c("QC", "sample.names.sample_name"), blank.tag = c("Blanc", "sample.names.sample_name")) 5 | 6 | # slight change in 'history' language causing error. unimportant, so just remove. 7 | expected$history <- NULL 8 | actual$history <- NULL 9 | 10 | expect_equal(actual, expected) 11 | }) 12 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.feature.filter.cv.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.feature.filter.cv", { 2 | ramclustObj <- readRDS(file.path("testdata", "rc.feature.normalize.qc.rds")) 3 | expected <- readRDS(file.path("testdata", "rc.feature.filter.cv.rds")) 4 | 5 | actual <- rc.feature.filter.cv(ramclustObj = ramclustObj, qc.tag = c("QC", "sample.names.sample_name")) 6 | 7 | ## remove history and params to keep them from triggering failure 8 | expected$history <- NULL 9 | expected$params <- NULL 10 | actual$history <- NULL 11 | actual$params <- NULL 12 | 13 | expect_equal(actual, expected) 14 | }) 15 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.feature.normalize.batch.qc.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.feature.normalize.batch.qc", { 2 | ramclustObj <- readRDS(file.path("testdata", "rc.feature.filter.blanks.rds")) 3 | expected <- readRDS(file.path("testdata", "rc.feature.normalize.batch.qc.rds")) 4 | metadata <- read_metadata(file.path("testdata", "testMetadata.csv")) 5 | 6 | actual <- rc.feature.normalize.batch.qc( 7 | order = metadata$order, 8 | batch = metadata$batch, 9 | qc = metadata$qc, 10 | ramclustObj = ramclustObj, 11 | qc.inj.range = 20 12 | ) 13 | 14 | expect_equal(actual, expected) 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.feature.normalize.qc.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.feature.normalize.qc", { 2 | ramclustObj <- readRDS(file.path("testdata", "rc.feature.filter.blanks.rds")) 3 | expected <- readRDS(file.path("testdata", "rc.feature.normalize.qc.rds")) 4 | metadata <- read_metadata(file.path("testdata", "testMetadata.csv")) 5 | 6 | actual <- rc.feature.normalize.qc( 7 | ramclustObj = ramclustObj, 8 | batch = metadata$batch, 9 | order = metadata$order, 10 | qc = metadata$qc 11 | ) 12 | 13 | actual$history <- NA 14 | expected$history <- NA 15 | actual$params$rc.feature.normalize.qc <- NA 16 | expected$params$rc.feature.normalize.qc <- NA 17 | 18 | expect_equal(actual, expected) 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.feature.normalize.quantile.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.feature.normalize.quantile", { 2 | ramclustObj <- readRDS(file.path("testdata", "rc.feature.filter.blanks.rds")) 3 | expected <- readRDS(file.path("testdata", "rc.feature.normalize.quantile.rds")) 4 | 5 | actual <- rc.feature.normalize.quantile(ramclustObj = ramclustObj) 6 | expect_equal(actual, expected) 7 | }) 8 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.feature.normalize.tic.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.feature.normalize.quantile", { 2 | ramclustObj <- readRDS(file.path("testdata", "rc.feature.filter.blanks.rds")) 3 | expected <- readRDS(file.path("testdata", "rc.feature.normalize.tic.rds")) 4 | 5 | actual <- rc.feature.normalize.tic(ramclustObj = ramclustObj) 6 | 7 | expect_equal(actual, expected) 8 | }) 9 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.feature.replace.na.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.feature.replace.na", { 2 | set.seed(123) # to get reproducible results with jitters 3 | ramclustObj <- readRDS(file.path("testdata", "rc.expand.sample.names.rds")) 4 | expected <- readRDS(file.path("testdata", "rc.feature.replace.na.rds")) 5 | 6 | actual <- rc.feature.replace.na(ramclustObj = ramclustObj) 7 | 8 | # slight change in 'history' language causing error. unimportant, so just remove. 9 | expected$history <- NULL 10 | actual$history <- NULL 11 | 12 | ## test that there are zero NA present 13 | expect_true(length(which(is.na(actual$MSdata))) == 0) 14 | }) 15 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.get.csv.data.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.get.csv.data", { 2 | filename <- file.path("testdata", "peaks.csv") 3 | phenoData <- file.path("testdata", "phenoData.csv") 4 | expected <- readRDS(file.path("testdata", "rc.get.csv.data.rds")) 5 | 6 | actual <- rc.get.csv.data(csv = filename, phenoData = phenoData, st = 5) 7 | 8 | expect_equal(actual, expected) 9 | }) 10 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.get.df.data.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.get.df.data", { 2 | phenoData <- readRDS(file.path("testdata", "phenoData_df.rds")) 3 | expected <- readRDS(file.path("testdata", "rc.get.df.data.rds")) 4 | ms1_featureDefinitions <- readRDS(file.path("testdata", "ms1_featureDefinitions.rds")) 5 | ms1_featureValues <- readRDS(file.path("testdata", "ms1_featureValues.rds")) 6 | 7 | actual <- rc.get.df.data( 8 | ms1_featureDefinitions = ms1_featureDefinitions, 9 | ms1_featureValues = ms1_featureValues, 10 | phenoData = phenoData, 11 | st = 5 12 | ) 13 | expect_equal(actual, expected) 14 | }) 15 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.get.xcms.data.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.get.xcms.data", { 2 | skip_if_not_installed("xcms") 3 | 4 | load(file.path("testdata", "test.fillpeaks")) 5 | expected <- readRDS(file.path("testdata", "rc.get.xcms.data.rds")) 6 | 7 | actual <- rc.get.xcms.data(xcmsObj = xdata) 8 | 9 | actual$history <- NA 10 | expected$history <- NA 11 | 12 | expect_equal(actual, expected) 13 | }) -------------------------------------------------------------------------------- /tests/testthat/test-rc.qc.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.qc", { 2 | wd <- getwd() 3 | tmp <- tempdir() 4 | ramclustObj <- readRDS(file.path("testdata", "clustering", "only_rt_rc.ramclustr.rds")) 5 | expected <- readRDS(file.path("testdata", "rc.qc.rds")) 6 | 7 | setwd(tmp) 8 | 9 | actual <- rc.qc(ramclustObj = ramclustObj, qc.tag = c("QC", "sample.names.sample_name")) 10 | 11 | expect_equal(actual, expected) 12 | 13 | setwd(wd) 14 | }) 15 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.ramclustr.R: -------------------------------------------------------------------------------- 1 | patrick::with_parameters_test_that("RAMClustR rc.ramclustr", { 2 | ramclustObj <- readRDS(file.path("testdata", "rc.feature.filter.cv.rds")) 3 | expected_path <- file.path("testdata", "clustering", paste0(.test_name,"_rc.ramclustr.rds")) 4 | expected <- readRDS(expected_path) 5 | 6 | actual <- rc.ramclustr(ramclustObj = ramclustObj, rt.only.low.n=rt_only_low_n) 7 | 8 | expect_equal(actual, expected) 9 | }, 10 | rt_only_low_n = list(TRUE, FALSE), 11 | .test_name = list("only_rt", "normal") 12 | ) 13 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.remove.qc.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.remove.qc", { 2 | ramclustObj <- readRDS(file.path("testdata", "rc.get.xcms.data.rds")) 3 | expected <- readRDS(file.path("testdata", "rc.remove.qc.rds")) 4 | 5 | actual <- rc.remove.qc(ramclustObj = ramclustObj, qc.tag = c("QC", "sample.names.sample_name")) 6 | 7 | ## remove history and params to keep them from triggering failure 8 | expected$history <- NULL 9 | expected$params <- NULL 10 | actual$history <- NULL 11 | actual$params <- NULL 12 | 13 | expect_equal(actual, expected) 14 | }) 15 | -------------------------------------------------------------------------------- /tests/testthat/test-rc.restore.qc.samples.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR rc.restore.qc.samples", { 2 | ramclustObj <- readRDS(file.path("testdata", "rc.remove.qc.rds")) 3 | expected <- readRDS(file.path("testdata", "rc.restore.qc.samples.rds")) 4 | 5 | actual <- rc.restore.qc.samples(ramclustObj = ramclustObj) 6 | 7 | expect_equal(actual, expected) 8 | }) 9 | -------------------------------------------------------------------------------- /tests/testthat/test-stepwise-workflow.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR workflow with xcms works", { 2 | skip_if_not_installed("xcms") 3 | set.seed(123) # to get reproducible results with jitters 4 | wd <- getwd() 5 | tmp <- tempdir() 6 | load(file.path("testdata", "test.fillpeaks")) 7 | expected <- readRDS(file.path("testdata", "do.findmain.rds")) 8 | metadata <- read_metadata(file.path("testdata", "testMetadata.csv")) 9 | setwd(tmp) 10 | 11 | ramclustObj <- rc.get.xcms.data(xcmsObj = xdata) 12 | ramclustObj <- rc.expand.sample.names(ramclustObj = ramclustObj, quiet = TRUE) 13 | ramclustObj <- rc.feature.replace.na(ramclustObj = ramclustObj) 14 | ramclustObj <- rc.feature.filter.blanks(ramclustObj = ramclustObj, qc.tag = c("QC", "sample.names.sample_name"), blank.tag = c("Blanc", "sample.names.sample_name")) 15 | ramclustObj <- rc.feature.normalize.qc( 16 | ramclustObj = ramclustObj, 17 | batch = metadata$batch, 18 | order = metadata$order, 19 | qc = metadata$qc 20 | ) 21 | ramclustObj <- rc.feature.filter.cv(ramclustObj = ramclustObj, qc.tag = c("QC", "sample.names.sample_name")) 22 | ramclustObj <- rc.ramclustr(ramclustObj = ramclustObj) 23 | ramclustObj <- rc.qc(ramclustObj = ramclustObj, qc.tag = c("QC", "sample.names.sample_name")) 24 | actual <- do.findmain(ramclustObj = ramclustObj) 25 | 26 | # renamed phenoData colnames as test fails in R CMD checks becuase of no user input for colnames 27 | colnames(actual$phenoData) <- colnames(expected$phenoData) 28 | 29 | actual$history <- NULL 30 | expected$history <- NULL 31 | actual$params <- NULL 32 | expected$params <- NULL 33 | 34 | expect_equal(actual, expected) 35 | 36 | setwd(wd) 37 | }) 38 | -------------------------------------------------------------------------------- /tests/testthat/test-workflow-comparison.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR workflow comparison test", { 2 | skip_if_not_installed("xcms") 3 | wd <- getwd() 4 | tmp <- tempdir() 5 | load(file.path("testdata", "test.fillpeaks")) 6 | setwd(tmp) 7 | 8 | ramclustr_obj <- ramclustR(xcmsObj = xdata, maxt = 20, sr = 0.5) 9 | 10 | ramclustObj <- rc.get.xcms.data(xcmsObj = xdata) 11 | ramclustObj <- rc.feature.replace.na(ramclustObj = ramclustObj) 12 | ramclustObj <- rc.feature.normalize.tic(ramclustObj = ramclustObj) 13 | ramclustObj <- rc.ramclustr(ramclustObj = ramclustObj, sr = 0.5, maxt = 20) 14 | 15 | expect_equal_labels(ramclustObj$labels, ramclustr_obj$labels) 16 | expect_equal(ramclustObj$height, ramclustr_obj$height) 17 | expect_equal(ramclustObj$frt, ramclustr_obj$frt) 18 | expect_equal(ramclustObj$fmz, ramclustr_obj$fmz) 19 | expect_equal(ramclustObj$SpecAbund, ramclustr_obj$SpecAbund, tolerance = 0.01) 20 | 21 | filenames <- xcms::fileNames(xdata) 22 | dimnames(ramclustr_obj$MSdata)[[1]] <- filenames 23 | 24 | expect_equal(ramclustObj$MSdata, ramclustr_obj$MSdata, tolerance = 0.01) 25 | 26 | setwd(wd) 27 | }) 28 | -------------------------------------------------------------------------------- /tests/testthat/test.R: -------------------------------------------------------------------------------- 1 | test_that("RAMClustR with xcms works", { 2 | skip_if_not_installed("xcms") 3 | set.seed(123) # to get reproducible results with jitters 4 | wd <- getwd() 5 | tmp <- tempdir() 6 | load(file.path("testdata", "test.fillpeaks")) 7 | expected <- readLines(file.path("testdata", "output.msp")) 8 | 9 | setwd(tmp) 10 | 11 | ramclustr_obj <- ramclustR(xcmsObj = xdata, maxt = 20, sr = 0.5, mzdec = 4) 12 | write.msp(ramclustr_obj, one.file = TRUE) 13 | mismatches <- setdiff(expected, readLines(file.path("spectra", "fill.msp"))) 14 | 15 | expect_true(length(mismatches) < 10) 16 | setwd(wd) 17 | }) 18 | 19 | test_that("RAMClustR with csv works", { 20 | wd <- getwd() 21 | tmp <- tempdir() 22 | filename <- file.path(wd, "testdata/peaks.csv") 23 | pheno <- file.path(wd, "testdata/phenoData.csv") 24 | expected <- readRDS(file.path("testdata", "test_csv.rds")) 25 | 26 | setwd(tmp) 27 | actual <- ramclustR( 28 | ms = filename, 29 | pheno_csv = pheno, 30 | st = 5, 31 | maxt = 1, 32 | blocksize = 1000 33 | ) 34 | 35 | actual$history <- NA 36 | expected$history <- NA 37 | 38 | expect_equal_labels(actual$labels, expected$labels) 39 | expect_equal_MSdata(actual$MSdata, expected$MSdata) 40 | 41 | actual$labels <- expected$labels <- actual$MSdata <- expected$MSdata <- NA 42 | 43 | expect_equal(actual, expected) 44 | setwd(wd) 45 | }) 46 | -------------------------------------------------------------------------------- /tests/testthat/testdata/calibrant.data.csv: -------------------------------------------------------------------------------- 1 | ri, rt 2 | 1100," 2.06" 3 | 1200," 2.39" 4 | 1300," 2.73" 5 | 1400," 3.07" 6 | 1500," 3.4" 7 | 1600," 3.71" 8 | 1700," 4.09" 9 | 1800," 4.48" 10 | 1900," 4.8" 11 | 2000," 5.12" 12 | 2100," 5.42" 13 | 2200," 5.69" 14 | 2300," 5.99" 15 | 2400," 6.29" 16 | 2500," 6.56" 17 | 2600," 6.8" 18 | 2700," 7.01" 19 | 2800," 7.2" 20 | 2900," 7.37" 21 | 3000," 7.55" 22 | 3100," 7.72" 23 | 3200," 7.91" 24 | 3300," 8.12" 25 | 3400," 8.35" 26 | 3500," 8.62" 27 | 3600," 8.92" 28 | 3700," 9.27" 29 | 3800," 9.69" 30 | 3900," 10.16" 31 | 4000," 10.73" 32 | -------------------------------------------------------------------------------- /tests/testthat/testdata/clustering/normal_rc.ramclustr.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/clustering/normal_rc.ramclustr.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/clustering/only_rt_rc.ramclustr.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/clustering/only_rt_rc.ramclustr.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/do.findmain.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/do.findmain.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/input.rc.calibrate.ri.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/input.rc.calibrate.ri.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/ms1_featureDefinitions.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/ms1_featureDefinitions.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/ms1_featureValues.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/ms1_featureValues.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/output.msp: -------------------------------------------------------------------------------- 1 | NAME:C1 2 | IONMODE:Negative 3 | SPECTRUMTYPE:Centroid 4 | RETENTIONTIME:49.42 5 | Num Peaks:9 6 | 112.9854 23883174 7 | 96.9692 6271185 8 | 128.9594 3399048 9 | 102.9565 2993255 10 | 180.9726 2950745 11 | 142.9748 1205256 12 | 294.9525 477345 13 | 176.8926 98519 14 | 184.8312 97987 15 | 16 | NAME:C2 17 | IONMODE:Negative 18 | SPECTRUMTYPE:Centroid 19 | RETENTIONTIME:63.88 20 | Num Peaks:8 21 | 191.0193 19783354 22 | 173.009 4462005 23 | 111.0086 1823353 24 | 129.0192 1553098 25 | 192.0223 1231832 26 | 85.0294 815391 27 | 87.0087 693187 28 | 359.0473 569529 29 | 30 | NAME:C3 31 | IONMODE:Negative 32 | SPECTRUMTYPE:Centroid 33 | RETENTIONTIME:59.06 34 | Num Peaks:7 35 | 149.0451 5591420 36 | 151.0067 2693689 37 | 166.0174 611655 38 | 177.0401 512718 39 | 75.0087 501709 40 | 209.066 176699 41 | 178.0633 154369 42 | 43 | NAME:C4 44 | IONMODE:Negative 45 | SPECTRUMTYPE:Centroid 46 | RETENTIONTIME:55.68 47 | Num Peaks:7 48 | 135.0295 7186586 49 | 179.056 4062674 50 | 195.0506 1858656 51 | 165.0401 1481223 52 | 61.9883 1319274 53 | 148.0279 666633 54 | 180.0589 177968 55 | 56 | NAME:C5 57 | IONMODE:Negative 58 | SPECTRUMTYPE:Centroid 59 | RETENTIONTIME:53.77 60 | Num Peaks:6 61 | 187.0372 1297151 62 | 80.9748 839611 63 | 146.0145 775702 64 | 219.0448 410412 65 | 189.0327 329058 66 | 159.024 170034 67 | 68 | NAME:C6 69 | IONMODE:Negative 70 | SPECTRUMTYPE:Centroid 71 | RETENTIONTIME:62.48 72 | Num Peaks:3 73 | 119.0346 4305586 74 | 101.0241 298307 75 | 133.0139 126874 76 | 77 | -------------------------------------------------------------------------------- /tests/testthat/testdata/phenoData.csv: -------------------------------------------------------------------------------- 1 | sample_name,class 2 | dataset_10908,sample 3 | dataset_10909,sample 4 | dataset_10910,sample 5 | -------------------------------------------------------------------------------- /tests/testthat/testdata/phenoData_df.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/phenoData_df.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.calibrate.ri.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.calibrate.ri.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.expand.sample.names.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.expand.sample.names.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.feature.filter.blanks.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.feature.filter.blanks.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.feature.filter.cv.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.feature.filter.cv.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.feature.normalize.batch.qc.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.feature.normalize.batch.qc.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.feature.normalize.qc.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.feature.normalize.qc.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.feature.normalize.quantile.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.feature.normalize.quantile.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.feature.normalize.tic.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.feature.normalize.tic.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.feature.replace.na.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.feature.replace.na.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.get.csv.data.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.get.csv.data.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.get.df.data.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.get.df.data.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.get.xcms.data.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.get.xcms.data.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.qc.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.qc.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.remove.qc.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.remove.qc.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/rc.restore.qc.samples.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/rc.restore.qc.samples.rds -------------------------------------------------------------------------------- /tests/testthat/testdata/test.fillpeaks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/test.fillpeaks -------------------------------------------------------------------------------- /tests/testthat/testdata/testMetadata.csv: -------------------------------------------------------------------------------- 1 | sample_name,class,sampleType,injectionOrder,batch 2 | QC1_008,QC,QC,105,1 3 | QC1_014,QC,QC,185,1 4 | HU_neg_192,sample,sample,165,1 5 | -------------------------------------------------------------------------------- /tests/testthat/testdata/test_csv.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/tests/testthat/testdata/test_csv.rds -------------------------------------------------------------------------------- /vignettes/ExpDes.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbroeckl/RAMClustR/2871646f20e2ccf53181e8d91e35bd28c6548756/vignettes/ExpDes.csv --------------------------------------------------------------------------------