%
% NOTE -- ONLY EDIT SubpathwayLNCE.Rnw!!!
% SubpathwayLNCE.tex file will get overwritten.
%
%\VignetteIndexEntry{SubpathwayLNCE Overview}
%\VignetteKeywords{pathway}
%\VignettePackage{SubpathwayLNCE}
%\VignetteDepends{igraph,graph,RBGL,BiasedUrn,utils}

\documentclass[10pt]{article}

\usepackage{hyperref}
\usepackage[pdftex]{graphicx}
\SweaveOpts{keep.source=TRUE,eps=FALSE,pdf=TRUE,prefix=FALSE} 
\author{Xinrui Shi, Chunquan Li, Xia Li}

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

\newcommand{\xiaowuhao}{\fontsize{9pt}{\baselineskip}\selectfont}
\newcommand{\liuhao}{\fontsize{7.875pt}{\baselineskip}\selectfont}
\newcommand{\qihao}{\fontsize{5.25pt}{\baselineskip}\selectfont}

\newcommand\Rpackage[1]{{\textsf{#1}\index{#1 (package)}}}
\newcommand\RpackageNoindex[1]{{\textsf{#1}}}
\newcommand\Rclass[1]{{\textit{#1}\index{#1 (class)}}}
\newcommand\Rfunction[1]{{{\small\texttt{#1}}\index{#1 (function)}}}
\newcommand\Rmethod[1]{{\small\texttt{#1}}}
\newcommand\Rcommand[1]{{{\small\texttt{#1}}\index{#1 (function)}}}
\newcommand\Rfunarg[1]{{\small\texttt{#1}}}
\newcommand\Robject[1]{{\small\texttt{#1}}}
\bibliographystyle{plainnat}

\begin{document}
\setkeys{Gin}{width=1.0\textwidth}
\title{How To Use SubpathwayLNCE}
\maketitle
\tableofcontents

\section{Overview}
This vignette demonstrates how to easily use the \Rpackage{SubpathwayLNCE} package. This package can implement the identification of Kyoto Encyclopedia of Genes and Genomes (KEGG) signal subpathways competitively regulated by long nocoding RNAs (lncRNAs), by topologically locating lncRNAs and genes within reconstructed KEGG signal pathway graphs, which emmbedded by lncRNAs based on ceRNA theory. (1) This package provides the \Rfunction{getExampleData} to return example data and environment variables. (see the section \ref{DataSection}). (2) This package provides the \Rfunction{getInteUMGraph} function to reconstruct KEGG signal pathways by embedding lncRNAs into  undirect KEGG signal pathway graphs.(see the section \ref{IntegrateSection}). (3) This package provides the \Rfunction{getLocSubGraph} function to locate lncRNAs competitively regulated signal subpathways by topologically analyzing the "lenient distance" of lncRNAs and genes, based on reconstructed pathways.(see the section \ref{LocateSection}). (4) This package provides the \Rfunction{identifyGraphW} function to identify the significantly enriched signal subpathways, based on located subpathways.(see the section \ref{IdentifySection}). (5) This package provides the \Rfunction{GetK2riData} function to get variable data in current environment.(see the section \ref{GetEnvirSection}). (6) This package provides the \Rfunction{updateOrgEnvir} function to updata the organism-specific environment variables.(see the section \ref{UpdateEnvirSection}).

<<echo=FALSE>>=
library(SubpathwayLNCE)
@ 

\section{get candidate lncRNA-mRNA interaction }\label{DataSection}

We can use function \Rfunction{getExampleData} to return example data and environment variables, such as the data of candidate lncRNA-mRNA interaction, the data of undirect KEGG metabolic pathway graphs with genes as nodes.

<<>>= 
#obtain the data for candidate lncRNA-mRNA interaction.
interaction<-GetExampleData(exampleData="pp")
# view first six rows of data
interaction[1:6,]
#obtain the data for undirect KEGG metabolic pathway graphs with genes as nodes
 g2<-GetExampleData(exampleData="g2")
#obtain example data of mathed mRNA-lncRNA expression profiles
 #GeneExp<-GetExampleData(exampleData="GeneExp")
 #LncExp<-GetExampleData(exampleData="LncExp")
@

\section{Reconstruct KEGG signal pathways}\label{IntegrateSection}

We can use function \Rfunction{getInteUMGraph} to return the integrated KEGG signal pathway graph list. We first convert KEGG metabolic pathways to direct/undirect graphs with genes as nodes, then reconstructed pathways by linking lncRNAs to competitively regulated targets within it.

\subsection{Get the co-express lncRNA-mRNA interactions}\label{getLncGenePairs}

The function \Rfunction{getLncGenePairs} can calculated co-expression coefficient for any pair of relations in the candidate LncRNA-mRNA interaction based on matched LncRNA and mRNA expression profiles, those relations had reached a significant positive threshold were retained.

<<>>= 
#obtain example data of mathed mRNA-lncRNA expression profiles
 GeneExp<-GetExampleData(exampleData="GeneExp")
 LncExp<-GetExampleData(exampleData="LncExp")
#calculated co-expression coefficient,the significant positive threshold is 0.025
 LncGenePairs<-getLncGenePairs(GeneExp,LncExp,a=0.025)
#obtain the data for undirect KEGG metabolic pathway graphs with genes as nodes
 g2<-GetExampleData(exampleData="g2")
# get reconstructed undirect pathway graph list
 #interUMGraph<-getInteGraphList(g2,LncGenePairs)
 
@ 

\subsection{Embed competitively regulated lncRNAs to undirect KEGG signal pathway graphs}\label{getInteUMGraph}

The function \Rfunction{getInteGraphList} can competitively regulated lncRNAs into undirect KEGG signal pathway graphs with genes as nodes. With integrated graph list, we can offer the additional interested  genes sets to identify the condition-specific pathways  competitively regulated by lncRNAs.

<<>>=
#obtain the data for undirect KEGG metabolic pathway graphs with genes as nodes
  g2<-GetExampleData(exampleData="g2")
 #obtain example data of mathed mRNA-lncRNA expression profiles
 #GeneExp<-GetExampleData(exampleData="GeneExp")
 #LncExp<-GetExampleData(exampleData="LncExp")
#calculated co-expression coefficient,the significant positive threshold is 0.025
 #LncGenePairs<-getLncGenePairs(GeneExp,LncExp,a=0.025)
# get reconstructed undirect pathway graph list
# To improve efficiency, a fraction of signal pathway as case
  LncGenePairs<-GetExampleData(exampleData="LncGenePairs")
  interUMGraph<-getInteGraphList(g2[42:45],LncGenePairs)
### Integrate lncRNAs of competitive regulation into KEGG pathway graphs ###
  ##LncGenePairs<-GetExampleData(exampleData="LncGenePairs")
  ##inteUMGraph<-getInteUMGraph(LncGenePairs)
@ 

The following commands can show the reconstructed pathway graph with genes and lncRNAs as nodes. 

<<UnDirectInteGraph, fig=TRUE, include=FALSE, prefix=FALSE>>=
# visualize the reconstructed undirect pathway
  #LncGenePairs<-GetExampleData(exampleData="LncGenePairs")
  #inteUMGraph<-getInteUMGraph(LncGenePairs)
  plotGraphL(interUMGraph[[1]],vertex.label=getNodeLabel)
@

Figure \ref{UnDirectInteGraph} shows the reconstructed undirect p53 signaling pathway.

\begin{figure}[!htbp]
\begin{center}
\includegraphics[width=1.0\textwidth]{UnDirectInteGraph}
\caption{The visualization of reconstructed undirect p53 signaling pathway.}\label{UnDirectInteGraph}
\end{center}
\end{figure}
@

\section{Locate KEGG metabolic subpathways}\label{LocateSection}

We can use function \Rfunction{getLocSubGraph} to locate signal subpathways by topologically analyzing the "lenient distance" of lncRNAs and/or genes based on reconstructed pathways.

<<>>=
### Integrate lncRNAs of competitive regulation into KEGG pathway graphs ###
  LncGenePairs<-GetExampleData(exampleData="LncGenePairs")
  #inteUMGraph<-getInteUMGraph(LncGenePairs)
  # To improve efficiency, a fraction of signal pathway as case
  LncGenePairs<-GetExampleData(exampleData="LncGenePairs")
  interUMGraph<-getInteGraphList(g2[42:45],LncGenePairs)
### get user-interested lncRNAs and genes sets.
##geneLnc<-c(getBackground(type="gene")[1:3000],unique(LncGenePairs[1,]))
  geneLnc<-GetExampleData(exampleData="geneLnc")
# get locate subpathways.
  sub<-getLocSubGraphLnc(geneLnc,interUMGraph,type="gene_lncRNA",n=1,s=8)
  
@ 

\section{Identify the significantly enriched subpathways}\label{IdentifySection}

We can use function \Rfunction{identifyGraphW} to identify the significantly enriched subpathways based on located direct/undirect signal subpathways.


<<>>=
### Integrate lncRNAs of competitive regulation into KEGG pathway graphs ###
  #LncGenePairs<-GetExampleData(exampleData="LncGenePairs")
  #inteUMGraph<-getInteUMGraph(LncGenePairs)
### get user-interested lncRNAs and genes sets.
##geneLnc<-c(getBackground(type="gene")[1:3000],unique(LncGenePairs[1,]))
  geneLnc<-GetExampleData(exampleData="geneLnc")
# get locate subpathways.
  #sub<-getLocSubGraphLnc(geneLnc,interUMGraph,type="gene_lncRNA",n=1,s=8)
  sub<-GetExampleData(exampleData="sub")
  # To improve efficiency, a fraction of signal subpathway as case
  SubcodeLncResult<-identifyLncGraphW(geneLnc,sub[50:55],type="gene_lncRNA",bet=1)
  #SubcodeLncResult<-identifyLncGraphW(geneLnc,sub,type="gene_lncRNA",bet=1)
  #resultT<-printGraphW(SubcodeLncResult,detail=TRUE)
  #write.table(resultT,file="result.txt",sep="\t",row.names=F,quote=F)
@
The following commands can show the reconstructed pathway graph with genes and miRNAs as nodes. 

<<PlotAnnGraph, fig=TRUE, include=FALSE, prefix=FALSE>>=
  plotAnnGraph("path:04916_1",sub,SubcodeLncResult,gotoKEGG=FALSE,vertex.label=getNodeLabel)
@

Figure \ref{PlotAnnGraph} shows the reconstructed undirect  Calcium signaling pathway.

\begin{figure}[!htbp]
\begin{center}
\includegraphics[width=1.0\textwidth]{PlotAnnGraph}
\caption{The visualization of reconstructed undirect  Calcium signaling pathway.}\label{PlotAnnGraph}
\end{center}
\end{figure}
@

\newpage
\section{Session Info}
The script runs within the following session:
<<sessionInfo, echo=FALSE, results=verbatim>>=
sessionInfo()
@

\begin{thebibliography}{}

\bibitem[Antonov {\it et~al}., 2008]{Antonov2008} Antonov, A.V., et al. (2008) Kegg Spider: Interpretation of Genomics Data in the Context of the Global Gene Metabolic Network. Genome Biol, 9, R179.

\bibitem[Csardi and Nepusz, 2006]{Csardi2006} Csardi, G. and Nepusz, T. (2006) The igraph software package for complex network research. InterJournal, Complex Systems, 1695.

\bibitem[Draghici {\it et~al}., 2007]{Draghici2007} Draghici, S., et al. (2007) A Systems Biology Approach for Pathway Level Analysis. Genome Res, 17, 1537-1545.

\bibitem[Guimera and Nunes Amaral, 2005]{Guimera2005} Guimera, R. and Nunes Amaral, L.A. (2005) Functional Cartography of Complex Metabolic Networks. Nature, 433, 895-900.

\bibitem[Huber {\it et~al}., 2007]{Huber2007}  Huber, W., et al. (2007) Graphs in Molecular Biology. BMC Bioinformatics, 8 Suppl 6, S8.

\bibitem[Hung {\it et~al}., 2010]{Hung2010} Hung, J.H., et al. (2010) Identification of Functional Modules That Correlate with Phenotypic Difference: The Influence of Network Topology. Genome Biol, 11, R23.

\bibitem[Kanehisa {\it et~al}., 2006]{Kanehisa2006} Kanehisa, M., et al. (2006) From Genomics to Chemical Genomics: New Developments in Kegg. Nucleic Acids Res, 34, D354-357.

\bibitem[Koyuturk {\it et~al}., 2004]{Koyuturk2004} Koyuturk, M., et al. (2004) An Efficient Algorithm for Detecting Frequent Subgraphs in Biological Networks. Bioinformatics, 20 Suppl 1, i200-207.

\bibitem[Li {\it et~al}., 2009]{Li2009} Li, C., et al. (2009) Subpathwayminer: A Software Package for Flexible Identification of Pathways. Nucleic Acids Res, 37, e131.

\bibitem[Li {\it et~al}., 2013]{Li2013} Li, C., et al. (2013) Subpathway-GM: identification of metabolic subpathways via joint power of interesting genes and metabolites and their topologies within pathways. Nucleic acids research, 41, e101.

\bibitem[Smart {\it et~al}., 2008]{Smart2008} Smart, A.G., et al. (2008) Cascading Failure and Robustness in Metabolic Networks. Proc Natl Acad Sci U S A, 105, 13223-13228.

\bibitem[Strimmer, 2008]{Strimmer2008} Strimmer, K. (2008) fdrtool: a versatile R package for estimating local and tail area-based false discovery rates. Bioinformatics, 24, 1461-1462.

\bibitem[Vergoulis {\it et~al}., 2012]{Vergoulis2012} Vergoulis, T., et al. (2012) TarBase 6.0: capturing the exponential growth of miRNA targets with experimental support. Nucleic acids research, 40, D222-229.

\bibitem[Xiao {\it et~al}., 2009]{Xiao2009} Xiao, F., et al. (2009) miRecords: an integrated resource for microRNA-target interactions. Nucleic acids research, 37, D105-110.

\bibitem[Hsu {\it et~al}., 2011]{Hsu2011} Hsu, S.D., et al. (2011) miRTarBase: a database curates experimentally validated microRNA-target interactions. Nucleic acids research, 39, D163-169.

\bibitem[Jiang {\it et~al}., 2009]{Jiang2009} Jiang, Q., et al. (2009) miR2Disease: a manually curated database for microRNA deregulation in human disease. Nucleic acids research, 37, D98-104.

\end{thebibliography}
\end{document}
