%
% NOTE -- ONLY EDIT THE .Rnw FILE!!!  The .tex file is
% likely to be overwritten.
%
% \VignetteIndexEntry{Using PPI predictions}
%\VignetteDepends{}
%\VignettePackage{y2hStat}
\documentclass[11pt]{article}

\usepackage{times}
\usepackage{hyperref}

\usepackage[authoryear,round]{natbib}
\usepackage{times}
\usepackage{comment}

\textwidth=6.2in
\textheight=8.5in
%\parskip=.3cm
\oddsidemargin=.1in
\evensidemargin=.1in
\headheight=-.3in

\newcommand{\Rfunction}[1]{{\texttt{#1}}}
\newcommand{\Robject}[1]{{\texttt{#1}}}
\newcommand{\Rpackage}[1]{{\textit{#1}}}
\newcommand{\Rclass}[1]{{\textit{#1}}}

\bibliographystyle{plainnat}

\title{Using Protein Protein Predictions}
\author{R. Gentleman}

\begin{document}

\maketitle

\cite{InfPPI} describe methodology that they employed to make predictions
of protein-protein interactions in \textit{S. cerevisiae}. They have
provided a downloadable set of predicted interactions, from
\url{http://bioinformatics.med.yale.edu/interaction/} and these data are
available as the \Robject{ppipred} data.

<<loadData>>=
library("y2hStat")
data(ppipred)

@

The first two columns are yeast gene names, typically they are common
names and will need to be translated to systematic names for
further processing.

A first decision that should be made is whether to select only those
interaction pairs where the prediction is larger than a specified cut-off.
For our example we will use a cut-off of $0.5$, largely to ensure
that the lists are quite short.

<<restrictbyProb>>=

ppi2 = ppipred[ppipred$Prob >= 0.5,]
dim(ppi2)

@

Now we translate the names.
For now we don't worry too much, but one problem is that in the
\Rpackage{YEAST} package only verified ORFs are used, and so 
the uncharacterized ones are not getting translated. We will need 
some way to do that, in the long run.

<<nameTranslation>>=
library("YEAST")

trN1 = mget(ppi2[[1]], YEASTCOMMON2SYSTEMATIC, ifnotfound=NA)
trN1 = sapply(trN1, function(x) x[1])

ppi2[[1]] = ifelse(is.na(trN1), ppi2[[1]], trN1)

trN2 = mget(ppi2[[2]], YEASTCOMMON2SYSTEMATIC, ifnotfound=NA)
trN2 = sapply(trN2, function(x) x[1])

ppi2[[2]] = ifelse(is.na(trN2), ppi2[[2]], trN2)

@

Now there are \Sexpr{nrow(ppi2)} pairs left.
For our purposes we want to find interaction pairs that
are wholy contained within a predicted protein complex, as that 
will be used as a basis for helping to determine if particular
protein complexes are well defined.

<<splitData>>=

 pairsBy = split(ppi2[[2]],ppi2[[1]])
 table(sapply(pairsBy, length))

@

The basic idea here is to think of each pair as a bait-prey (although that
is not true) since it helps us to reduce the number of protein complexes
that need to be examined.

Next we load up the \Rpackage{ScISI} package.

<<loadScISI>>=

 library("ScISI")
 data(ScISI)

@


And now, we find complexes that contain at least one bait.

<<findComp>>=

 haveB = row.names(ScISI) %in% names(pairsBy)

  ScSub1 = ScISI[haveB,]
  havC = colSums(ScSub1) > 0

 ##these are the complexes we have some chance with
 ScSub2 = ScISI[,havC]


 byComp = function(cMat, bpL) {
    rn = row.names(cMat)
    bNames = names(bpL)
    ans = rep(0, ncol(cMat))
    for(i in 1:ncol(cMat) ) {
       nIn = 0
       protInC = rn[cMat[,i]>0]
       wB = bNames[bNames %in% protInC]
       if(length(wB) == 0 ) 
           warning("Complex", i, "has a problem")
       else {
          for(j in wB) 
             nIn = nIn + length(intersect(bpL[[j]], protInC))
       }
       ans[i] = nIn
    }
    ans
 }

 t1 = byComp(ScSub2, pairsBy)

@



\end{document}
