annotate abims_hclustering.r @ 0:2f7381ee5235 draft

Uploaded
author lecorguille
date Tue, 30 Jun 2015 06:36:09 -0400
parents
children 36fc0a87d7fb
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) {
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
24 #meandata = apply(data,1,mean, na.rm=T)
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
25 #data = log2(data/meandata)
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
26 data=t(scale(t(data)))
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
27 }
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
28
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
29 # -- hclust / output files for TreeView --
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
30 file="hclust.cdt"
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
31 hclust2treeview(data,file=file, method = method, link = link, keep.hclust= keep.hclust)
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
32
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
33 # -- output / return --
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
34 system("zip -r hclust.zip hclust.*", ignore.stdout = TRUE)
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
35 }
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
36
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
37 listArguments = parseCommandArgs(evaluate=FALSE)
2f7381ee5235 Uploaded
lecorguille
parents:
diff changeset
38 do.call(hclust_metabolomics, listArguments)