%\VignetteIndexEntry{Howto find putative ptm marker ion?}
\documentclass[nojss]{jss}
\usepackage[utf8]{inputenc}
\usepackage{rotating}

\author{Christian~Panse\thanks{
Correspondence: Christian~Panse,
Functional Genomics Center Zurich,
Winterthurerstr. 190,
CH-8057, Z{\"u}rich, Switzerland,
Telephone: +41-44-63-53910,
E-mail: \texttt{cp@fgcz.ethz.ch}}\\
Functional Genomics Center Zurich
\And
Paolo~Nanni\thanks{
Paolo~Nanni,
Functional Genomics Center Zurich,
Winterthurerstr. 190,
CH-8057, Z{\"u}rich, Switzerland,
Telephone: +41-44-63-53930,
E-mail: \texttt{paolo.nanni@fgcz.uzh.ch}}\\
Functional Genomics Center Zurich
}

\title{On Finding putative PTM (pPTM) Marker Ion in HCD scans using \code{PTM\_MarkerFinder}}

\Plainauthor{Christian Panse, Paolo Nanni}
\Plaintitle{On Finding putative PTM (pPTM) Marker Ion in HCD scans using \code{PTM\_MarkerFinder}}
\Shorttitle{PTM MarkerFinder}

\Abstract{
Glycopeptides as well as acetylated, methylated and other modified peptides release 
specific fragment ions during CID (collision-induced dissociation) and HCD (higher energy 
collisional dissociation) fragmentation. These fragment ions can be used to validate the 
presence of the PTM (post translational modifications) on the peptides. 
\code{PTM\_MarkerFinder}, 
an R function of the \pkg{protViz} package that takes advantage of such marker ions. 
\code{PTM\-\_MarkerFinder} scans the 
MS/MS spectra in the output of a peptide spectrum match search, 
e.g., Mascot, for marker 
ions specific for selected PTMs.

While the  software tool has been described by \citet{pPTM} here we provide 
a step-by-step guide 
on how the software can be used.
}

\Keywords{MarkerFinder, putative post translational modifications, R}
\Plainkeywords{MarkerFinder, putative post translational modifications, R} %% without formatting

\Submitdate{2016-09-01}

\Address{
Paolo Nanni and Christian Panse\\
UZH\texttt{|}ETH Z{\"u}rich\\
Functional Genomics Center Zurich\\
Winterthurerstr. 190\\
CH-8057, Z{\"u}rich, Switzerland\\
Telephone: +41/44/63-53910
}



\begin{document}
\SweaveOpts{concordance=TRUE}
<<echo = FALSE, eval = TRUE>>=
options(prompt = "R> ", continue = "+  ", width = 70, useFancyQuotes = FALSE)
@

\section{Howto get the software and data}
The method for finding the marker ions is contained in the R package \pkg{protViz} 
available through CRAN using \url{https://cran.r-project.org/package=protViz}.
The package requires R \citep{R} installed.

The minimal data structure requirement for the \code{PTM\_MarkerFinder} function looks as follow. 

<<keep.source = FALSE, eval = TRUE, fig = FALSE>>=
library(protViz)
data(HexNAc)
str(HexNAc[[1]], nchar.max=30)
@
Here we have listed the \code{HexNAc} data which is included in \pkg{protViz}.

\pkg{protViz} also provides and perl script \code{protViz\_mascotDat2RData.pl}\footnote{The prefix \code{protViz\_} is used to benefit from the \code{bash} tab completion.} taking mascot server dat files as input and producing RData output.

\begin{verbatim}
$ /usr/local/lib/R/site-library/protViz/exec/protViz_mascotDat2RData.pl \
  -d=/usr/local/mascot/data/20130116/F178287.dat \
  -m=$HOME/mod_file
\end{verbatim}

\code{mascotDat2RData.pl} requires the mascot server \code{mod\_file} keeping all the configured modification of the mascot server.

In theory \code{PTM\_MarkerFinder} can process the output of any search engine for peptide identification. It is up to the R user writing a wrapper script converting the output of any particular peptide identification search engine to the data structure listed above.

\section{Finding the Marker Ions}
\subsection{HexNAc -- Example}

\code{PTM\_MarkerFinder} can search for any Marker ion series. The next lines define the \code{HexNAc\_MarkerIons}.

<<>>=
HexNAc_MarkerIons <- c(126.05495, 138.05495, 144.06552,
   168.06552, 186.07608, 204.08665)
@

The lines below configure the modification information used by the search engine.
The HexNAc modification below is described on unimod \url{http://www.unimod.org/modifications_view.php?editid1=43}.

<<>>=
ptm.0 <- cbind(AA = "-",
	mono = 0.0, avg = 0.0, desc = "unmodified", unimodAccID = NA)

ptm.1 <- cbind(AA='N', 
	mono = 317.122300, avg = NA, desc = "HexNAc",
        unimodAccID=2)
             
ptm.2 <- cbind(AA='M',
	mono = 147.035400, avg = NA, desc = "Oxidation",
        unimodAccID=1)
     
m <- as.data.frame(rbind(ptm.0, ptm.1, ptm.2))
@

\code{PTM\_MarkerFinder} is called.


<<>>=
S <- PTM_MarkerFinder(data = HexNAc,
	modification = m$mono, 
	modificationName = m$desc,
        minMarkerIntensityRatio = 3,
        itol_ppm = 20,
        mZmarkerIons = HexNAc_MarkerIons) 
@

The content of \code{S} can be seen in the Table below.
%\ref{Table:xtable1}.

<<xtable1, results=tex, echo=FALSE>>=
library(xtable)
print(xtable(S, caption="Result",  label="Table:xtable1"), include.rownames=FALSE, scalebox="0.5")
@


<<>>=
summary(S)
@

\paragraph{Some overview graphics}

just an overview of the sample data set \code{HexNAc}.

<<label=example1, keep.source = TRUE, eval = TRUE, fig = TRUE, include=FALSE>>=
op <- par(mfrow = c(2, 2), mar=c(4, 4, 4, 1))

dump <- lapply(split(S, S$query), 
    function(x){ 
      plot(x$mZ, x$markerIonIntensity, 
        type = 'h',
        col = 'lightblue',
        cex = 2,
        ylab = 'intensity', xlab='m/z',
        xlim = range(c(HexNAc_MarkerIons,  
            max(HexNAc_MarkerIons) 
                + 0.1 * (max(HexNAc_MarkerIons) - min(HexNAc_MarkerIons)), 
            min(HexNAc_MarkerIons) 
                - 0.1 * (max(HexNAc_MarkerIons) - min(HexNAc_MarkerIons)))),
        ylim = range(S$markerIonIntensity),
            log = 'y',
            main = paste("scan=", unique(x$scans),
                "/query=", unique(x$query), sep='')); 
            text(x$mZ, x$markerIonIntensity, 
                round(x$mZ,2),col='red',cex=0.7)
        }
    )
par(op)
@


Figure \ref{fig:example1} dislays the output of \code{PTM\_MarkerFinder}.

\begin{figure}[ht]
\centering
\resizebox{.75\textwidth}{!}{
        \includegraphics{PTM_MarkerFinder-example1}
}

\caption{\label{fig:example1}Overview of the marker ions.}
\end{figure}


\subsection{Reshaping the output and export}

The R method \code{reshape} transforms the data frame \code{S} from a 
long format to a wide format.


<<>>=
names(S)[4] <- "mII"
S.wide <- reshape(S[,c(1,7,3,4)],
                  direction = 'wide', 
                  timevar = "markerIonMZ", 
                  idvar = c('scans','query'))

@

<<xtable2, results=tex, echo=FALSE>>=
library(xtable)
print(xtable(S.wide, caption="Result",  label="Table:xtable2"), include.rownames=FALSE, scalebox=0.8)
@

export as comma separeted file

<<keep.source = TRUE, eval = TRUE, fig = FALSE>>=
write.table(S.wide, 
	file = "HexNAc_PTM_markerFinder.csv",
    	sep = ',', 
	row.names = FALSE,
	col.names = TRUE, 
	quote = FALSE)
@


\subsection{Visualization of the Result}

<<label=example2, eval = TRUE, fig = TRUE, width=18, height=12, echo=TRUE, include=FALSE>>=
# prepare the input
d <- list(); d[[1]] <- HexNAc[[3]]; d[[2]] <- HexNAc[[4]]; d[[3]] <- HexNAc[[5]]
S <- PTM_MarkerFinder(data = d, modification = m$mono, 
	modificationName = m$desc,
        minMarkerIntensityRatio = 3,
        itol_ppm = 20,
        mZmarkerIons = HexNAc_MarkerIons) 
@

The graphics can be seen in Figure \ref{fig:example2}.

\begin{sidewaysfigure}
\centering
\resizebox{1.0\textwidth}{!}{
        \includegraphics{PTM_MarkerFinder-example2}
}

\caption{\label{fig:example2}Graphical output of the method.}
\end{sidewaysfigure}


\section{Demonstartion}

The user can call the demonstration with 
<<eval = FALSE>>=
demo(PTM_MarkerFinder) 
@

\subsection{Other examples}

The following ADP-Ribose marker ions configuration was described by \citet{pmid28035797}.
<<>>=
ADP_Ribose <- c(136.0618, 250.0935, 348.0704, 428.0367)
@

\section{Session information}

An overview of the package versions used to produce this document are
shown below.

<<sessioninfo, results=tex, echo=FALSE>>=
toLatex(sessionInfo())
@


\bibliography{protViz}
\end{document}
