changeset 0:724ad06de5a5 draft

planemo upload for repository https://github.com/galaxyecology/tools-ecology/tools/spocc_occ commit e37f100e1c3ea68ade708868f9de3f4c0dd7e720
author ecology
date Thu, 23 May 2019 09:58:35 -0400
parents
children f9d76a46799a
files spocc_occ.R spocc_occ.xml test-data/canis-lupus_gbif_bison1.tab
diffstat 3 files changed, 282 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spocc_occ.R	Thu May 23 09:58:35 2019 -0400
@@ -0,0 +1,57 @@
+#!/usr/bin/Rscript
+
+library(spocc)
+
+
+##Def functions :
+help<-function(){
+    cat("HELP\n")
+    cat("Spocc::occ, Search on a single species name, or many. And search across a single or many data sources.\n\n")
+    cat("Need 3 args :\n")
+    cat("    - query : (character) One to many scientific names.\n")
+    cat("    - from : (character)  Data source to get data from, any combination of gbif, bison, inat,ebird, ecoengine and/or vertnet.\n")
+    cat("    - limit : (numeric) Number of records to return. This is passed across all sources.\n")
+    q("no")
+}
+
+formatSpName <- function(spName) paste(strsplit(spName, split=' ')[[1]], collapse='_') ###Wallace function
+
+####################################
+
+args = commandArgs(trailingOnly=TRUE)
+
+#Help display
+if(args[1]=="-h" || args[1]=="--help" || length(args)<3){help()}
+
+#Get args
+sname<-args[1]
+dbase_input<-args[2]
+max<-as.integer(args[3])
+
+#Get all databases
+bases<-strsplit(dbase_input,",")
+dbase<-c()
+for (base in bases){
+    dbase<-c(dbase,base)
+}
+
+#Get occurrences
+results <- spocc::occ(query=sname, from=dbase, limit=max, has_coords=TRUE)
+
+#Dispay results
+if(length(dbase)==1){
+    results_data <- results[[dbase[1]]]$data[[formatSpName(sname)]]
+}else{
+    res <- occ2df(results)
+    results_data <- res
+}
+
+results_data<-as.matrix(results_data)
+
+#If empty
+if(length(results_data)==0){cat("\nNo occurrences found.\nLittle tip : Check your input typo, some databases are case sensitive : Genus species.\n")}
+
+#Write them
+write.table(file="output.tab",results_data,sep="\t",row.names=FALSE)
+
+q('no')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spocc_occ.xml	Thu May 23 09:58:35 2019 -0400
@@ -0,0 +1,124 @@
+<tool id="spocc_occ" name="Get species occurrences data" version="0.9.0">
+    <description>from GBIF, ALA, iNAT and others</description>
+    <requirements>
+        <requirement type="package" version="0.9.0">r-spocc</requirement>
+    </requirements>
+    <command detect_errors="exit_code"><![CDATA[
+        Rscript '$__tool_directory__/spocc_occ.R' 
+            '$sname' 
+            '$from' 
+            $limit; 
+
+        #if $from=='gbif':
+            sed -z -i -e 's/\n  \"/ /g' -e 's/\n}/ /g' output.tab
+        #end if
+    ]]></command>
+    <inputs>
+        <param name="sname" type="text" label="Scientific name of the species" help="Genus species format, eg : Canis lupus"/>
+        <param name="from" type="select" multiple="true" label="Data source to get data from" help="Any combination of gbif, bison, inat, ebird, antweb, ala, idigbio, obis, ecoengine and/or vertnet" value="gbif,bison,inat">
+            <option value="gbif">Global Biodiversity Information Facility : GBIF</option>
+            <option value="bison">Biodiversity Information Serving Our Nation : BISON</option>
+            <option value="inat">INaturalist : INAT</option>
+            <option value="ebird">eBbird</option>
+            <option value="antweb">AntWeb</option>
+            <option value="ala">Atlas of Living Australia : ALA</option>
+            <option value="idigbio">Integrated Digitized Biocollections : iDigBio</option>
+            <option value="obis">Oceanic Biogeographic Information System : OBIS</option>
+            <option value="ecoengine">Berkeley Ecoinformatics Engine : EcoEngine</option>
+            <option value="vernet">VerNet</option>
+        </param>    
+        <param name="limit" type="integer" label="Number of records to return" help="This is passed across all sources" value="500"/>
+    </inputs>
+    <outputs>
+        <data name="output" format="tabular" from_work_dir="output.tab" label="Species occurences"/>
+    </outputs>
+    <tests>
+        <test> 
+            <param name="sname" value="Canis lupus"/>
+            <param name="from" value="gbif,bison"/>
+            <param name="limit" value="50"/>
+            <output name="output">
+                <assert_contents>
+                    <has_text text="name"/>
+                    <has_text text="Canis lupus"/>
+                    <has_n_columns n="6"/>
+                </assert_contents>
+            </output>
+        </test>
+    </tests>
+    <help><![CDATA[
+===========================
+Get species occurences data
+===========================      
+**What it does**
+
+Search species occurences across a single or many data sources.
+
+|
+
+**How to use it**
+
+Enter a species scientific name, be careful that the tool is case sensitive. Eg : Canis lupus.
+
+Select one or more data source. It can be any combination of gbif, bison, inat, ebird, antweb, ala, idigbio, obis, ecoengine and/or vertnet.
+
+|
+
+**Output**
+
+The tool returns a table with the species observations available in the chosen databases.
+
+Output file will have the following attributes : name, longituden latitude, prov, data, key.
+
+prov is the datasouce and key the occurence corresponding unique identifier.
+
+|
+
+**How it works**
+
+This tool use the spocc R package (Spocc::occ) :
+
+A programmatic interface to many species occurrence data sources, including :
+
+  - Global Biodiversity Information Facility : GBIF
+    https://www.gbif.org/
+
+  - USGSs' Biodiversity Information Serving Our Nation : BISON
+    https://bison.usgs.gov/#home
+    
+  - iNaturalist : iNat
+    https://www.inaturalist.org/,
+
+  - eBird
+    https://ebird.org/home
+
+  - Berkeley Ecoinformatics Engine : EcoEngine
+    https://ecoengine.berkeley.edu/
+
+  - AntWeb
+    https://www.antweb.org/
+
+  - Integrated Digitized Biocollections : iDigBio
+    https://www.idigbio.org/
+
+  - VertNet
+    http://vertnet.org/
+
+  - Ocean Biogeographic Information System : OBIS 
+    https://obis.org/
+
+  - Atlas of Living Australia : ALA
+    https://www.ala.org.au/. 
+
+
+Includes functionality for retrieving species occurrence data, and combining those data.
+
+|
+
+**Sources**
+
+Original source : https://cran.r-project.org/web/packages/spocc/index.html
+
+Reference manual : https://cran.r-project.org/web/packages/spocc/spocc.pdf
+    ]]></help>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/canis-lupus_gbif_bison1.tab	Thu May 23 09:58:35 2019 -0400
@@ -0,0 +1,101 @@
+"name"	"longitude"	"latitude"	"prov"	"date"	"key"
+"Canis lupus Linnaeus, 1758"	"  12.163912"	" 60.28862"	"gbif"	"2019-01-18"	"1988307594"
+"Canis familiaris Linnaeus, 1758"	" 100.405060"	" 14.78179"	"gbif"	"2019-01-21"	"2005338796"
+"Canis lupus Linnaeus, 1758"	"  11.048093"	" 59.48167"	"gbif"	"2019-01-23"	"2012823436"
+"Canis lupus Linnaeus, 1758"	"  28.973364"	" 69.23767"	"gbif"	"2019-01-16"	"2028051051"
+"Canis lupus dingo Meyer, 1793"	" 145.545322"	"-16.27793"	"gbif"	"2019-01-19"	"1990575442"
+"Canis familiaris Linnaeus, 1758"	" -78.833777"	" 36.05233"	"gbif"	"2019-01-24"	"1990576477"
+"Canis lupus Linnaeus, 1758"	"  11.159160"	" 59.72548"	"gbif"	"2019-01-27"	"1990656034"
+"Canis familiaris Linnaeus, 1758"	"  74.792893"	" 13.35156"	"gbif"	"2019-01-07"	"1986608286"
+"Canis lupus Linnaeus, 1758"	"  11.000690"	" 59.53739"	"gbif"	"2019-01-19"	"1988307939"
+"Canis familiaris Linnaeus, 1758"	"-117.216541"	" 33.98280"	"gbif"	"2019-01-20"	"2005276886"
+"Canis familiaris Linnaeus, 1758"	" -97.673194"	" 28.42286"	"gbif"	"2019-01-23"	"1990570437"
+"Canis lupus Linnaeus, 1758"	"  11.047684"	" 59.48154"	"gbif"	"2019-01-23"	"2006001212"
+"Canis lupus lycaon Schreber, 1775"	" -78.401972"	" 45.57230"	"gbif"	"2019-01-02"	"1986610881"
+"Canis familiaris Linnaeus, 1758"	"-101.629497"	" 37.12117"	"gbif"	"2019-01-10"	"1990470069"
+"Canis lupus Linnaeus, 1758"	"   9.030524"	" 44.74131"	"gbif"	"2019-01-12"	"1990488501"
+"Canis lupus Linnaeus, 1758"	" -93.110484"	" 45.40214"	"gbif"	"2019-01-17"	"1993718245"
+"Canis lupus Linnaeus, 1758"	"  12.003221"	" 61.36278"	"gbif"	"2019-01-01"	"2028051584"
+"Canis familiaris Linnaeus, 1758"	"-121.098885"	" 37.08132"	"gbif"	"2019-01-28"	"1993725010"
+"Canis lupus Linnaeus, 1758"	"   7.619356"	" 45.69360"	"gbif"	"2019-01-03"	"2236240391"
+"Canis familiaris Linnaeus, 1758"	"   8.252381"	" 51.48241"	"gbif"	"2019-01-21"	"1989765540"
+"Canis lupus Linnaeus, 1758"	"   7.030619"	" 45.16022"	"gbif"	"2019-01-04"	"1986578666"
+"Canis lupus Linnaeus, 1758"	"  11.771043"	" 60.79850"	"gbif"	"2019-01-27"	"1989766089"
+"Canis lupus Linnaeus, 1758"	"  11.009331"	" 59.86555"	"gbif"	"2019-01-21"	"1989766220"
+"Canis lupus Linnaeus, 1758"	"  11.024379"	" 59.71250"	"gbif"	"2019-01-17"	"1988308206"
+"Canis lupus Linnaeus, 1758"	"  11.683887"	" 59.69185"	"gbif"	"2019-01-23"	"1989766131"
+"Canis lupus Linnaeus, 1758"	" -93.337121"	" 45.51879"	"gbif"	"2019-01-26"	"1990625756"
+"Canis lupus Linnaeus, 1758"	"  10.340948"	" 63.10199"	"gbif"	"2019-01-19"	"2028054300"
+"Canis familiaris Linnaeus, 1758"	" -85.648400"	" 32.44466"	"gbif"	"2019-01-22"	"1993716904"
+"Canis lupus Linnaeus, 1758"	"  10.920536"	" 59.58577"	"gbif"	"2019-01-10"	"1988308000"
+"Canis familiaris Linnaeus, 1758"	" -85.646839"	" 32.44423"	"gbif"	"2019-01-22"	"2237420714"
+"Canis lupus Linnaeus, 1758"	"  10.994740"	" 59.85693"	"gbif"	"2019-01-22"	"1989766129"
+"Canis lupus Linnaeus, 1758"	"-113.686295"	" 47.46992"	"gbif"	"2019-01-26"	"1993733922"
+"Canis lupus Linnaeus, 1758"	"  11.329828"	" 59.55214"	"gbif"	"2019-01-10"	"1988307663"
+"Canis lupus Linnaeus, 1758"	"  12.037582"	" 61.38100"	"gbif"	"2019-01-01"	"2028051614"
+"Canis familiaris Linnaeus, 1758"	"   6.627318"	" 50.70491"	"gbif"	"2019-01-03"	"1984208185"
+"Canis familiaris Linnaeus, 1758"	" 120.602292"	" 23.99870"	"gbif"	"2019-01-24"	"1990574963"
+"Canis familiaris Linnaeus, 1758"	"  47.806338"	" 30.47966"	"gbif"	"2019-01-07"	"2005345445"
+"Canis familiaris Linnaeus, 1758"	"  11.450637"	" 48.38851"	"gbif"	"2019-01-31"	"1990656210"
+"Canis familiaris Linnaeus, 1758"	"   8.352727"	" 49.68351"	"gbif"	"2019-01-12"	"1988294116"
+"Canis lupus Linnaeus, 1758"	"  28.852713"	" 69.22144"	"gbif"	"2019-01-05"	"2028042974"
+"Canis lupus Linnaeus, 1758"	"  10.920496"	" 59.58575"	"gbif"	"2019-01-10"	"1988307998"
+"Canis lupus Linnaeus, 1758"	"  11.770231"	" 60.79854"	"gbif"	"2019-01-27"	"1989766090"
+"Canis familiaris Linnaeus, 1758"	" -17.776737"	" 28.61137"	"gbif"	"2019-01-08"	"1988294122"
+"Canis lupus lycaon Schreber, 1775"	" -78.465376"	" 45.54244"	"gbif"	"2019-01-20"	"1990552381"
+"Canis familiaris Linnaeus, 1758"	"  10.297331"	" 48.93172"	"gbif"	"2019-01-06"	"1984208101"
+"Canis familiaris Linnaeus, 1758"	"   8.499363"	" 49.45227"	"gbif"	"2019-01-01"	"1984208113"
+"Canis familiaris Linnaeus, 1758"	"-101.629348"	" 37.12143"	"gbif"	"2019-01-10"	"1986628708"
+"Canis lupus baileyi Nelson & Goldman, 1929"	" -85.149113"	" 42.24575"	"gbif"	"2019-01-17"	"1989894063"
+"Canis lupus Linnaeus, 1758"	"  11.080055"	" 59.72776"	"gbif"	"2019-01-23"	"1989766095"
+"Canis familiaris Linnaeus, 1758"	" 108.263023"	" 16.00398"	"gbif"	"2019-01-22"	"1990559572"
+"Canis lupus"	" -94.218414"	" 35.97121"	"bison"	"1957-01-01"	"919969407"
+"Canis lupus"	" -92.678590"	" 36.26666"	"bison"	"1972-01-09"	"919969412"
+"Canis lupus"	" -92.140495"	" 35.85699"	"bison"	"1970-01-01"	"919969420"
+"Canis lupus"	" -94.274990"	" 35.19698"	"bison"	NA	"919969655"
+"Canis lupus"	" -94.274990"	" 35.19698"	"bison"	"1970-01-01"	"919969656"
+"Canis lupus"	" -92.689250"	" 35.26570"	"bison"	"1970-07-06"	"919969664"
+"Canis lupus"	" -90.779290"	" 34.77975"	"bison"	"1970-07-21"	"919969665"
+"Canis lupus"	" -94.218414"	" 35.97121"	"bison"	"1970-01-01"	"919969666"
+"Canis lupus"	" -93.031530"	" 35.45530"	"bison"	"1968-08-15"	"919969671"
+"Canis lupus"	" -94.256190"	" 36.33783"	"bison"	"1968-10-16"	"919969689"
+"Canis lupus"	" -94.274990"	" 35.19698"	"bison"	NA	"919969690"
+"Canis lupus"	" -92.140495"	" 35.85699"	"bison"	"1970-01-01"	"919969694"
+"Canis lupus"	" -91.722780"	" 33.58724"	"bison"	"1970-04-06"	"919969702"
+"Canis lupus"	" -93.408300"	" 34.99771"	"bison"	"1970-06-15"	"919969708"
+"Canis lupus"	" -95.393036"	" 29.85727"	"bison"	NA	"919969805"
+"Canis lupus"	" -94.218414"	" 35.97121"	"bison"	"1972-01-01"	"919969833"
+"Canis lupus"	" -94.218414"	" 35.97121"	"bison"	"1949-11-11"	"919969859"
+"Canis lupus"	" -92.140495"	" 35.85699"	"bison"	"1936-04-01"	"919969875"
+"Canis lupus"	" -93.720566"	" 35.21855"	"bison"	"1950-11-29"	"919969879"
+"Canis lupus"	" -94.218414"	" 35.97121"	"bison"	"1949-12-19"	"919969896"
+"Canis lupus"	" -91.203316"	" 34.67951"	"bison"	"1970-03-18"	"919969918"
+"Canis lupus"	" -91.101150"	" 36.04110"	"bison"	"1951-07-20"	"919969956"
+"Canis lupus"	" -94.766080"	" 34.11707"	"bison"	"1936-03-24"	"919970090"
+"Canis lupus"	" -94.766080"	" 34.11707"	"bison"	"1936-07-04"	"919970107"
+"Canis lupus"	NA	NA	"bison"	NA	"919970259"
+"Canis lupus"	" -93.720566"	" 35.21855"	"bison"	"1975-12-15"	"919970279"
+"Canis lupus"	NA	NA	"bison"	NA	"919970291"
+"Canis lupus"	" -94.808205"	" 36.39337"	"bison"	"1988-12-14"	"919972484"
+"Canis lupus"	" -94.808205"	" 36.39337"	"bison"	NA	"919972528"
+"Canis lupus"	" -94.256190"	" 36.33783"	"bison"	"1988-02-19"	"919972597"
+"Canis lupus"	" -92.515976"	" 35.58296"	"bison"	"1969-06-06"	"919973097"
+"Canis lupus"	" -91.280140"	" 47.35155"	"bison"	"2017-11-02"	"1806350848"
+"Canis lupus"	" -95.261180"	" 47.35066"	"bison"	"2018-01-19"	"1806334455"
+"Canis lupus"	"-125.546340"	" 48.94160"	"bison"	"2017-05-19"	"1562977820"
+"Canis lupus"	"-110.392006"	" 44.52775"	"bison"	"2011-07-15"	"1848809578"
+"Canis lupus"	"-110.191980"	" 44.93100"	"bison"	"2012-07-21"	"1848805186"
+"Canis lupus"	" -78.560486"	" 45.56983"	"bison"	"2000-07-19"	"920908694"
+"Canis lupus"	" -78.560486"	" 45.56983"	"bison"	"2000-07-20"	"920921836"
+"Canis lupus"	" -94.137210"	" 58.69291"	"bison"	"2010-06-07"	"920989000"
+"Canis lupus"	"-130.648040"	" 60.09208"	"bison"	"1967-06-01"	"876159279"
+"Canis lupus"	" -96.000000"	" 42.00000"	"bison"	NA	"36231929"
+"Canis lupus"	"-103.900000"	" 50.80000"	"bison"	NA	"36231931"
+"Canis lupus"	" -84.830000"	" 34.15000"	"bison"	NA	"36232359"
+"Canis lupus"	"-145.532780"	" 62.91389"	"bison"	"1968-12-01"	"202062196"
+"Canis lupus"	"-114.295815"	" 48.24529"	"bison"	"2000-09-03"	"1147030583"
+"Canis lupus"	" -76.473480"	" 42.45300"	"bison"	"1975-05-11"	"1147032515"
+"Canis lupus"	"-114.295815"	" 48.24529"	"bison"	"2000-09-03"	"1147034599"
+"Canis lupus"	"-114.295815"	" 48.24529"	"bison"	"2000-09-03"	"1147040577"
+"Canis lupus"	" -76.473480"	" 42.45300"	"bison"	"1975-05-09"	"1147041973"
+"Canis lupus"	" -76.473480"	" 42.45300"	"bison"	"1975-03-12"	"1147042200"