changeset 4:393957ecc97d draft

planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators commit b377ff767e3051f301c2f02cfe3e1a17b285ede4
author ecology
date Thu, 18 Jan 2024 09:34:02 +0000
parents 4e7c1fb5e894
children dc187fe78055
files macro.xml obisindicators.xml robis.r
diffstat 3 files changed, 66 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/macro.xml	Tue Feb 14 15:33:30 2023 +0000
+++ b/macro.xml	Thu Jan 18 09:34:02 2024 +0000
@@ -7,12 +7,11 @@
             <yield />
         </requirements>
     </xml>
-    <xml name="SRS_input">
+    <xml name="obis_input">
        <param name="input" type="data" format="tabular,csv,txt" label="Input table"/>
        <param name="colnames" type="boolean" label="First line is a header line" checked="true"/>
-       <param name="separator" type="text" label="What character is the separator in your data? (Mostlikely a comma for a csv file and t for a tabular)"/>
     </xml>
-    <xml name="SRS_bibref">
+    <xml name="obis_bibref">
        <citations>
             <citation type="bibtex">
             @Manual{,
@@ -25,6 +24,11 @@
             </citation>
         </citations>
     </xml>
+    <xml name="obis_doiref">
+        <citations>
+            <citation type="doi">DOI:10.5281/zenodo.6969395</citation>
+        </citations>
+    </xml>
     <xml name="topic">
         <edam_topics>
            <edam_topic>topic_0610</edam_topic>
--- a/obisindicators.xml	Tue Feb 14 15:33:30 2023 +0000
+++ b/obisindicators.xml	Thu Jan 18 09:34:02 2024 +0000
@@ -40,7 +40,7 @@
         ]]>
     </command>
     <inputs>
-        <expand macro="SRS_input"/>
+        <expand macro="obis_input"/>
         <param name="separator" type="select" display="radio" label="What character is the separator in your data? (Mostlikely a comma for a csv file and t for a tabular)">
             <option value="t">Tabulator (\t)</option>                 
             <option value=",">Comma (,)</option>  
@@ -132,5 +132,5 @@
 
 - Multiple PNG files representing the indicators on a map (according to the choice of map made).
     ]]></help>
-    <expand macro="SRS_bibref"/>
+    <expand macro="obis_bibref"/>
 </tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/robis.r	Thu Jan 18 09:34:02 2024 +0000
@@ -0,0 +1,57 @@
+#Rscript
+
+###########################################
+##     Retrieve Obis occurences data     ##
+###########################################
+
+##### Packages : robis
+# https://iobis.github.io/robis/articles/getting-started.html
+# Get args
+args <- commandArgs(trailingOnly = TRUE)
+
+if (length(args) < 1) {
+    stop("This tool needs at least 1 argument : longitude, latitude, species or taxonID")
+}else {
+    sname <- args[1]
+    taxid <- args[2]
+    lat_min <- args[3]
+    lat_max <- args[4]
+    long_min <- args[5]
+    long_max <- args[6]
+}
+
+if (lat_min == "0.0" & lat_max == "0.0" & long_min == "0.0" & long_max == "0.0") {
+lat_min <- ""
+lat_max <- ""
+long_min <- ""
+long_max <- ""
+}
+
+##### Import data
+# Get biological occurrences
+if (lat_min != "" & sname != "" & taxid != "") {
+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, "))"))
+}else if (lat_min != "" & sname != "" & taxid == "") {
+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, "))"))
+}else if (lat_min != "" & sname == "" & taxid != "") {
+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, "))"))
+}else if (lat_min != "" & sname == "" & taxid == "") {
+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, "))"))
+}else if (lat_min == "" & sname != "" & taxid != "") {
+my_occs <- robis::occurrence(scientificname = sname, taxonid = taxid)
+}else if (lat_min == "" & sname == "" & taxid != "") {
+my_occs <- robis::occurrence(taxonid = taxid)
+}else if (lat_min == "" & sname != "" & taxid == "") {
+my_occs <- robis::occurrence(scientificname = sname)
+}
+
+
+# Dispay results
+
+# If empty
+if(length(my_occs) == 0) {
+cat("\nNo occurrences found.\nLittle tip : Check your input typo, some databases are case sensitive : Genus species.\n")
+}
+
+
+write.table(file = "output.tab", my_occs, sep = "\t", dec = ".", na = "", row.names = FALSE, col.names = TRUE, quote = FALSE)