changeset 0:8852afebb8f6 draft

Uploaded
author mnhn65mo
date Thu, 02 Aug 2018 04:33:51 -0400
parents
children 064d2c2649dc
files spocc_occ.R spocc_occ_notaxref.xml
diffstat 2 files changed, 118 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spocc_occ.R	Thu Aug 02 04:33:51 2018 -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_notaxref.xml	Thu Aug 02 04:33:51 2018 -0400
@@ -0,0 +1,61 @@
+<tool id="spocc_occ_no_taxrefv2" name="Get species occurrences data" version="0.2">
+    <description>from GBIF, ALA, iNAT and others</description>
+    <requirements>
+<!--
+        <requirement type="package" version="1.2.3">r-stringi</requirement>
+        <requirement type="package" version="7.0">readline</requirement>
+-->
+        <requirement type="package" version="0.8.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" value="Genus species"/>
+        <param name="from" type="text" label="Data source to get data from, any combination of gbif, bison, inat, ebird, antweb, ala, idigbio, obis, ecoengine and/or vertnet" value="gbif,bison,inat"/>
+        <param name="limit" type="integer" label="Number of records to return. This is passed across all sources" value="500"/>
+    </inputs>
+    <outputs>
+        <data name="output" format="tabular" from_work_dir="output.tab" label="Species occurences"/>
+    </outputs>
+
+<!-- Warning old test -->
+    <tests>
+        <test> 
+            <param name="sname" value="Canis lupus"/>
+            <param name="from" value="gbif,bison"/>
+            <param name="limit" value="50"/>
+            <param name="taxref_choice" value="do_link_taxref"/>
+            <output name="output" file="canis-lupus_gbif_bison.tab" ftype="tabular"/>
+            <output name="output_taxref" file="res_taxref_grep.tab" ftype="tabular"/>
+        </test>
+    </tests>
+
+    <help><![CDATA[
+==========
+Spocc::occ
+==========       
+**What id does**
+
+Search on a single species name, or many. And search across a single or many data sources.
+
+|
+
+**How it works**
+
+This tool use the spocc R package :
+
+A programmatic interface to many species occurrence data sources, including Global Biodiversity Information Facility ('GBIF'), 'USGSs' Biodiversity Information Serving Our Nation ('BISON'), 'iNaturalist', Berkeley 'Ecoinformatics' Engine, 'AntWeb', Integrated Digitized 'Biocollections' ('iDigBio'), 'VertNet', Ocean 'Biogeographic' Information System ('OBIS'), and Atlas of Living Australia ('ALA'). Includes functionality for retrieving species occurrence data, and combining those data.
+
+|
+
+Original source here : https://cran.r-project.org/web/packages/spocc/index.html
+
+    ]]></help>
+</tool>