annotate abims_acp.r @ 0:79c7fdc90ed6 draft default tip

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