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