-
Notifications
You must be signed in to change notification settings - Fork 0
/
step9-summaryInfo.Rmd
177 lines (135 loc) · 5.11 KB
/
step9-summaryInfo.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
output:
knitrBootstrap::bootstrap_document:
theme.chooser: TRUE
highlight.chooser: TRUE
---
Summary info
===========
```{r "options", bootstrap.show.code = FALSE}
## Options
opt$example <- eval(parse(text=opt$example))
example <- opt$example
names(example) <- NULL
## Required libs
suppressMessages(library("GenomicRanges"))
suppressMessages(library("ggbio"))
suppressMessages(library("TxDb.Hsapiens.UCSC.hg19.knownGene"))
suppressMessages(library("derfinder"))
suppressMessages(library("derfinderPlot"))
```
Summary information for `r opt$short` data set, analysis `r paste(opt$run, collapse = ', ')` showcasing best clusters `r example` which illustrate `r paste(names(opt$example), collapse = ', ')` respectively.
## Number of filtered bases
```{r "filtered", bootstrap.show.code = FALSE}
## Extract data from log files
reads <- system(paste0('grep filterData ', file.path(rootdir, opt$short, 'CoverageInfo', 'logs'), '/fullCov-*.e* | grep -v "that 0 percent"'), intern=TRUE)
filt <- data.frame(original=as.integer(gsub("were | rows", "", regmatches(reads, regexpr("were [0-9]* rows", reads)))), filtered=as.integer(gsub("are | rows", "", regmatches(reads, regexpr("are [0-9]* rows", reads)))))
## How many were filtered?
## What is the percent filtered?
## Percent remaining?
filtered <- colSums(filt)
summ <- c(
'Filtered' = filtered["original"] - filtered["filtered"],
'PercentFilt' = (filtered["original"] - filtered["filtered"]) / filtered["original"] * 100,
'PercentRemaining' = 100 - (filtered["original"] - filtered["filtered"]) / filtered["original"] * 100
)
summ
```
## Number of candidate regions
```{r "nCandidate", bootstrap.show.code = FALSE}
## Load regions data
load(file.path(rootdir, opt$short, 'derAnalysis', opt$run, 'fullRegions.Rdata'))
## How many candidate regions?
nRegs <- c('cDERsN' = length(fullRegions))
nRegs
```
## Number of DE regions
As determined by q-value < 0.10
```{r "regionsDEqval", bootstrap.show.code = FALSE}
## How many regions DE? Judged by q-value
## What is the percent of regions DE among the candidate ones?
qval <- c(
'nDE' = sum(fullRegions$significantQval == TRUE),
'percentDE' = sum(fullRegions$significantQval == TRUE) / length(fullRegions) * 100
)
qval
```
As determined by FWER adjusted p-value < 0.05
```{r "regionsDEfwer", bootstrap.show.code = FALSE}
## How many regions DE? Judged by FWER adjusted p-value
## What is the percent of regions DE among the candidate ones?
fwer <- c(
'nDE' = sum(fullRegions$significantFWER == TRUE),
'percentDE' = sum(fullRegions$significantFWER == TRUE) / length(fullRegions) * 100
)
fwer
## Save results
save(summ, nRegs, qval, fwer, file=file.path(resdir, "summaryResults.Rdata"))
```
## Example regions from each case
```{r "exampleRegions", message=FALSE, fig.width=20, fig.height=10, dev="CairoPNG", bootstrap.show.code = FALSE}
## Load full coverage data
load(file.path(rootdir, opt$short, 'CoverageInfo', 'fullCov.Rdata'))
## Load options
load(file.path(rootdir, opt$short, 'derAnalysis', opt$run, 'chr22', 'optionsStats.Rdata'))
## For ggplot
tmp <- fullRegions
names(tmp) <- seq_len(length(tmp))
regions.df <- as.data.frame(tmp)
regions.df$width <- width(tmp)
rm(tmp)
## Select clusters by cluster area
df <- data.frame(area=fullRegions$area, clusterChr=paste0(as.integer(fullRegions$cluster), chr=as.character(seqnames(fullRegions))))
regionClustAreas <- tapply(df$area, df$clusterChr, sum)
bestArea <- sapply(names(head(sort(regionClustAreas, decreasing=TRUE), 70)), function(y) { which(df$clusterChr == y)[[1]]})
## Graphical setup: ideograms
## Load ideogram info
data(hg19IdeogramCyto, package = "biovizBase")
ideos.set <- as.character(unique(seqnames(fullRegions[bestArea])))
p.ideos <- lapply(ideos.set, function(xx) {
plotIdeogram(hg19IdeogramCyto, xx)
})
names(p.ideos) <- ideos.set
## Graphical setup: transcription database
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
## Graphical setup: main plotting function
regionClusterPlot <- function(idx, tUse="fwer") {
## Chr specific selections
chr <- as.character(seqnames(fullRegions[idx]))
p.ideo <- p.ideos[[chr]]
covInfo <- fullCov[[chr]]
## Make the plot
p <- plotCluster(idx, regions=fullRegions, annotation=regions.df, coverageInfo=covInfo, groupInfo=optionsStats$groupInfo, titleUse=tUse, txdb=txdb, p.ideogram=p.ideo)
print(p)
## Save .Rdata
save(p, file=file.path(resdir, paste0("exampleRegion", idx, ".Rdata")) )
## Save as pdf
pdf(file=file.path(resdir, paste0("exampleRegion", idx, ".pdf")), width=20, height=10)
print(p)
dev.off()
rm(p.ideo, covInfo)
return(invisible(TRUE))
}
## Genome plots
for(idx in opt$example) {
regionClusterPlot(bestArea[idx], "fwer")
}
```
# Reproducibility
Date the report was generated.
```{r "reproducibility1", echo=FALSE, width = 90}
## Date the report was generated
Sys.time()
```
Wallclock time spent generating the report.
```{r "reproducibility2", echo=FALSE}
## Processing time in seconds
totalTime <- diff(c(startTime, Sys.time()))
round(totalTime, digits=3)
```
`R` session information.
```{r "reproducibility3", bootstrap.show.code = FALSE}
## Session info
options(width=120)
devtools::session_info()
```