-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from Marie59/obisindicators
Add retrieving occurences data from obis
- Loading branch information
Showing
5 changed files
with
165 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |