0
|
1 #!/usr/local/public/bin/Rscript
|
|
2 # abims_acp.r version="1.1"
|
|
3
|
|
4 # date: 04-06-2013
|
|
5 # **Authors** Gildas Le Corguille ABiMS - UPMC/CNRS - Station Biologique de Roscoff - gildas.lecorguille|at|sb-roscoff.fr
|
|
6
|
|
7
|
|
8
|
|
9 #function PCA from package FactoMineR
|
|
10
|
|
11 library(batch)
|
|
12 library(FactoMineR)
|
|
13
|
|
14 acp_metabolomics=function(file ,graph=FALSE, scale.unit=TRUE, sep=";", dec="."){
|
|
15
|
|
16 if (sep=="tabulation") sep="\t"
|
|
17 if (sep=="semicolon") sep=";"
|
|
18 if (sep=="comma") sep=","
|
|
19
|
|
20 # -- loading --
|
|
21 data=read.table(file, header = TRUE, row.names=1, sep = sep, quote="\"", dec = dec,
|
|
22 fill = TRUE, comment.char="",na.strings = "NA")
|
|
23
|
|
24 # -- acp / output pdf --
|
|
25 resPCA =PCA(t(data),graph=graph, scale.unit=scale.unit)
|
|
26 # scale.unit=F : on réalise l'ACP sans la réduction des variables
|
|
27 # graph=F : pas de sortie graphique
|
|
28 dev.off() #close plot
|
|
29 dev.off()
|
|
30
|
|
31 # -- output png --
|
|
32 # Percentage of variance
|
|
33 png("percentage_of_variance.png", width =800, height = 400);
|
|
34 barplot(resPCA$eig$per,xlab="Components",ylab="percentage of variance");
|
|
35 dev.off()
|
|
36
|
|
37 png("eigenvalue.png", width =800, height = 400);
|
|
38 barplot(resPCA$eig$eig,xlab="Components",ylab="eigenvalue");
|
|
39 dev.off()
|
|
40
|
|
41 # -- output / return --
|
|
42 system("zip -r acp.zip percentage_of_variance.png eigenvalue.png Rplots*.pdf", ignore.stdout = TRUE)
|
|
43 }
|
|
44
|
|
45 listArguments = parseCommandArgs(evaluate=FALSE)
|
|
46 do.call(acp_metabolomics, listArguments)
|