Skip to content

Commit

Permalink
Merge pull request #90 from Marie59/obisindicators
Browse files Browse the repository at this point in the history
Add retrieving occurences data from obis
  • Loading branch information
bgruening authored Jan 18, 2024
2 parents 236f364 + 37ef204 commit b377ff7
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 5 deletions.
1 change: 1 addition & 0 deletions tools/obisindicators/.shed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ categories:
- Ecology
owner: ecology
remote_repository_url: https://github.com/galaxyecology/tools-ecology/tree/master/tools/obisindicators
homepage_url: https://github.com/Marie59/obisindicators
long_description: |
Compute biodiveristy indicators for marine data from obis
type: unrestricted
Expand Down
10 changes: 7 additions & 3 deletions tools/obisindicators/macro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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{,
Expand All @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions tools/obisindicators/obisindicators.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -132,5 +132,5 @@ A tabular file with observation data. Must at least contain four columns longitu
- 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>
57 changes: 57 additions & 0 deletions tools/obisindicators/robis.r
Original file line number Diff line number Diff line change
@@ -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)
98 changes: 98 additions & 0 deletions tools/obisindicators/robis.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<tool id="obis_data" name="OBIS occurences" version="@VERSION@" profile="20.01">
<description>retrieve data</description>
<macros>
<import>macro.xml</import>
</macros>
<expand macro="topic"/>
<expand macro="requirements">
<requirement type="package" version="2.11.3">r-robis</requirement>
</expand>
<required_files>
<include type="literal" path="robis.r"/>
</required_files>
<command detect_errors="exit_code"><![CDATA[
Rscript
'$__tool_directory__/robis.r'
'$species'
'$taxon'
'$lat_min'
'$lat_max'
'$long_min'
'$long_max'
'$output'
]]>
</command>
<inputs>
<param name="species" type="text" label="Scientific name of the species" help="Genus species format, eg : Scomber scombrus">
<validator type="regex">^[A-Za-z ]*$</validator>
</param>
<param name="taxon" type="text" label="Taxon ID">
<validator type="regex">^[0-9]*$</validator>
</param>
<param name="lat_min" type="float" min="-90" max="90" value="0" label="Input latitude min (+north/-south):" optional="true"/>
<param name="lat_max" type="float" min="-90" max="90" value="0" label="Input latitude max (+north/-south):" optional="true"/>
<param name="long_min" type="float" min="-90" max="90" value="0" label="Input longitude min (+east/-west):" optional="true"/>
<param name="long_max" type="float" min="-90" max="90" value="0" label="Input longitude max (+east/-west):" optional="true"/>
</inputs>
<outputs>
<data name="output" format="tabular" from_work_dir="output.tab" label="Species occurences"/>
</outputs>
<tests>
<test expect_num_outputs="1">
<param name="species" value="Scomber scombrus"/>
<output name="output">
<assert_contents>
<has_text text="Scombridae"/>
<has_n_columns n="163"/>
</assert_contents>
</output>
</test>
<test expect_num_outputs="1">
<param name="lat_min" value="6"/>
<param name="lat_max" value="12"/>
<param name="long_min" value="40"/>
<param name="long_max" value="43"/>
<output name="output">
<assert_contents>
<has_text text="basisOfRecord"/>
<has_n_columns n="144"/>
</assert_contents>
</output>
</test>
</tests>
<help><![CDATA[
===========================
Get species occurences data
===========================
**What it does**
Search and retrieve species occurences across OBIS database.
|
**How to use it**
Enter a species scientific name, be careful that the tool is case sensitive. Eg : Scomber scombrus.
Or enter the latitude longitude of the area you want to retrieve data from.
|
**Output**
The tool returns a table with the species observations available in OBIS database.
Output file will have at least the following attributes : BasisOfRecords, longitude, latitude, species, individualcount.
|
**How it works**
This tool use the robis R package.
Includes functionality for retrieving species occurrence data, and combining those data.
]]></help>
<expand macro="obis_doiref"/>
</tool>

0 comments on commit b377ff7

Please sign in to comment.