comparison cluster_ceamarc.R @ 0:5cde56683579 draft

planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Ecoregionalization_workflow commit 5d48df67919fbc9d77b98a8243d438c397f61a0e
author ecology
date Thu, 21 Mar 2024 14:05:01 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:5cde56683579
1 ##13/04/2023
2 ##Seguineau Pauline
3 ### Clustering with Clara algorithm
4
5 #load library
6 library(cluster)
7 library(dplyr)
8 library(tidyverse)
9
10 #load arguments
11 args = commandArgs(trailingOnly=TRUE)
12 if (length(args)==0)
13 {
14 stop("This tool needs at least one argument")
15 }else{
16 data <- args[1]
17 enviro <- args[2]
18 data.bio <- args[3]
19 k <- as.numeric(args[4])
20 metric <- args[5]
21 sample <- as.numeric(args[6])
22 }
23
24 #load data
25 env.data <- read.table(enviro, header=TRUE, sep="\t",dec = ".", na.strings = "-9999")
26 data.bio <- read.table(data.bio, header=TRUE, sep="\t")
27 test3 <- read.table(data, header = TRUE, sep="\t")
28
29 ######################################################################################################
30 #Make clustering
31
32 k <- k #number of clusters
33 test5 <- clara(test3, k, metric = metric, samples = sample, sampsize = min(nrow(test3), (nrow(data.bio)/nrow(test3))+2*k))
34
35 #######################################################################################################
36 #save results
37
38 png("sih.png")
39 plot(silhouette(test5))
40 dev.off()
41
42 clus <- cbind(data.bio[1:nrow(test3), 1:2],test5$clustering)
43 names(clus) <- c("lat", "long", "cluster")
44 clus <- cbind(clus,test3,env.data[,3:19])
45
46 write.table(clus[1:3], file = "points_clus.tsv", quote = FALSE, sep="\t", row.names = FALSE)
47 write.table(clus, file = "clus.tsv", quote = FALSE, sep="\t", row.names = FALSE)
48
49
50
51
52