annotate deseq-hts_1.0/src/difftest_deseq.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 e27b4f7811c2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
1 ### load DESeq package
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
2 suppressMessages(require("DESeq"))
0
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
3
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
4 ### get arguments 1: INFILE, 2: OUTFILE 3:SIZE
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
5 args <- commandArgs()
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
6 INFILE<-args[4]
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
7 OUTFILE<-args[5]
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
8
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
9 INFILE_COUNTS=c(paste(INFILE, "_COUNTS.tab", sep=""))
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
10 INFILE_CONDS=c(paste(INFILE, "_CONDITIONS.tab", sep=""))
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
11
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
12 ### read count data from file
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
13 countsTable <- read.delim( INFILE_COUNTS, header=TRUE, stringsAsFactors=TRUE )
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
14 condsTable <- read.delim( INFILE_CONDS, header=TRUE, stringsAsFactors=TRUE )
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
15
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
16 ### use gene IDs as row names
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
17 rownames( countsTable ) <- countsTable$gene
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
18 countsTable <- countsTable[ , -1 ]
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
19 head( countsTable )
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
20
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
21 conds <- factor( condsTable[ , 2] )
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
22 #head( countsTable )
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
23
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
24 cds <- newCountDataSet( round(countsTable), conds )
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
25 #head( counts(cds) )
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
26
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
27 cds <- estimateSizeFactors( cds )
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
28 #sizeFactors( cds )
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
29
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
30 ### estimate variance function, use blind only, if no replicates are provided
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
31 if (length(levels(conds)) < length(conds))
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
32 {
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
33 cds <- estimateDispersions( cds )
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
34 } else {
9
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
35 writeLines("\n***You did not enter any replicates! - The results may be less valuable without replicates!***\n")
0
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
36 cds <- estimateDispersions( cds, method='blind', sharingMode='fit-only')
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
37 }
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
38 experiments <- levels(conds)
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
39
9
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
40 res_1<-c()
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
41 res_2<-c()
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
42 res_3<-c()
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
43 res_4<-c()
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
44 res_5<-c()
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
45 res_6<-c()
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
46 res_7<-c()
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
47 res_8<-c()
0
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
48 table_col_names<-c()
9
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
49
0
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
50 for (i in 1:(length(experiments)-1))
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
51 {
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
52 for( j in (i+1):(length(experiments)))
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
53 {
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
54 print(c(i,j))
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
55 tempres <- nbinomTest(cds,experiments[i],experiments[j])
9
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
56 res_1 = cbind(res_1,tempres[,1])
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
57 res_2 = cbind(res_2,tempres[,2])
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
58 res_3 = cbind(res_3,tempres[,3])
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
59 res_4 = cbind(res_4,tempres[,4])
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
60 res_5 = cbind(res_5,tempres[,5])
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
61 res_6 = cbind(res_6,tempres[,6])
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
62 res_7 = cbind(res_7,tempres[,7])
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
63 res_8 = cbind(res_8,tempres[,8])
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
64 table_col_names = cbind(table_col_names,paste('cond_', experiments[i], '_vs._cond_', experiments[j], sep='', 'test'))
0
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
65 }
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
66 }
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
67
9
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
68 DiffTable<-cbind(res_1,res_2,res_3,res_4,res_5,res_6,res_7,res_8)
e27b4f7811c2 Updated DESeq version 1.12
vipints <vipin@cbio.mskcc.org>
parents: 0
diff changeset
69 colnames(DiffTable)<-c('feature ID', 'base mean', 'base mean A', 'base mean B', 'fold change', 'log2 fold change','p value', 'adjusted p value')
0
94a108763d9e deseq-hts version 1.0 wraps the DESeq 1.6.0
vipints
parents:
diff changeset
70 write.table(DiffTable, file = OUTFILE, quote = FALSE, sep ="\t", eol ="\n", na = "1.000", dec = ".", row.names = TRUE,col.names =TRUE)