-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep2-makeModels.R
117 lines (93 loc) · 3.56 KB
/
step2-makeModels.R
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
## Load the data without a filter, save it, then filter it for derfinder processing steps
## Load libraries
library('getopt')
## Available at http://www.bioconductor.org/packages/release/bioc/html/derfinder.html
library('derfinder')
library('devtools')
## Specify parameters
spec <- matrix(c(
'experiment', 'e', 1, 'character', 'Experiment. Either snyder or hippo',
'help' , 'h', 0, 'logical', 'Display help'
), byrow=TRUE, ncol=5)
opt <- getopt(spec)
## if help was asked for print a friendly message
## and exit with a non-zero error code
if (!is.null(opt$help)) {
cat(getopt(spec, usage=TRUE))
q(status=1)
}
## Check experiment input
stopifnot(opt$experiment %in% c('snyder', 'hippo'))
## Load the coverage information
load(file.path('..', '..', 'CoverageInfo', 'fullCov.Rdata'))
load(file.path('..', '..', 'CoverageInfo', 'chr22CovInfo.Rdata'))
## Identify the samplefiles
files <- colnames(chr22CovInfo$coverage)
## Calculate the library adjustments and build the models
buildModels <- function(fullCov, testvars, colsubset = NULL) {
## Determine sample size adjustments
if(file.exists("sampleDepths.Rdata")) {
load("sampleDepths.Rdata")
} else {
if(file.exists("collapsedFull.Rdata")) {
load("collapsedFull.Rdata")
} else {
## Collapse
collapsedFull <- collapseFullCoverage(fullCov, colsubset = colsubset, save=TRUE)
}
## Get the adjustments
sampleDepths <- sampleDepth(collapsedFull = collapsedFull, probs = 1,
nonzero = TRUE, scalefac = 32, center = FALSE)
save(sampleDepths, file="sampleDepths.Rdata")
}
## Build the models
models <- makeModels(sampleDepths = sampleDepths, testvars = testvars,
adjustvars = NULL, testIntercept = FALSE)
return(models)
}
##### Note that this whole section is for defining the models using makeModels()
##### You can alternatively define them manually and/or use packages such as splines if needed.
if(opt$experiment == 'snyder') {
## The information table
info <- read.csv("/home/epi/ajaffe/Lieber/Projects/Timecourse_RNAseq/Profile/phenotype.csv")
info$shortBAM <- gsub(".*/", "", info$bamFile)
## Match dirs with actual rows in the info table
match <- sapply(files, function(x) { which(info$GEO_ID == x)})
info <- info[match, ]
## Test a spline on days
library("splines")
testvars <- bs(info$Day, df=5)
## Define the groups for plotting
library("Hmisc")
groupInfo <- cut2(info$Day, g=4)
tmp <- groupInfo
groupInfo <- factor(gsub(",", "to", gsub("\\[| |)|\\]", "", groupInfo)))
names(groupInfo) <- tmp
## Build models
models <- buildModels(fullCov, testvars)
} else if(opt$experiment == 'hippo') {
## Define the groups
load("/home/epi/ajaffe/Lieber/Projects/RNAseq/HippoPublic/sra_phenotype_file.rda")
info <- sra
info <- info[complete.cases(info),]
## Match dirs with actual rows in the info table
match <- sapply(files, function(x) { which(info$SampleID == x)})
info <- info[match, ]
## Set the control group as the reference
groupInfo <- factor(info$Pheno, levels=c("CT", "CO", "ETOH"))
## Define colsubset
colsubset <- which(!is.na(groupInfo))
save(colsubset, file="colsubset.Rdata")
## Update the group labels
groupInfo <- groupInfo[!is.na(groupInfo)]
## Build models
models <- buildModels(fullCov, groupInfo, colsubset)
}
## Save models
save(models, file="models.Rdata")
## Save information used for analyzeChr(groupInfo)
save(groupInfo, file="groupInfo.Rdata")
## Done :-)
proc.time()
options(width = 120)
session_info()