## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width=8, 
  fig.height=8
)

## ---- message=FALSE, warning=FALSE--------------------------------------------
library(MSstatsPTM)

## ---- eval = FALSE------------------------------------------------------------
#  if (!requireNamespace("BiocManager", quietly = TRUE))
#      install.packages("BiocManager")
#  
#  BiocManager::install("MSstatsPTM")

## ----raw_data_ptm, eval = FALSE-----------------------------------------------
#  # Run MSstatsPTM converter with modified and unmodified datasets.
#  raw.input <- MaxQtoMSstatsPTMFormat(raw_ptm_df, annotation, evidence_file,
#                                      proteinGroupsfile)

## ----raw_data, eval = FALSE---------------------------------------------------
#  # Add site into ProteinName column
#  raw_ptm_df$ProteinName <- paste(raw_ptm_df$ProteinName,
#                                  raw_ptm_df$Site, sep = "_")
#  
#  # Run MSstats Converters
#  PTM.data <- MaxQtoMSstatsTMTFormat(raw_ptm_df)
#  PROTEIN.data <- MaxQtoMSstatsTMTFormat(raw_protein_df)
#  
#  # Combine into one list
#  raw.input <- list(PTM = PTM.data,
#                    PROTEIN = PROTEIN.data)

## -----------------------------------------------------------------------------
head(raw.input.tmt$PTM)
head(raw.input.tmt$PROTEIN)

## ----summarize, echo=FALSE, message=FALSE, warning=FALSE----------------------

MSstatsPTM.summary <- dataSummarizationPTM_TMT(raw.input.tmt, verbose = FALSE)

## ----show_summ----------------------------------------------------------------
head(MSstatsPTM.summary$PTM$ProteinLevelData)
head(MSstatsPTM.summary$PROTEIN$ProteinLevelData)

## ----qcplot, message=FALSE, warning=FALSE-------------------------------------

dataProcessPlotsPTM(MSstatsPTM.summary,
                    type = 'QCPLOT',
                    which.PTM = "allonly",
                    address = FALSE)

## ----profileplot, message=FALSE, warning=FALSE--------------------------------
dataProcessPlotsPTM(MSstatsPTM.summary,
                    type = 'PROFILEPLOT',
                    which.Protein = c("Protein_12"),
                    address = FALSE)

## ----model, message=FALSE, warning=FALSE--------------------------------------

# Specify contrast matrix
comparison <- matrix(c(1,0,0,-1,0,0,
                       0,1,0,0,-1,0,
                       0,0,1,0,0,-1,
                       1,0,-1,0,0,0,
                       0,1,-1,0,0,0,
                       0,0,0,1,0,-1,
                       0,0,0,0,1,-1),nrow=7, ncol=6, byrow=TRUE)

# Set the names of each row
row.names(comparison)<-c('1-4', '2-5', '3-6', '1-3', 
                         '2-3', '4-6', '5-6')
colnames(comparison) <- c('Condition_1','Condition_2','Condition_3',
                          'Condition_4','Condition_5','Condition_6')
MSstatsPTM.model <- groupComparisonPTM(MSstatsPTM.summary,
                                       data.type = "TMT",
                                       contrast.matrix = comparison)
head(MSstatsPTM.model$PTM.Model)
head(MSstatsPTM.model$PROTEIN.Model)
head(MSstatsPTM.model$ADJUSTED.Model)

## ----volcano, message=FALSE, warning=FALSE------------------------------------
groupComparisonPlotsPTM(data = MSstatsPTM.model,
                        type = "VolcanoPlot",
                        which.Comparison = c('1-4'),
                        which.PTM = 1:50,
                        address=FALSE)

## ----meatmap, message=FALSE, warning=FALSE------------------------------------
groupComparisonPlotsPTM(data = MSstatsPTM.model,
                        type = "Heatmap",
                        which.PTM = 1:49,
                        address=FALSE)

