0
|
1 #!/usr/local/public/bin/Rscript --verbose
|
|
2 # 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 # abims_hclust.r version 20130604
|
|
8
|
|
9 library(batch)
|
|
10 library(ctc)
|
|
11
|
|
12 hclust_metabolomics = function(file, method = "pearson", link = "ward", normalization=TRUE, keep.hclust=FALSE, sep=";", dec="."){
|
|
13
|
|
14 if (sep=="tabulation") sep="\t"
|
|
15 if (sep=="semicolon") sep=";"
|
|
16 if (sep=="comma") sep=","
|
|
17
|
|
18 # -- loading --
|
|
19 data=read.table(file, header = TRUE, row.names=1, sep = sep, quote="\"", dec = dec,
|
|
20 fill = TRUE, comment.char="",na.strings = "NA")
|
|
21
|
|
22 # -- Normalization: logratio --
|
|
23 if (normalization) {
|
1
|
24 #meandata = apply(data,1,mean, na.rm=T)
|
|
25 #data = log2(data/meandata)
|
|
26 data=t(scale(t(data)))
|
|
27
|
|
28 #AMAP: Unable to compute Hierarchical Clustering: missing values in distance matrix
|
|
29 #Erreur dans hcluster(x, method = method, link = link) :
|
|
30 # Missing values in distance Matrix
|
|
31 #Calls: do.call -> <Anonymous> -> hclust2treeview -> hcluster
|
|
32 #Exécution arrêtée
|
|
33 data[is.nan(data)] = 0
|
0
|
34 }
|
1
|
35
|
|
36 #Erreur dans `[.default`(xj, i) :
|
|
37 # les indices négatifs ne peuvent être mélangés qu'à des 0
|
|
38 #Calls: do.call ... r2cdt -> [ -> [.data.frame -> [ -> [.factor -> NextMethod
|
|
39 #Exécution arrêtée
|
|
40 data = data[!apply(data,1,sum)==0,]
|
0
|
41
|
|
42 # -- hclust / output files for TreeView --
|
|
43 file="hclust.cdt"
|
|
44 hclust2treeview(data,file=file, method = method, link = link, keep.hclust= keep.hclust)
|
|
45
|
|
46 # -- output / return --
|
|
47 system("zip -r hclust.zip hclust.*", ignore.stdout = TRUE)
|
|
48 }
|
|
49
|
|
50 listArguments = parseCommandArgs(evaluate=FALSE)
|
|
51 do.call(hclust_metabolomics, listArguments)
|