knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  # fig.width = 7, 
  # fig.height = 5,
  warning = FALSE,
  message = TRUE,
  out.width = "100%"
)


Download demo data


Raw data can be downloaded from the Google drive. Link is here


Data preparation


massprocesser can used to processed the raw MS data for peak detection and alignment, and generate a peak table for next analysis.

The MS raw data from Mass Spectrometry should be converted to mzXML or mzMLformat and then placed in different folders according to their class, for example Subject, QC, and Blank samples.

You can convert raw MS data to mzXML or mzML format using ProteoWizard software. And the parameter setting is shown the below figure:

Data organization


All the mzXML format files should be placed in different folder according to sample type, such as QC, Subject, Control, Case, and Blank.


Run process_data() function


This function is used to peak picking and peak alignment.

library(massprocesser)
library(tidyverse)
library(xcms)
library(MSnbase)
library(mzR)

Data processing

Next, we use the process_data() function for peak detection and alignment.

We first do the positive mode.

massprocesser::process_data(
  path = "massprocesser_demo_data/POS/",
  polarity = "positive",
  ppm = 15,
  peakwidth = c(10, 60),
  snthresh = 5,
  noise = 500,
  threads = 6,
  output_tic = TRUE,
  output_bpc = TRUE,
  output_rt_correction_plot = TRUE,
  min_fraction = 0.5,
  fill_peaks = FALSE,
  group_for_figure = "QC"
)

Some important arguments:

Other parameters you can find here: process_data().


Output results


After all done, all the results are placed in a new folder named as Result.

object

object is a mass_dataset class object which can be used for next analysis. See more about mass_dataset class here.

load("massprocesser_demo_data/POS/Result/object")
library(massdataset)
object

Peak_table.csv

The peak table for next analysis.

data = readr::read_csv("massprocesser_demo_data/POS/Result/Peak_table.csv")
library(kableExtra)
library(magrittr)
kbl(data[1:500,]) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"),
                fixed_thead = TRUE) %>% 
  scroll_box(width = "100%", height = "600px")

Only top 500 features show.

Peak_table_for_cleaning.csv

Some usefulness columns are deleted from the Peak_table.csv, this can be directory used for next data cleaning.

data = readr::read_csv("massprocesser_demo_data/POS/Result/Peak_table_for_cleaning.csv")
library(kableExtra)
library(magrittr)
kbl(data[1:500,]) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"),
                fixed_thead = TRUE) %>% 
  scroll_box(width = "100%", height = "600px")

Only top 500 features show.

BPC.pdf

Base peak chromatogram.

Default it only shows the samples which are in the group you set in group_for_figure. If you want to show other samples, you can try to do use the below script.

###load data
load("massprocesser_demo_data/POS/Result/intermediate_data/xdata2")
##set threads
if(tinytools::get_os() == "windows") {
  bpparam <-
    BiocParallel::SnowParam(workers = 4,
                            progressbar = TRUE)
} else{
  bpparam <- BiocParallel::MulticoreParam(workers = 4,
                                          progressbar = TRUE)
}
###extract bpc plot object
bpc.plot <- xcms::chromatogram(object = xdata2,
                               aggregationFun = "max",
                               BPPARAM = bpparam)
####plot_chromatogram to show the plot
##set the group_for_figure if you want to show specific groups. And set it as "all" if you want to show all samples.
plot <- plot_chromatogram(object = bpc.plot,
                          title = "BPC",
                          group_for_figure = c("Case", "QC"))
plot
plot <- plot_chromatogram(object = bpc.plot,
                          title = "BPC",
                          group_for_figure = c("all"))
plot
##if you want to show specific samples, set the `sample_for_figure` parameter
plot <- plot_chromatogram(object = bpc.plot,
                          title = "BPC",
                          sample_for_figure = c("sample_11", "sample_78"))
plot
##set `interactive` as TRUE to get interactive plot
plot <- plot_chromatogram(object = bpc.plot,
                          title = "BPC",
                          sample_for_figure = c("sample_11", "sample_78"),
                          interactive = TRUE
                          )
plot

TIC.pdf

Total ion peak chromatogram

Default it only shows the samples which are in the group you set in group_for_figure. If you want to show other samples, you can try to do use the below script.

###load data
load("massprocesser_demo_data/POS/Result/intermediate_data/xdata2")
##set threads
if(tinytools::get_os() == "windows") {
  bpparam <-
    BiocParallel::SnowParam(workers = 4,
                            progressbar = TRUE)
} else{
  bpparam <- BiocParallel::MulticoreParam(workers = 4,
                                          progressbar = TRUE)
}
###extract tic plot object
tic.plot <- xcms::chromatogram(object = xdata2,
                               aggregationFun = "sum",
                               BPPARAM = bpparam)
####plot_chromatogram to show the plot
##set the group_for_figure if you want to show specific groups. And set it as "all" if you want to show all samples.
plot <- plot_chromatogram(object = tic.plot,
                          title = "TIC",
                          group_for_figure = c("Case", "QC"))
plot
plot <- plot_chromatogram(object = tic.plot,
                          title = "TIC",
                          group_for_figure = c("all"))
plot
##if you want to show specific samples, set the `sample_for_figure` parameter
plot <- plot_chromatogram(object = tic.plot,
                          title = "TIC",
                          sample_for_figure = c("sample_11", "sample_78"))
plot
##set `interactive` as TRUE to get interactive plot
plot <- plot_chromatogram(object = tic.plot,
                          title = "TIC",
                          sample_for_figure = c("sample_11", "sample_78"),
                          interactive = TRUE
                          )
plot

RT correction plot.pdf

RT correction.

Default it only shows the samples which are in the group you set in group_for_figure. If you want to show other samples, you can try to do use the below script.

###load data
load("massprocesser_demo_data/POS/Result/intermediate_data/xdata2")
##set the group_for_figure if you want to show specific groups. And set it as "all" if you want to show all samples.
plot = 
plot_adjusted_rt(object = xdata2, 
                 group_for_figure = c("Case", "QC"))
plot
plot = 
plot_adjusted_rt(object = xdata2, 
                 group_for_figure = "all")
plot
plot = 
plot_adjusted_rt(object = xdata2, 
                sample_for_figure = c("sample_11", "sample_78"))
plot
plot = 
plot_adjusted_rt(object = xdata2, 
                sample_for_figure = "all", 
                interactive = TRUE)
plot

intermediate_data

This is a folder which contains some intermediate data. If you want to re-run the data processing, please delete this folder first.


Session information


sessionInfo()


tidymass/massprocesser documentation built on May 7, 2023, 10:18 p.m.