annotate abims_hclustering.r @ 1:36fc0a87d7fb draft default tip

planemo upload
author lecorguille
date Fri, 13 Nov 2015 08:43:11 -0500
parents 2f7381ee5235
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
1 #!/usr/local/public/bin/Rscript --verbose
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
2 # version="1.1"
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
3
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
4 # date: 04-06-2013
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
5 # **Authors** Gildas Le Corguille ABiMS - UPMC/CNRS - Station Biologique de Roscoff - gildas.lecorguille|at|sb-roscoff.fr
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
6
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
7 # abims_hclust.r version 20130604
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
8
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
9 library(batch)
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
10 library(ctc)
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
11
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
12 hclust_metabolomics = function(file, method = "pearson", link = "ward", normalization=TRUE, keep.hclust=FALSE, sep=";", dec="."){
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
13
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
14 if (sep=="tabulation") sep="\t"
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
15 if (sep=="semicolon") sep=";"
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
16 if (sep=="comma") sep=","
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
17
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
18 # -- loading --
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
19 data=read.table(file, header = TRUE, row.names=1, sep = sep, quote="\"", dec = dec,
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
20 fill = TRUE, comment.char="",na.strings = "NA")
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
21
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
22 # -- Normalization: logratio --
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
23 if (normalization) {
1
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
24 #meandata = apply(data,1,mean, na.rm=T)
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
25 #data = log2(data/meandata)
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
26 data=t(scale(t(data)))
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
27
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
28 #AMAP: Unable to compute Hierarchical Clustering: missing values in distance matrix
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
29 #Erreur dans hcluster(x, method = method, link = link) :
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
30 # Missing values in distance Matrix
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
31 #Calls: do.call -> <Anonymous> -> hclust2treeview -> hcluster
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
32 #Exécution arrêtée
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
33 data[is.nan(data)] = 0
0
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
34 }
1
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
35
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
36 #Erreur dans `[.default`(xj, i) :
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
37 # les indices négatifs ne peuvent être mélangés qu'à des 0
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
38 #Calls: do.call ... r2cdt -> [ -> [.data.frame -> [ -> [.factor -> NextMethod
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
39 #Exécution arrêtée
36fc0a87d7fb planemo upload
lecorguille
parents: 0
diff changeset
40 data = data[!apply(data,1,sum)==0,]
0
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
41
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
42 # -- hclust / output files for TreeView --
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
43 file="hclust.cdt"
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
44 hclust2treeview(data,file=file, method = method, link = link, keep.hclust= keep.hclust)
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
45
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
46 # -- output / return --
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
47 system("zip -r hclust.zip hclust.*", ignore.stdout = TRUE)
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
48 }
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
49
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
50 listArguments = parseCommandArgs(evaluate=FALSE)
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
51 do.call(hclust_metabolomics, listArguments)