### R code from vignette source 'vignettes/CAGEr/inst/doc/CAGEr.Rnw'

###################################################
### code chunk number 1: setup
###################################################
options(width = 60)
olocale=Sys.setlocale(locale="C")


###################################################
### code chunk number 2: CAGEr.Rnw:139-140
###################################################
library(CAGEr)


###################################################
### code chunk number 3: CAGEr.Rnw:146-147
###################################################
library(BSgenome.Drerio.UCSC.danRer7)


###################################################
### code chunk number 4: CAGEr.Rnw:168-171
###################################################
inputDir <- system.file("extdata", package = "CAGEr")
pathsToInputFiles <- list.files(inputDir, full.names = TRUE)
basename(pathsToInputFiles)


###################################################
### code chunk number 5: CAGEr.Rnw:179-183
###################################################
myCAGEset <- new("CAGEset", genomeName = "BSgenome.Drerio.UCSC.danRer7",
		inputFiles = pathsToInputFiles, inputFilesType = "ctss",
		sampleLabels = c("zf_30p_dome", "zf_high", 
		"zf_prim6_rep1", "zf_prim6_rep2", "zf_unfertilized_egg"))


###################################################
### code chunk number 6: CAGEr.Rnw:187-188
###################################################
myCAGEset


###################################################
### code chunk number 7: CAGEr.Rnw:196-197
###################################################
getCTSS(myCAGEset)


###################################################
### code chunk number 8: CAGEr.Rnw:202-204
###################################################
ctss <- CTSStagCount(myCAGEset)
head(ctss)


###################################################
### code chunk number 9: CAGEr.Rnw:208-209
###################################################
sampleLabels(myCAGEset)


###################################################
### code chunk number 10: CAGEr.Rnw:220-221 (eval = FALSE)
###################################################
## corr.m <- plotCorrelation(myCAGEset, samples = "all", method = "pearson")


###################################################
### code chunk number 11: CAGEr.Rnw:240-243
###################################################
mergeSamples(myCAGEset, mergeIndex = c(3,2,4,4,1), 
			mergedSampleLabels = c("zf_unfertilized_egg", 
			"zf_high", "zf_30p_dome", "zf_prim6"))


###################################################
### code chunk number 12: CAGEr.Rnw:255-256
###################################################
librarySizes(myCAGEset)


###################################################
### code chunk number 13: CAGEr.Rnw:268-269 (eval = FALSE)
###################################################
## plotReverseCumulatives(myCAGEset, fitInRange = c(5, 1000), onePlot = TRUE)


###################################################
### code chunk number 14: CAGEr.Rnw:287-289
###################################################
normalizeTagCount(myCAGEset, method = "powerLaw", 
		fitInRange = c(5, 1000), alpha = 1.2, T = 5*10^4)


###################################################
### code chunk number 15: CAGEr.Rnw:308-309 (eval = FALSE)
###################################################
## exportCTSStoBedGraph(myCAGEset, values = "normalized", oneFile = TRUE)


###################################################
### code chunk number 16: CAGEr.Rnw:340-343
###################################################
clusterCTSS(object = myCAGEset, threshold = 1, thresholdIsTpm = TRUE, 
		nrPassThreshold = 1, method = "distclu", maxDist = 20, 
		removeSingletons = TRUE, keepSingletonsAbove = 5)


###################################################
### code chunk number 17: CAGEr.Rnw:349-351
###################################################
tc <- tagClusters(myCAGEset, sample = "zf_unfertilized_egg")
head(tc)


###################################################
### code chunk number 18: CAGEr.Rnw:388-390
###################################################
cumulativeCTSSdistribution(myCAGEset, clusters = "tagClusters")
quantilePositions(myCAGEset, clusters = "tagClusters", qLow = 0.1, qUp = 0.9)


###################################################
### code chunk number 19: CAGEr.Rnw:394-397
###################################################
tc <- tagClusters(myCAGEset, sample = "zf_unfertilized_egg",
		returnInterquantileWidth = TRUE,  qLow = 0.1, qUp = 0.9)
head(tc)


###################################################
### code chunk number 20: CAGEr.Rnw:401-403 (eval = FALSE)
###################################################
## exportToBed(object = myCAGEset, what = "tagClusters", 
## 		qLow = 0.1, qUp = 0.9, oneFile = TRUE)


###################################################
### code chunk number 21: CAGEr.Rnw:417-419 (eval = FALSE)
###################################################
## plotInterquantileWidth(myCAGEset, clusters = "tagClusters", 
## 		tpmThreshold = 3, qLow = 0.1, qUp = 0.9)


###################################################
### code chunk number 22: CAGEr.Rnw:437-439
###################################################
aggregateTagClusters(myCAGEset, tpmThreshold = 5, 
		qLow = 0.1, qUp = 0.9, maxDist = 100)


###################################################
### code chunk number 23: CAGEr.Rnw:444-446
###################################################
consensusCl <- consensusClusters(myCAGEset)
head(consensusCl)


###################################################
### code chunk number 24: CAGEr.Rnw:461-463
###################################################
getExpressionProfiles(myCAGEset, what = "consensusClusters", tpmThreshold = 10, 
		nrPassThreshold = 1, method = "som", xDim = 4, yDim = 2)


###################################################
### code chunk number 25: CAGEr.Rnw:467-468 (eval = FALSE)
###################################################
## plotExpressionProfiles(myCAGEset, what = "consensusClusters")


###################################################
### code chunk number 26: CAGEr.Rnw:480-483
###################################################
class3_1 <- extractExpressionClass(myCAGEset, 
		what = "consensusClusters", which = "3_1")
head(class3_1)


###################################################
### code chunk number 27: CAGEr.Rnw:488-490 (eval = FALSE)
###################################################
## exportToBed(myCAGEset, what = "consensusClusters", 
## 		colorByExpressionProfile = TRUE)


###################################################
### code chunk number 28: CAGEr.Rnw:512-513
###################################################
cumulativeCTSSdistribution(myCAGEset, clusters = "consensusClusters")


###################################################
### code chunk number 29: CAGEr.Rnw:516-518
###################################################
scoreShift(myCAGEset, groupX = "zf_unfertilized_egg", groupY = "zf_prim6",
		testKS = TRUE, useTpmKS = FALSE)


###################################################
### code chunk number 30: CAGEr.Rnw:542-546
###################################################
shifting.promoters <- getShiftingPromoters(myCAGEset, 
		tpmThreshold = 5, scoreThreshold = 0.6,
		fdrThreshold = 0.01)
head(shifting.promoters)


###################################################
### code chunk number 31: CAGEr.Rnw:566-567
###################################################
library(FANTOM3and4CAGE)


###################################################
### code chunk number 32: CAGEr.Rnw:570-572
###################################################
data(FANTOMhumanSamples)
head(FANTOMhumanSamples)


###################################################
### code chunk number 33: CAGEr.Rnw:576-577
###################################################
data(FANTOMtissueCAGEhuman)


###################################################
### code chunk number 34: CAGEr.Rnw:581-582
###################################################
library(BSgenome.Hsapiens.UCSC.hg18)


###################################################
### code chunk number 35: CAGEr.Rnw:587-590
###################################################
myCAGEset <- importPublicData(dataset = FANTOMtissueCAGEhuman,
		group = c("liver", "liver", "blood"), 
		sample = c("liver", "malignancy", "RCB-0806_Jurkat"))


###################################################
### code chunk number 36: CAGEr.Rnw:594-595
###################################################
myCAGEset


###################################################
### code chunk number 37: CAGEr.Rnw:603-604
###################################################
sessionInfo()


