###################################################
### chunk number 1: load library
###################################################
#line 102 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
library(GeneAnswers)


###################################################
### chunk number 2: build GeneAnswers
###################################################
#line 109 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
data('humanGeneInput')
data('humanExpr')
## build a GeneAnswers instance with statistical test based on biological process of GO and saved example data.
x <- geneAnswersBuilder(humanGeneInput, 'org.Hs.eg.db', categoryType='GO.BP', testType='hyperG',  pvalueT=0.1, FDR.correction=TRUE, geneExpressionProfile=humanExpr)
class(x)
## build a GeneAnswers instance with statistical test based on KEGG and saved example data. 
y <- geneAnswersBuilder(humanGeneInput, 'org.Hs.eg.db', categoryType='KEGG', testType='hyperG', pvalueT=0.1, geneExpressionProfile=humanExpr, verbose=FALSE)
## build a GeneAnswers instance with statistical test based on DOLite and saved example data.
z <- geneAnswersBuilder(humanGeneInput, 'org.Hs.eg.db', categoryType='DOLITE', testType='hyperG', pvalueT=0.1, geneExpressionProfile=humanExpr, verbose=FALSE)
w <- geneAnswersBuilder(humanGeneInput, 'org.Hs.eg.db', categoryType='GO.BP', testType='hyperG', pvalueT=0.1, FDR.correction=TRUE, geneExpressionProfile=humanExpr, level=2, verbose=FALSE) 


###################################################
### chunk number 3: build customized GeneAnswers
###################################################
#line 125 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
keywordsList <- list(Apoptosis=c('apoptosis'), CellAdhesion=c('cell adhesion'))
entrezIDList <- searchEntrez(keywordsList) 
q <- geneAnswersBuilder(humanGeneInput, entrezIDList, testType='hyperG', totalGeneNumber = 45384, pvalueT=0.1, geneExpressionProfile=humanExpr, verbose=FALSE)
class(q)
getAnnLib(q)
getCategoryType(q)


###################################################
### chunk number 4: make GeneAnswers readable and generate concept-gene network
###################################################
#line 139 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## mapping gene IDs and category IDs to gene symbols and category terms
xx <- geneAnswersReadable(x)
yy <- geneAnswersReadable(y, verbose=FALSE)
zz <- geneAnswersReadable(z, verbose=FALSE)
ww <- geneAnswersReadable(w, verbose=FALSE)
q <- setAnnLib(q, 'org.Hs.eg.db')
qq <- geneAnswersReadable(q, catTerm=FALSE) 


###################################################
### chunk number 5: plot barplot and / or piechart eval=FALSE
###################################################
## #line 151 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## plot barplot and / or piechart
## geneAnswersChartPlots(xx, chartType='all')


###################################################
### chunk number 6: plot interactive  concept-gene network eval=FALSE
###################################################
## #line 173 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## plot interactive concept-gene network
## geneAnswersConceptNet(xx, colorValueColumn='foldChange', centroidSize='pvalue', output='interactive')


###################################################
### chunk number 7: plot interactive  go structure network eval=FALSE
###################################################
## #line 187 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## plot interactive go structure network
## geneAnswersConceptRelation(x, direction='both', netMode='connection', catTerm=TRUE, catID=TRUE, nameLength=15) 


###################################################
### chunk number 8: plot interactive  concept-gene network with gene interaction eval=FALSE
###################################################
## #line 201 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## plot interactive concept-gene network
## geneAnswersConceptNet(x, color='foldChange', geneLayer=5, output='interactive', showCats=c("GO:0009611", "GO:0043933", "GO:0045622"), catTerm=TRUE, geneSymbol=TRUE, catID=TRUE)


###################################################
### chunk number 9: plot Gene interaction eval=FALSE
###################################################
## #line 216 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## plot the given gene interaction
## buildNet(c('444','3638', '5087','55835'), idType='GeneInteraction', layers=2, filterGraphIDs=getGeneInput(x)[,1], filterLayer=2, netMode='connection')


###################################################
### chunk number 10: plot Gene interaction with expression information eval=FALSE
###################################################
## #line 232 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## plot the given gene interaction
## buildNet(c('444','3638', '5087','55835'), idType='GeneInteraction', layers=2, filterGraphIDs=getGeneInput(x)[,1:2], filterLayer=2, netMode='connection')


###################################################
### chunk number 11: plot Gene interaction with pvalues eval=FALSE
###################################################
## #line 246 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## plot the given gene interaction
## buildNet(c('444','3638', '5087','55835'), idType='GeneInteraction', layers=2, filterGraphIDs=cbind(getGeneInput(x)[,1], -log2(getGeneInput(x)[,3])), filterLayer=2, netMode='connection')


###################################################
### chunk number 12: plot Gene interaction for all of given genes eval=FALSE
###################################################
## #line 260 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## plot the given gene interaction
## buildNet(getGeneInput(x)[,1], idType='GeneInteraction', layers=2, filterGraphIDs=getGeneInput(x)[,1:2], filterLayer=2, netMode='connection')


###################################################
### chunk number 13: plot Go-concept network for 2 level nodes removal eval=FALSE
###################################################
## #line 277 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## plot Go-concept network for 2 level nodes removal
## geneAnswersConceptNet(ww, colorValueColumn='foldChange', centroidSize='pvalue', output='fixed')


###################################################
### chunk number 14: sort GeneAnswers
###################################################
#line 292 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## sort enrichmentInfo dataframe by fdr adjusted p value
xxx <- geneAnswersSort(xx, sortBy='correctedPvalue')
yyy <- geneAnswersSort(yy, sortBy='pvalue') 
zzz <- geneAnswersSort(zz, sortBy='geneNum')


###################################################
### chunk number 15: plot concept-gene networks eval=FALSE
###################################################
## #line 299 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## geneAnswersConceptNet(yyy, colorValueColumn='foldChange', centroidSize='geneNum', output='fixed')
## geneAnswersConceptNet(zzz, colorValueColumn='foldChange', centroidSize='pvalue', output='fixed', showCats=c(10:16))


###################################################
### chunk number 16: generate GO-gene cross tabulation eval=FALSE
###################################################
## #line 322 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## generate GO-gene cross tabulation
## geneAnswersHeatmap(x, catTerm=TRUE, geneSymbol=TRUE)


###################################################
### chunk number 17: 
###################################################
#line 329 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## generate GO-gene cross tabulation
geneAnswersHeatmap(x, catTerm=TRUE, geneSymbol=TRUE)


###################################################
### chunk number 18:  eval=FALSE
###################################################
## #line 337 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## geneAnswersHeatmap(yyy)


###################################################
### chunk number 19: 
###################################################
#line 343 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
geneAnswersHeatmap(yyy)


###################################################
### chunk number 20: generate DOLite-gene cross tabulation eval=FALSE
###################################################
## #line 351 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## geneAnswersHeatmap(zzz, mapType='heatmap')


###################################################
### chunk number 21: 
###################################################
#line 358 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
geneAnswersHeatmap(zzz, mapType='heatmap')


###################################################
### chunk number 22: generate customized GO-gene cross tabulation eval=FALSE
###################################################
## #line 365 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## geneAnswersHeatmap(qq)


###################################################
### chunk number 23: 
###################################################
#line 371 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
geneAnswersHeatmap(qq)


###################################################
### chunk number 24: plot customized concept-gene cross tabulation
###################################################
#line 380 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
GOBPIDs <- c("GO:0043627", "GO:0042493", "GO:0006259", "GO:0007243")
GOBPTerms <- c("response to estrogen stimulus", "response to drug", "protein kinase cascade", "DNA metabolic process")


###################################################
### chunk number 25: generate concept-gene cross tabulation eval=FALSE
###################################################
## #line 385 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## generate concept-gene cross tabulation
## geneAnswersConceptNet(x, colorValueColumn='foldChange', centroidSize='pvalue', output='fixed', showCats=GOBPIDs, catTerm=TRUE, geneSymbol=TRUE) 


###################################################
### chunk number 26: generate customized concept-gene cross tabulation eval=FALSE
###################################################
## #line 398 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## geneAnswersHeatmap(x, showCats=GOBPIDs, catTerm=TRUE, geneSymbol=TRUE)


###################################################
### chunk number 27: 
###################################################
#line 405 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
geneAnswersHeatmap(x, showCats=GOBPIDs, catTerm=TRUE, geneSymbol=TRUE)


###################################################
### chunk number 28: generate concept-gene cross tabulation eval=FALSE
###################################################
## #line 413 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## generate concept-gene cross tabulation
## geneAnswersConcepts(xxx, centroidSize='geneNum', output='fixed', showCats=GOBPTerms) 


###################################################
### chunk number 29: print top categories and genes
###################################################
#line 429 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## print top GO categories sorted by hypergeometric test p value
topGOGenes(x,  orderby='pvalue')
## print top KEGG categories sorted by gene numbers and sort genes by fold changes 
topPATHGenes(y, orderby='geneNum', top=4, topGenes=8, genesOrderBy='foldChange')
## print and save top 10 DOLites information 
topDOLiteGenes(z, orderby='pvalue', top=5, topGenes='ALL', genesOrderBy='pValue', file=TRUE)


###################################################
### chunk number 30: multigroup gene analysis
###################################################
#line 442 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
##load multigroup genes sample data
data(sampleGroupsData)
##Build a GeneAnswers List
gAKEGGL <- lapply(sampleGroupsData, geneAnswersBuilder, 'org.Hs.eg.db', categoryType='KEGG', pvalueT=0.01, verbose=FALSE)
##Output integrated text table
output<- getConceptTable(gAKEGGL, items='geneNum')


###################################################
### chunk number 31: multigroup genes KEGG analysis eval=FALSE
###################################################
## #line 451 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## drawTable(output[[1]], matrixOfHeatmap=output[[2]], mar=c(2,28,3,2), clusterTable=NULL) 


###################################################
### chunk number 32: homogene conversation
###################################################
#line 468 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
 ## load mouse example data
data('mouseExpr')
data('mouseGeneInput') 
mouseExpr[1:10,]
mouseGeneInput[1:10,]
 ## only keep first one for one to more mapping
pickHomo <- function(element, inputV) {return(names(inputV[inputV == element])[1])}
 ## mapping geneInput to homo entrez IDs.
homoLL <- getHomoGeneIDs(mouseGeneInput[,1], species='mouse', speciesL='human', mappingMethod='direct')
newGeneInput <- mouseGeneInput[mouseGeneInput[,1] %in% unlist(lapply(unique(homoLL), pickHomo, homoLL)),]
dim(mouseGeneInput)
dim(newGeneInput)
newGeneInput[,1] <- homoLL[newGeneInput[,1]]
## mapping geneExpr to homo entrez IDs.
homoLLExpr <- getHomoGeneIDs(as.character(mouseExpr[,1]), species='mouse', speciesL='human', mappingMethod='direct')
newExpr <- mouseExpr[as.character(mouseExpr[,1]) %in% unlist(lapply(unique(homoLLExpr) , pickHomo, homoLLExpr)),]
newExpr[,1] <- homoLLExpr[as.character(newExpr[,1])]
dim(mouseExpr)
dim(newExpr)
## build a GeneAnswers instance based on mapped data
v <- geneAnswersBuilder(newGeneInput, 'org.Hs.eg.db', categoryType='DOLITE', testType='hyperG', pvalueT=0.1, FDR.correct=TRUE, geneExpressionProfile=newExpr)
## make the GeneAnswers instance readable, only map DOLite IDs to terms
vv <- geneAnswersReadable(v, geneSymbol=F)
getAnnLib(vv)
## mapping back to mouse genes
uu <- geneAnswersHomoMapping(vv, species='human', speciesL='mouse', mappingMethod='direct')
getAnnLib(uu)
## make mapped genes readable, DOLite terms are not mapped
u <- geneAnswersReadable(uu, catTerm=FALSE)
## sort new GeneAnswers instance
u1 <- geneAnswersSort(u, sortBy='pvalue')


###################################################
### chunk number 33: plot concept-gene network eval=FALSE
###################################################
## #line 502 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## plot concept-gene network
## geneAnswersConceptNet(u, colorValueColumn='foldChange', centroidSize='pvalue', output='fixed')


###################################################
### chunk number 34: generate homogene DOLite-gene cross tabulation eval=FALSE
###################################################
## #line 515 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## ## plot homogene DOLite-gene cross tabulation
## geneAnswersHeatmap(u1)


###################################################
### chunk number 35: 
###################################################
#line 522 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## plot homogene DOLite-gene cross tabulation
geneAnswersHeatmap(u1)


###################################################
### chunk number 36: homogene conversation
###################################################
#line 530 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
## output top information
topDOLiteGenes(u, geneSymbol=FALSE, catTerm=FALSE, orderby='pvalue', top=6, topGenes='ALL', genesOrderBy='pValue', file=TRUE)  


###################################################
### chunk number 37: sessionInfo
###################################################
#line 536 "E:/biocbld/bbs-2.7-bioc/tmpdir/RtmpVko4Vz/R.INSTALL2a751b6a/GeneAnswers/inst/doc/geneAnswers.Rnw"
toLatex(sessionInfo())


