## ----style, echo = FALSE, results = 'asis'------------------------------------------------------------------
BiocStyle::markdown()

## ----global_options, include=FALSE--------------------------------------------------------------------------
knitr::opts_chunk$set(fig.width=10, fig.height=7, warning=FALSE, message=FALSE)
options(width=110)

## ----setup--------------------------------------------------------------------------------------------------
library(MSstats)
library(data.table)

## ----load-data----------------------------------------------------------------------------------------------
input_path = system.file("tinytest/raw_data/MZMine/mzmine_input.csv",
                         package = "MSstatsConvert")
annotation_path = system.file("tinytest/raw_data/MZMine/annotation.csv",
                              package = "MSstatsConvert")
mzmine_ann_path = system.file("tinytest/raw_data/MZMine/mzmine_annotations.csv",
                              package = "MSstatsConvert")
sirius_path = system.file("tinytest/raw_data/MZMine/structure_identifications.tsv",
                          package = "MSstatsConvert")

mzmine_input = data.table::fread(input_path)
annotation = data.table::fread(annotation_path)
mzmine_annotations = data.table::fread(mzmine_ann_path)
sirius_annotations = data.table::fread(sirius_path)

head(mzmine_input, 5)
head(annotation)
head(mzmine_annotations)
head(sirius_annotations)

## ----convert, message = FALSE-------------------------------------------------------------------------------
mzmine_msstats = MZMinetoMSstatsFormat(
    input              = mzmine_input,
    annotation         = annotation,
    mzmine_annotations = mzmine_annotations,
    sirius_annotations = sirius_annotations,
    use_log_file       = FALSE
)
head(mzmine_msstats)

## ----summarize, message = FALSE-----------------------------------------------------------------------------
summarized = dataProcess(
    mzmine_msstats,
    logTrans      = 2,
    normalization = "equalizeMedians",
    featureSubset = "all",
    summaryMethod = "TMP",
    censoredInt   = "NA",
    MBimpute      = TRUE,
    use_log_file  = FALSE
)
head(summarized$FeatureLevelData)
head(summarized$ProteinLevelData)

## ----contrast, message = FALSE------------------------------------------------------------------------------
# A contrast matrix has one row per comparison and one column per condition.
# Columns must match the condition levels (alphabetical here: Control, Treatment).
# The -1 / +1 pair selects the two groups being compared.
contrast_matrix = matrix(c(-1, 1), nrow = 1)
colnames(contrast_matrix) = c("Control", "Treatment")
rownames(contrast_matrix) = "Treatment vs Control"
contrast_matrix

comparison = groupComparison(contrast.matrix = contrast_matrix,
                             data = summarized, use_log_file = FALSE)
comparison$ComparisonResult

## ----profile, fig.width = 8, fig.height = 5-----------------------------------------------------------------
dataProcessPlots(summarized,
                 type          = "ProfilePlot",
                 which.Protein = "Caffeine",
                 address       = FALSE)

## ----volcano, eval = FALSE----------------------------------------------------------------------------------
# groupComparisonPlots(data    = comparison$ComparisonResult,
#                      type    = "VolcanoPlot",
#                      address = FALSE)

## ----session------------------------------------------------------------------------------------------------
sessionInfo()

