comparison cluster_ceamarc.R @ 0:f0d6938d0451 draft

planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Ecoregionalization_workflow commit 2a2ae892fa2dbc1eff9c6a59c3ad8f3c27c1c78d
author ecology
date Wed, 18 Oct 2023 09:58:51 +0000
parents
children fc621f3f8226
comparison
equal deleted inserted replaced
-1:000000000000 0:f0d6938d0451
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=" ",dec = ".", na.strings = "-9999.00")
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.txt",quote = FALSE, row.names = FALSE)
47 write.table(clus, file = "clus.txt",quote = FALSE, row.names = FALSE)
48
49
50
51
52