annotate dexseq-hts_1.0/src/run_DEXseq.R @ 11:cec4b4fb30be draft default tip

DEXSeq version 1.6 added
author vipints <vipin@cbio.mskcc.org>
date Tue, 08 Oct 2013 08:22:45 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
1 ### load DEXSeq package
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
2 suppressMessages(require("DEXSeq"))
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
3
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
4 ### get arguments 1: INFILE, 2: OUTFILE 3:SIZE
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
5 args <- commandArgs()
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
6 INFILE<-args[4]
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
7 EXTRAPATH<-args[5]
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
8 annodb<-args[6]
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
9 OUTFILE<-args[7]
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
10
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
11 INFILE_CONDS=c(paste(INFILE, "_CONDITIONS.tab", sep=""))
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
12
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
13 ### read count data from file
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
14 condsTable <- read.delim( INFILE_CONDS, header=TRUE, stringsAsFactors=TRUE, row.names=1 )
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
15 #head(condsTable)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
16
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
17 conditions<-factor( condsTable[ , 1] )
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
18 #print(conditions)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
19
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
20 ## unique condition to define the pair of tests
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
21 uniq_conds <- unique(conditions)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
22 #print(uniq_conds)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
23
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
24 ## all possible pairs of conditions
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
25 pw_tests <- list()
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
26 for(i in 1:(length(uniq_conds)-1)) {
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
27 for(j in (i+1):length(uniq_conds)) {
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
28 pw_tests[[length(pw_tests)+1]] <- c(uniq_conds[i], uniq_conds[j])
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
29 }
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
30 }
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
31 #print(pw_tests)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
32
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
33 tab <- NULL
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
34 ## testing all possible pairs of conditions
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
35 for(i in 1:length(pw_tests)) {
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
36 ## header name
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
37 test_pair_name <- c(paste(pw_tests[[i]][1], "__vs__", pw_tests[[i]][2], sep=""))
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
38 print(test_pair_name)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
39
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
40 sub.data <- subset(condsTable, (conditions %in% c(pw_tests[[i]][1],pw_tests[[i]][2])))
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
41 sub.data[[1]]<-as.factor(sub.data[[1]])
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
42
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
43 ecs = read.HTSeqCounts(countfiles=file.path(EXTRAPATH, row.names(sub.data)), design=sub.data, flattenedfile=annodb)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
44
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
45 ## Normalisation
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
46 ecs <- estimateSizeFactors(ecs)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
47 print(sizeFactors(ecs))
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
48
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
49 suppressMessages(require("parallel"))
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
50 ## Dispersion estimation
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
51 ecs <- estimateDispersions(ecs, nCores=2)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
52 ecs <- fitDispersionFunction(ecs)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
53
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
54 ## Testing for differential exon usage
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
55 ecs <- testForDEU(ecs, nCores=2)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
56
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
57 ## estimate the fold change
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
58 ecs <- estimatelog2FoldChanges(ecs, nCores=2)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
59
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
60 ## Result table
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
61 resultTable <- DEUresultTable(ecs)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
62 print(head(resultTable))
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
63
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
64 colnames(resultTable) <- paste(test_pair_name, colnames(resultTable), sep=":")
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
65 #print(colnames(resultTable))
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
66
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
67 if(is.null(tab)) {
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
68 tab<- resultTable
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
69 }
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
70 else tab<- cbind(tab, resultTable)
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
71 }
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
72 ## printing the result to out file
cec4b4fb30be DEXSeq version 1.6 added
vipints <vipin@cbio.mskcc.org>
parents:
diff changeset
73 write.table(tab, OUTFILE, quote=F, sep="\t", row.names=F)