comparison recup_liste_taxon.R @ 1:b38b954b92b9 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:20 +0000
parents 3d750279158b
children 374555fc30bd
comparison
equal deleted inserted replaced
0:3d750279158b 1:b38b954b92b9
14 data <- args[1] 14 data <- args[1]
15 preds <- args[2] 15 preds <- args[2]
16 enviro <- args[3] 16 enviro <- args[3]
17 } 17 }
18 18
19 env = read.table(enviro, header=T, na.strings = "na") 19 env = read.table(enviro, sep="\t", dec=".", header=T, na.strings = "-9999")
20 occurrence_files = strsplit(data,",") 20 occurrence_files = strsplit(data,",")
21 preds_files = strsplit(preds,",") 21 preds_files = strsplit(preds,",")
22 22
23 #########functions########## 23 #########functions##########
24 24
43 return(have_model)} 43 return(have_model)}
44 44
45 ##########Execution######## 45 ##########Execution########
46 brt = NULL 46 brt = NULL
47 for (j in 1:length(preds_files[[1]])){ 47 for (j in 1:length(preds_files[[1]])){
48 brt <- rbind(brt,read.table(preds_files[[1]][j], header = TRUE, na.strings = "na")) 48 brt <- rbind(brt,read.table(preds_files[[1]][j], sep="\t", header = TRUE, na.strings = "na"))
49 } 49 }
50 50
51 for (i in 1:length(occurrence_files[[1]])) { 51 for (i in 1:length(occurrence_files[[1]])) {
52 occurrence <- NULL 52 occurrence <- NULL
53 cmpt <- NULL 53 cmpt <- NULL
54 taxon <- list() 54 taxon <- list()
55 55
56 occurrence <- read.table(occurrence_files[[1]][i], dec = ",", sep = ";", header = TRUE, na.strings = "na") 56 occurrence <- read.table(occurrence_files[[1]][i], sep = "\t", header = TRUE, na.strings = "na")
57 57
58 taxon_names <- names(occurrence) 58 taxon_names <- names(occurrence)
59 new_taxon <- taxon_names[!(taxon_names %in% names(env)) & taxon_names != "station"] 59 new_taxon <- taxon_names[!(taxon_names %in% names(env)) & taxon_names != "station"]
60 taxon <- c(taxon, new_taxon) 60 taxon <- c(taxon, new_taxon)
61 61
64 64
65 have_model <- have.model(taxon, occurrence, cmpt, brt) 65 have_model <- have.model(taxon, occurrence, cmpt, brt)
66 } 66 }
67 67
68 #Taxa for which a model was obtained 68 #Taxa for which a model was obtained
69 have_model2 = subset(have_model, have_model$`Model` != "N") 69 have_model2 = subset(have_model, have_model$`Model` != "No")
70 have_model3 = subset(have_model, have_model$`Model` != "N") 70 have_model3 = subset(have_model, have_model$`Model` != "No")
71 71
72 #Obtain a list of taxa (cleaned) that have obtained a BRT model (file that can be submitted to the match taxa tool of the WoRMS database to obtain their classification and be able to sort duplicates between taxonomic ranks) 72 #Obtain a list of taxa (cleaned) that have obtained a BRT model (file that can be submitted to the match taxa tool of the WoRMS database to obtain their classification and be able to sort duplicates between taxonomic ranks)
73 73
74 have_model2$Taxa <- as.character(trim_taxa(have_model2$Taxa)) 74 have_model2$Taxa <- as.character(trim_taxa(have_model2$Taxa))
75 75
78 have_model2 <- have_model2 %>% filter(!str_ends(Taxa, "sp.1|sp[0-9]")) 78 have_model2 <- have_model2 %>% filter(!str_ends(Taxa, "sp.1|sp[0-9]"))
79 have_model3 <- have_model3 %>% filter(!str_ends(Taxa, "sp.1|sp[0-9]")) 79 have_model3 <- have_model3 %>% filter(!str_ends(Taxa, "sp.1|sp[0-9]"))
80 have_model <- have_model %>% filter(!str_ends(Taxa, "sp.1|sp[0-9]")) 80 have_model <- have_model %>% filter(!str_ends(Taxa, "sp.1|sp[0-9]"))
81 81
82 #extraction of the have_model object 82 #extraction of the have_model object
83 write.csv(have_model,file = "have_model.csv", quote = F, row.names = F) 83 write.table(have_model,file = "have_model.tsv", sep="\t", quote = F, row.names = F)
84 84
85 #getting list of taxa for next if not using worms 85 #getting list of taxa for next if not using worms
86 list_taxon = have_model3$Taxa 86 list_taxon = have_model3$Taxa
87 write.table(list_taxon, file= "list_taxa.txt", quote = F, row.names = F, col.names = F) 87 write.table(list_taxon, file= "list_taxa.txt", quote = F, row.names = F, col.names = F)
88 88