|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
read <- function(counts_file, design_file,number_of_samples){ |
|
|
counts = read.table(counts_file, header=TRUE, sep="\t", row.names=1 ) |
|
|
idx = ncol(counts) - number_of_samples |
|
|
|
|
|
|
|
|
if (idx > 0) counts = counts[-c(1:idx)] else counts=counts |
|
|
|
|
|
numeric_idx = sapply(counts, mode) == 'numeric' |
|
|
counts[numeric_idx] = round(counts[numeric_idx], 0) |
|
|
|
|
|
colData = read.table(design_file, header=TRUE, sep="\t", row.names=1 ) |
|
|
|
|
|
|
|
|
dds = DESeqDataSetFromMatrix(countData=counts, colData=colData, design = ~1) |
|
|
|
|
|
|
|
|
vsd = vst(dds) |
|
|
names = colnames(counts) |
|
|
groups = colnames(colData) |
|
|
|
|
|
rlist <- list("vsd" = vsd, "names"=names, "groups" =groups) |
|
|
return(rlist) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
args = commandArgs(trailingOnly=TRUE) |
|
|
|
|
|
|
|
|
if (length(args)!=3) { |
|
|
stop("Counts file, Design file and the number of samples must be specified at the commandline", call.=FALSE) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
suppressPackageStartupMessages(library(DESeq2)) |
|
|
suppressPackageStartupMessages(library(ggplot2)) |
|
|
|
|
|
|
|
|
WIDTH = 12 |
|
|
HEIGHT = 8 |
|
|
|
|
|
|
|
|
|
|
|
infile = args[1] |
|
|
|
|
|
|
|
|
coldata_file = args[2] |
|
|
|
|
|
|
|
|
sno = args[3] |
|
|
sno= as.numeric(sno) |
|
|
|
|
|
res = read(infile, coldata_file, sno) |
|
|
vsd= res$vsd |
|
|
names = res$names |
|
|
groups = res$groups |
|
|
|
|
|
|
|
|
pdf('pca.pdf', width = WIDTH, height = HEIGHT) |
|
|
par(mfrow = c(2,1)) |
|
|
nudge <- position_nudge(y = 0.5) |
|
|
|
|
|
z=plotPCA(vsd, intgroup=c(groups)) |
|
|
z+ geom_text(aes(label = names), position=nudge, size = 2.5) +ggtitle(aes("PCA")) |
|
|
dev.off() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library(pheatmap) |
|
|
library("RColorBrewer") |
|
|
|
|
|
sampleDists = dist(t(assay(vsd))) |
|
|
sampleDistMatrix = as.matrix(sampleDists) |
|
|
|
|
|
colnames(sampleDistMatrix) = NULL |
|
|
|
|
|
colors = colorRampPalette( rev(brewer.pal(9, "Blues")) )(255) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pdf('heatmap.pdf', width = 8, height = HEIGHT) |
|
|
|
|
|
pheatmap(sampleDistMatrix, |
|
|
clustering_distance_rows=sampleDists, |
|
|
clustering_distance_cols=sampleDists, |
|
|
col=colors) + geom_label(aes(label = names)) |
|
|
|
|
|
dev.off() |
|
|
|
|
|
|