### R code from vignette source 'ToPASeq.Rnw'

###################################################
### code chunk number 1: ToPASeq.Rnw:66-70
###################################################
library(ToPASeq)
pathways<-pathways("hsapiens", "kegg")[1:5]
pathways[[1]]
str(pathways[[1]])


###################################################
### code chunk number 2: ToPASeq.Rnw:120-121
###################################################
options(width=60)


###################################################
### code chunk number 3: lib
###################################################
library(ToPASeq)
library(DEGraph)
data(Loi2008_DEGraphVignette)
pathways<-pathways("hsapiens", "kegg")[1:5]
ls()


###################################################
### code chunk number 4: ToPASeq.Rnw:142-174 (eval = FALSE)
###################################################
## top<-TopologyGSA(exprLoi2008, classLoi2008, pathways, type="MA", perms=200)
## #99 node labels mapped to the expression data
## #Average coverage 31.47657 %
## #0 (out of 5) pathways without a mapped node
## #Acute myeloid leukemia
## #Adherens junction
## #Adipocytokine signaling pathway
## #Adrenergic signaling in cardiomyocytes
## #African trypanosomiasis
## res(top)
## #$results
## #                                        t.value df.mean1 df.mean2 p.value
## #Acute myeloid leukemia                 3024.796       30      224       0
## #Adherens junction                      1102.830       10      244       0
## #Adipocytokine signaling pathway        3196.432       25      229       0
## #Adrenergic signaling in cardiomyocytes 2178.476       26      228       0
## #African trypanosomiasis                1404.259        8      246       0
## #                                      lambda.value df.var  p.value.var
## #Acute myeloid leukemia                    213.01437    156 1.649509e-03
## #Adherens junction                          39.92094     10 1.749659e-05
## #Adipocytokine signaling pathway           192.81336    121 3.595452e-05
## #Adrenergic signaling in cardiomyocytes    169.47418     80 2.211953e-08
## #African trypanosomiasis                    13.02808     12 3.670031e-01
## #                                       qchisq.value var.equal q.value
## #Acute myeloid leukemia                    186.14575         1       0
## #Adherens junction                          18.30704         1       0
## #Adipocytokine signaling pathway           147.67353         1       0
## #Adrenergic signaling in cardiomyocytes    101.87947         1       0
## #African trypanosomiasis                    21.02607         0       0
## #
## #$errors
## #named list()


###################################################
### code chunk number 5: ToPASeq.Rnw:184-186
###################################################
deg<-DEGraph(exprLoi2008, classLoi2008, pathways, type="MA")
res(deg)


###################################################
### code chunk number 6: ToPASeq.Rnw:197-226 (eval = FALSE)
###################################################
## cli<-clipper( exprLoi2008, classLoi2008, pathways,type="MA", method="mean")
## #99 node labels mapped to the expression data
## #Average coverage 31.47657 %
## #0 (out of 5) pathways without a mapped node
## #0  pathways were filtered out
## #Analysing pathway:
## #
## #Acute myeloid leukemia 
## #Adherens junction 
## #Adipocytokine signaling pathway 
## #Adrenergic signaling in cardiomyocytes 
## #African trypanosomiasis 
## #0 denoted as 0 
## # 1 denoted as 1
## # Contrasts:  1 - 0 
## #Warning messages:
## #1: In getJunctionTreePaths(graph, root) :
## #  The DAG presents cliques that are not connected.
## #2: In prunePaths(clipped, pruneLevel) : pathSummary is NULL
## #3: In getJunctionTreePaths(graph, root) :
## #  The DAG presents cliques that are not connected.
## #4: In prunePaths(clipped, pruneLevel) : pathSummary is NULL
## res(cli)$results[[1]]
## #                                       alphaVar alphaMean mean.q.value var.q.value
## #Acute myeloid leukemia                    0.735     0.009       0.0150     0.91875
## #Adherens junction                         0.101     0.022       0.0275     0.26500
## #Adipocytokine signaling pathway           0.656     0.001       0.0050     0.91875
## #Adrenergic signaling in cardiomyocytes    0.106     0.061       0.0610     0.26500
## #African trypanosomiasis                   0.953     0.007       0.0150     0.95300


###################################################
### code chunk number 7: ToPASeq.Rnw:237-239
###################################################
spi<-SPIA(exprLoi2008, classLoi2008,pathways , type="MA", logFC.th=-1)
res(spi)


###################################################
### code chunk number 8: ToPASeq.Rnw:254-256
###################################################
tap<-TAPPA(exprLoi2008, classLoi2008, pathways, type="MA")
res(tap)


###################################################
### code chunk number 9: ToPASeq.Rnw:265-268
###################################################
Prs<-PRS( exprLoi2008, classLoi2008, pathways, type="MA",  logFC.th=-1, nperm=100)
res(Prs)



###################################################
### code chunk number 10: ToPASeq.Rnw:284-304 (eval = FALSE)
###################################################
## pwe<-PWEA(exprLoi2008, classLoi2008, pathways,  type="MA", nperm=100)
## #0 denoted as 0 
## # 1 denoted as 1
## # Contrasts:  1 - 0 
## #29 node labels mapped to the expression data
## #Average coverage 5.752782 %
## #1 (out of 5) pathways without a mapped node
## #1  pathways were filtered out
## # Preparing permutations..
## res(pwe)
## #$results
## #                                               ES p.value   q.value
## #Acute myeloid leukemia                 -0.1516072    0.36 0.5066667
## #Adherens junction                       0.2576037    1.00 1.0000000
## #Adipocytokine signaling pathway         0.2221782    0.38 0.5066667
## #Adrenergic signaling in cardiomyocytes -0.2265755    0.05 0.2000000
## #
## #$errors
## #named list()
## 


###################################################
### code chunk number 11: seq1
###################################################
library(gageData)
data(hnrnp.cnts)
hnrnp.cnts<-hnrnp.cnts[rowSums(hnrnp.cnts)>0,]
group<-c(rep("sample",4), rep("control",4))
pathways<-pathways("hsapiens", "kegg")



###################################################
### code chunk number 12: seq2 (eval = FALSE)
###################################################
## top<-TopologyGSA(hnrnp.cnts, group, pathways[1:3], type="RNASeq", nperm=1000)
## #528 node labels mapped to the expression data
## #Average coverage 83.16538
## #0 (out of 10) pathways without a mapped node
## #Normalization method was not specified. TMM used as default
## #Acute myeloid leukemia
## #Adherens junction
## #Adipocytokine signaling pathway
## 
## 
## res(top)
## #data frame with 0 columns and 1 rows
## 
## 


###################################################
### code chunk number 13: seq3
###################################################
deg<-DEGraph(hnrnp.cnts, group, pathways, type="RNASeq")
res(deg)[[1]][[1]]


###################################################
### code chunk number 14: seq4 (eval = FALSE)
###################################################
## cli<-clipper(hnrnp.cnts, group, pathways, type="RNASeq", method="mean")
## #530 node labels mapped to the expression data
## #Average coverage 82.98681 %
## #0 (out of 10) pathways without a mapped node
## #1  pathways were filtered out
## #Analysing pathway:
## #
## #Acute myeloid leukemia
## #Adherens junction
## #Adipocytokine signaling pathway
## #Adrenergic signaling in cardiomyocytes
## #African trypanosomiasis
## #Alanine, aspartate and glutamate metabolism
## #Alcoholism
## #Aldosterone-regulated sodium reabsorption
## #Allograft rejection
## #alpha-Linolenic acid metabolism
## res(cli)$results[[1]][1:2,]
## #                       alphaVar alphaMean mean.q.value var.q.value
## #Acute myeloid leukemia    0.026     0.010        0.016       0.033
## #Adherens junction         0.030     0.009        0.016       0.033
## 


###################################################
### code chunk number 15: seq5
###################################################
spi<-SPIA(hnrnp.cnts, group, pathways, type="RNASeq", logFC.th=-1)
res(spi)


###################################################
### code chunk number 16: seq6
###################################################
tap<-TAPPA(hnrnp.cnts, group, pathways, type="RNASeq")
res(tap)


###################################################
### code chunk number 17: seq7
###################################################
Prs<-PRS(hnrnp.cnts, group, pathways, type="RNASeq",  logFC.th=-1, nperm=100)
res(Prs)


###################################################
### code chunk number 18: seq8 (eval = FALSE)
###################################################
## pwe<-PWEA(hnrnp.cnts, group, pathways, type="RNASeq", nperm=100)
## #528 node labels mapped to the expression data
## #Average coverage 83.16538
## #0 (out of 10) pathways without a mapped node
## #Acute myeloid leukemia
## #Adherens junction
## #Adipocytokine signaling pathway
## #Adrenergic signaling in cardiomyocytes
## #African trypanosomiasis
## #Alanine, aspartate and glutamate metabolism
## #Alcoholism
## #Aldosterone-regulated sodium reabsorption
## #Allograft rejection
## #alpha-Linolenic acid metabolism
## res(pwe)
## #                                                   ES    p     p.adj
## #Acute myeloid leukemia                      0.3526104 0.29 0.4142857
## #Adherens junction                           0.3829831 1.00 1.0000000
## #Adipocytokine signaling pathway             0.3102945 1.00 1.0000000
## #Adrenergic signaling in cardiomyocytes      0.3611207 0.20 0.3333333
## #African trypanosomiasis                     0.3272899 0.20 0.3333333
## #Alanine, aspartate and glutamate metabolism 0.2720946 0.20 0.3333333
## #Alcoholism                                  0.4708293 0.86 1.0000000
## #Aldosterone-regulated sodium reabsorption   0.3951037 0.20 0.3333333
## #Allograft rejection                         0.9421248 0.03 0.3000000
## #alpha-Linolenic acid metabolism             0.6587026 0.20 0.3333333


###################################################
### code chunk number 19: plot1 (eval = FALSE)
###################################################
## #Fails during check
## library(gageData)
## data(hnrnp.cnts)
## 
## group<-c(rep("sample",4), rep("control",4))
## hnrnp.cnts<-hnrnp.cnts[rowSums(hnrnp.cnts)>0,]
## res<-clipper(hnrnp.cnts, group, pathways[1:2], type="RNASeq", testCliques=TRUE)
## 
## plot(res,1, pathways)
## 


###################################################
### code chunk number 20: plot2 (eval = FALSE)
###################################################
## library(gageData)
## data(hnrnp.cnts)
## 
## group<-c(rep("sample",4), rep("control",4))
## hnrnp.cnts<-hnrnp.cnts[rowSums(hnrnp.cnts)>0,]
## pathways<-pathways("hsapiens", "kegg")[50:55]
## spi<-SPIA(hnrnp.cnts, group, pathways, type="RNASeq", logFC.th=-1)
## plot(spi,"Complement and coagulation cascades", pathways, fontsize=50)
## 


