Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions script/run_deseq.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sizeFactorsFile <- Args[7]
qcPdfFile <- Args[8]
filterPercentile <- as.numeric( Args[9] )


# Get data and samples
countData <- read.table( countFile, header=TRUE, row.names=1 )
samples <- read.table( samplesFile, header=TRUE, row.names=1 )
Expand Down Expand Up @@ -42,7 +43,7 @@ if (filterPercentile) {
# Create DESeqDataSet (with design according to number of factors)
dds <- DESeqDataSetFromMatrix(countData, samples, design = ~ condition)
if (numFactors == 2) {
design(dds) <- formula(~ group + condition)
design(dds) <- formula(~ group * condition)
}

# Ensure control level (usually "sibling") is first level (i.e. before "mutant")
Expand All @@ -51,14 +52,34 @@ colData(dds)$condition <- factor(colData(dds)$condition,

# Differential expression analysis
dds <- DESeq(dds)
res <- results(dds)

# Find the condition term (does not contain '.' and constains 'condition')
results_names=resultsNames(dds)
non_interaction_terms = which(grepl("\\.",results_names,perl =T) == FALSE)
all_condition_terms_index = which(grepl("condition",results_names) == TRUE)
condition_terms_index = intersect(non_interaction_terms,all_condition_terms_index)

# create matrix with pvalues of all terms in the model
pvalues_matrix = matrix(ncol=0,nrow=nrow(dds))
col_names<-c();
for (i in 1:length(results_names) )
{
equation_term = results_names[i];
results = results(dds, name= equation_term)
palues = as.matrix(results$pvalue)
padj = as.matrix(results$padj)
pvalues_matrix = cbind(pvalues_matrix,palues)
pvalues_matrix = cbind(pvalues_matrix,padj)
col_names<-c(col_names,paste(equation_term,"_pvalue",sep=""),paste(equation_term,"_pvalue_adjusted",sep=""))
}
colnames(pvalues_matrix)=col_names;



# Write output
out <- data.frame(pvalue=res$pvalue, padj=res$padj, row.names=rownames(res))
write.table( out, file=outputFile, col.names=FALSE, row.names=TRUE,
quote=FALSE, sep="\t" )
write.table( sizeFactors( dds ), file=sizeFactorsFile, col.names=FALSE,
row.names=FALSE, quote=FALSE, sep="\t" )
out <- data.frame(pvalues_matrix, row.names=rownames(res))
write.table( out, file=outputFile, col.names=TRUE, row.names=TRUE, quote=FALSE, sep="\t" )
write.table( sizeFactors( dds ), file=sizeFactorsFile, col.names=FALSE,row.names=FALSE, quote=FALSE, sep="\t" )

# Data transformations for QC
rld <- rlogTransformation(dds, blind=TRUE)
Expand Down