Mercurial > repos > ecology > ecoregion_brt_analysis
comparison indval.R @ 8:dcc059f387b6 draft default tip
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Ecoregionalization_workflow commit 9dee19b2d28b61a81f2a89d4c7d35678e31a9927
author | ecology |
---|---|
date | Wed, 23 Jul 2025 14:37:01 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:694738eda0dc | 8:dcc059f387b6 |
---|---|
1 #Seguineau Pauline | |
2 #02/12/2024 | |
3 #Indicspecies tool | |
4 | |
5 library(dplyr) | |
6 library(indicspecies) | |
7 | |
8 #load arguments | |
9 args = commandArgs(trailingOnly=TRUE) | |
10 if (length(args)==0) | |
11 { | |
12 stop("This tool needs at least one argument") | |
13 }else{ | |
14 clus_pts <- args[1] | |
15 occ <- args[2] | |
16 spe_name <- args[3] | |
17 sign <- args[4] | |
18 } | |
19 | |
20 ###load data | |
21 clus <- read.table(clus_pts, dec=".", sep="\t", header=T,na.strings = "na") #cluster points file (ecoregionalization workflow) | |
22 data.col <- read.table(occ, dec=".", sep="\t", header=T,na.strings = "na") #occurrence file (merged table from ecoregionalization workflow) | |
23 spe_name = strsplit(spe_name, ",") | |
24 spname=NULL | |
25 | |
26 for (n in spe_name) { | |
27 spname = cbind(names(data.col[as.numeric(n)]))} | |
28 | |
29 #Rename decimalLatitude and decimalLongitude columns from occurrence file | |
30 if ("decimalLatitude" %in% colnames(data.col)) { | |
31 colnames(data.col)[which(colnames(data.col) == "decimalLatitude")] <- "lat" | |
32 } | |
33 if ("decimalLongitude" %in% colnames(data.col)) { | |
34 colnames(data.col)[which(colnames(data.col) == "decimalLongitude")] <- "long" | |
35 } | |
36 | |
37 #Round lat and long of the data.col file to be able to put clus cluster in it | |
38 data.col$lat = round(data.col$lat,digits = 2) | |
39 data.col$long = round(data.col$long,digits = 2) | |
40 | |
41 # Creates a new "station" column that associates a unique identifier to each latitude-longitude pair | |
42 data.col <- data.col %>% mutate(station = as.factor(paste(lat, long, sep = "_"))) | |
43 | |
44 # convert "station" to a unique numeric identifier | |
45 data.col <- data.col %>% mutate(station = as.numeric(factor(station))) | |
46 | |
47 #Adding clusters to file | |
48 clusta <- merge(data.col,clus, by=c("lat","long"), all.x = TRUE) | |
49 | |
50 #This generated duplicates with different clusters | |
51 clusta <- aggregate(clusta, by=list(clusta$station,clusta$cluster), FUN=mean, na.rm=TRUE) | |
52 clusta <- na.exclude(clusta) | |
53 | |
54 # indval on all clusters | |
55 indval = multipatt(clusta[,spname], clusta$cluster,duleg = TRUE, control = how(nperm=999)) | |
56 if (sign=="true"){ | |
57 capture.output(summary(indval,indvalcomp=TRUE), file = "indval.txt") | |
58 }else{ | |
59 capture.output(summary(indval,indvalcomp=TRUE, alpha=1), file = "indval.txt")} |