Skip to content

Commit

Permalink
pca plot with no colors, ref #13
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo Garcia committed Jun 3, 2015
1 parent 2a52b5f commit a1cc62b
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions PCAPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,41 @@
#

suppressPackageStartupMessages(library(argparse))
library(devtools)
install_github("ggbiplot", "vqv")
library(ggbiplot)
suppressPackageStartupMessages(library(ggbiplot))

parser <- ArgumentParser(description="Plot PCA")
parser$add_argument("--matrix", required=TRUE, help="normalized expression matrix output")
parser <- ArgumentParser(description="Plot PCA from a matrix file.")
parser$add_argument("--matrix", required=TRUE, help="matrix file")
parser$add_argument("--pdf", required=TRUE, help="path to PDF output")
args <- parser$parse_args()


pcaexprmat<-function(M){
#An expression matrix as input.
T.M<-t(M)
#Se transpone para que los pacientes queden como rownames y se integren con los grupos definidos sobre ellossean grupo
colnames(T.M)<-rownames(M)
# Se evita que los colnames de la nueva matrix queden vacios (de lo contrario ggplots dara problemas)
T.M.log<-log(T.M)
T.M.pca<-prcomp(T.M,center=TRUE,scale.=TRUE)
summary(T.M.pca)
plot(T.M.pca, type = "l")
return(T.M.pca)
T.M<-t(M)
colnames(T.M)<-rownames(M)
T.M.log<-log(T.M)
T.M.pca<-prcomp(T.M, center=TRUE, scale.=TRUE)
#plot(T.M.pca, type = "l")

summary(T.M.pca)
return(T.M.pca)
}


plotpcagroups <-function (T.M.pca , SPECIES){
g <- ggbiplot(T.M.pca, obs.scale = 1, var.scale = 1, var.axes=FALSE ,groups = SPECIES, ellipse = TRUE, circle = TRUE)
g <- g + scale_color_discrete(name = '')
g <- g + theme(legend.direction = 'horizontal',
legend.position = 'top')
pdf(file="PlotT.M.pca.pdf")
print(g)
dev.off()
plotpcagroups <-function (T.M.pca, outpdf) {
pdf(file=outpdf)
g <- ggbiplot(T.M.pca, obs.scale = 1, var.scale = 1, var.axes=FALSE, ellipse = TRUE, circle = TRUE)
g <- g + scale_color_discrete(name = '')
g <- g + theme(legend.direction = 'horizontal',
legend.position = 'top')
print(g)
dev.off()
}


M = read.table(args$matrix)
plotpcagroups( pcaexprmat(M) )




M = read.table(args$matrix, sep=",", header=TRUE, row.names=1)

plotpcagroups( pcaexprmat(M), args$pdf )

0 comments on commit a1cc62b

Please sign in to comment.