Mercurial > repos > ecology > obis_data
comparison robis.r @ 0:ed3688d04c12 draft default tip
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit 13ac67c0a21d742b29e6273cdff058560abad770
| author | ecology |
|---|---|
| date | Tue, 05 Nov 2024 14:17:28 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:ed3688d04c12 |
|---|---|
| 1 #Rscript | |
| 2 | |
| 3 ########################################### | |
| 4 ## Retrieve Obis occurences data ## | |
| 5 ########################################### | |
| 6 | |
| 7 ##### Packages : robis | |
| 8 # https://iobis.github.io/robis/articles/getting-started.html | |
| 9 # Get args | |
| 10 args <- commandArgs(trailingOnly = TRUE) | |
| 11 | |
| 12 if (length(args) < 1) { | |
| 13 stop("This tool needs at least 1 argument : longitude, latitude, species or taxonID") | |
| 14 }else { | |
| 15 sname <- args[1] | |
| 16 taxid <- args[2] | |
| 17 lat_min <- args[3] | |
| 18 lat_max <- args[4] | |
| 19 long_min <- args[5] | |
| 20 long_max <- args[6] | |
| 21 } | |
| 22 | |
| 23 if (lat_min == "0.0" & lat_max == "0.0" & long_min == "0.0" & long_max == "0.0") { | |
| 24 lat_min <- "" | |
| 25 lat_max <- "" | |
| 26 long_min <- "" | |
| 27 long_max <- "" | |
| 28 } | |
| 29 | |
| 30 ##### Import data | |
| 31 # Get biological occurrences | |
| 32 if (lat_min != "" & sname != "" & taxid != "") { | |
| 33 my_occs <- robis::occurrence(scientificname = sname, taxonid = taxid, geometry = paste("POLYGON ((", long_min, lat_min, ", ", long_min, lat_max, ", ", long_max, lat_min, ", ", long_max, lat_max, ", ", long_min, lat_min, "))")) | |
| 34 }else if (lat_min != "" & sname != "" & taxid == "") { | |
| 35 my_occs <- robis::occurrence(scientificname = sname, geometry = paste("POLYGON ((", long_min, lat_min, ", ", long_min, lat_max, ", ", long_max, lat_min, ", ", long_max, lat_max, ", ", long_min, lat_min, "))")) | |
| 36 }else if (lat_min != "" & sname == "" & taxid != "") { | |
| 37 my_occs <- robis::occurrence(taxonid = taxid, geometry = paste("POLYGON ((", long_min, lat_min, ", ", long_min, lat_max, ", ", long_max, lat_min, ", ", long_max, lat_max, ", ", long_min, lat_min, "))")) | |
| 38 }else if (lat_min != "" & sname == "" & taxid == "") { | |
| 39 my_occs <- robis::occurrence(geometry = paste("POLYGON ((", long_min, lat_min, ", ", long_min, lat_max, ", ", long_max, lat_min, ", ", long_max, lat_max, ", ", long_min, lat_min, "))")) | |
| 40 }else if (lat_min == "" & sname != "" & taxid != "") { | |
| 41 my_occs <- robis::occurrence(scientificname = sname, taxonid = taxid) | |
| 42 }else if (lat_min == "" & sname == "" & taxid != "") { | |
| 43 my_occs <- robis::occurrence(taxonid = taxid) | |
| 44 }else if (lat_min == "" & sname != "" & taxid == "") { | |
| 45 my_occs <- robis::occurrence(scientificname = sname) | |
| 46 } | |
| 47 | |
| 48 | |
| 49 # Dispay results | |
| 50 | |
| 51 # If empty | |
| 52 if(length(my_occs) == 0) { | |
| 53 cat("\nNo occurrences found.\nLittle tip : Check your input typo, some databases are case sensitive : Genus species.\n") | |
| 54 } | |
| 55 | |
| 56 | |
| 57 write.table(file = "output.tab", my_occs, sep = "\t", dec = ".", na = "", row.names = FALSE, col.names = TRUE, quote = FALSE) |
