comparison brt.R @ 1:e94a25eed489 draft

planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Ecoregionalization_workflow commit 459ba1277acd7d8d4a02f90dbd7ff444bf8eac92
author ecology
date Wed, 24 Jan 2024 15:53:32 +0000
parents 0f6542d0986e
children 001d7d101915
comparison
equal deleted inserted replaced
0:0f6542d0986e 1:e94a25eed489
1 #16/02/2023 1 #16/02/2023
2 ## Analyse BRT data Ceamarc 2 ## Analyse BRT data
3 3
4 ### Clean environment 4 ### Clean environment
5 rm(list = ls(all.names = TRUE)) 5 rm(list = ls(all.names = TRUE))
6 options(warn=-1) 6 options(warn=-1)
7 7
19 stop("This tool needs at least one argument") 19 stop("This tool needs at least one argument")
20 }else{ 20 }else{
21 enviro <- args[1] 21 enviro <- args[1]
22 species_files <- args[2] 22 species_files <- args[2]
23 abio_para <- args[3] 23 abio_para <- args[3]
24 dec_env <- args[8]
25 dec_species <- args[9]
24 } 26 }
25 27
26 ### load data 28 ### load data
27 29
28 env = read.table(enviro, header = TRUE, dec = ".", na.strings = "-9999") 30 env = read.table(enviro, dec = dec_env, header = TRUE, sep="\t", na.strings = "-9999")
29 pred.vars = strsplit(abio_para, ",")[[1]] 31 pred_vars = strsplit(abio_para, ",")[[1]]
30 data_files = strsplit(species_files,",") 32 data_files = strsplit(species_files,",")
31 33
34 pred.vars <- character(length(pred_vars))
35
36 for (i in seq_along(pred_vars)) {
37 pred_var_col <- as.numeric(pred_vars[i])
38 pred.vars[i] <- names(env)[pred_var_col]}
39
32 #environemental parameters 40 #environemental parameters
33 #Carbo,Grav,Maxbearing,Maxmagnit,Meancurmag,Meansal,Meantheta,Mud,Prof,Rugosity,Sand,Seaice_prod,Sili,Slope,Standcurmag,Standsal,Standtheta 41 #Carbo,Grav,Maxbearing,Maxmagnit,Meancurmag,Meansal,Meantheta,Mud,Prof,Rugosity,Sand,Seaice_prod,Sili,Slope,Standcurmag,Standsal,Standtheta
34 42
35 #Load functions 43 #Load functions
36 44
84 coord_quickmap() 92 coord_quickmap()
85 output_directory <- ggsave(paste("BRT-",spe,"_pred_plot.png")) 93 output_directory <- ggsave(paste("BRT-",spe,"_pred_plot.png"))
86 94
87 #Write prediction in a file 95 #Write prediction in a file
88 preds <- cbind(preds,spe) 96 preds <- cbind(preds,spe)
89 write.table(preds, paste(nb_file,"_brts_pred_ceamarc.txt",sep=""), quote=FALSE, dec=".", row.names=F, col.names=T,append = T) 97 write.table(preds, paste(nb_file,"_brts_pred_ceamarc.tsv",sep=""), quote=FALSE, dec=".", row.names=F, col.names=T,append = T,sep="\t")
90 } 98 }
91 99
92 #### RUN BRT #### 100 #### RUN BRT ####
93 nb_file = 0 101 nb_file = 0
94 102
95 for (file in data_files[[1]]) { 103 for (file in data_files[[1]]) {
96 species_data <- read.table(file, dec = ",", sep = ";", header = TRUE, na.strings = "na", colClasses = "numeric") 104 species_data <- read.table(file, dec = dec_species, sep = "\t", header = TRUE, na.strings = "NA", colClasses = "numeric")
97 nb_file = nb_file + 1 105 nb_file = nb_file + 1
98 `%!in%` <- Negate(`%in%`) 106 `%!in%` <- Negate(`%in%`)
99 sp = list() 107 sp = list()
100 for (n in names(species_data)) { 108 for (n in names(species_data)) {
101 if (n %!in% names(env) && n != 'station'){ 109 if (n %!in% names(env) && n != 'station'){
102 sp = cbind(sp,n) 110 sp = cbind(sp,n)
103 } 111 }
104 } 112 }
105
106 for (spe in sp){ 113 for (spe in sp){
107 try(make.prediction.brt(make.brt(spe,species_data,pred.vars,env,nb_file))) 114 try(make.prediction.brt(make.brt(spe,species_data,pred.vars,env,nb_file)))
108 } 115 }
109 } 116 }
117
118 cat("Here is the list of your abiotic parameters:\n")
119 cat(paste(pred.vars, collapse = ", "), "\n")
120
121