parse_csv_points
Created: 2013-12-24 11:41:36
Last updated: 2014-11-18 18:08:26
Parses csv content with species occurrence points.
Preview
Run
Run this Workflow in the Taverna Workbench...
Workflow Components
Authors (1)
Alan R Williams & Renato De Giovanni |
Titles (1)
Parse csv content with species occurrence points. |
Descriptions (1)
Parses the csv content, determining column indexes and returning the records as a list of points in openModeller format (XML). All points are considered presence points. |
Dependencies (0)
Inputs (1)
Name |
Description |
csv_content |
A list of strings. Each string is a list of points separated by newlines. Each point in the string is longitude,latitude
|
Processors (5)
Name |
Type |
Description |
parse_header |
beanshell |
Scriptimport java.io.StringReader;
import java.io.BufferedReader;
int name_idx = -1;
int id_idx = -1;
int long_idx = -1;
int lat_idx = -1;
BufferedReader reader = new BufferedReader(new StringReader(csv_content));
String header = reader.readLine();
if ( header != null) {
String[] parts = header.split(",");
List terms = Arrays.asList(parts);
name_idx = terms.indexOf("nameComplete");
id_idx = terms.indexOf("occurrenceID");
long_idx = terms.indexOf("decimalLongitude");
lat_idx = terms.indexOf("decimalLatitude");
}
else {
throw new RuntimeException("The input file provided for species occurrence points is empty.");
}
if ( name_idx == -1 ) {
throw new RuntimeException("The column nameComplete is missing from the header of the input points file.");
}
if ( long_idx == -1 ) {
throw new RuntimeException("The column decimalLongitude is missing from the header of the input points file.");
}
if ( lat_idx == -1 ) {
throw new RuntimeException("The column decimalLatitude is missing from the header of the input points file.");
}
|
extract_taxon_points |
beanshell |
Scriptimport java.io.StringReader;
import java.io.BufferedReader;
BufferedReader reader = new BufferedReader(new StringReader(csv_content));
StringBuilder builder = new StringBuilder();
int name_idx_int = Integer.parseInt(name_idx);
String eol = System.getProperty("line.separator");
int i = 0;
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
i++;
if (i == 1) {
continue;
}
if (taxon_name != void) {
String[] parts = line.split(",");
if (parts.length > name_idx_int) {
if (parts[name_idx_int].equals(taxon_name)) {
builder.append(line+eol);
}
}
}
else {
builder.append(line+eol);
}
}
String taxon_points = builder.toString(); |
get_first_taxon |
beanshell |
Scriptimport java.io.StringReader;
import java.io.BufferedReader;
String taxon_name = "";
int name_idx_int = Integer.parseInt(name_idx);
BufferedReader reader = new BufferedReader(new StringReader(csv_content));
String first_line = reader.readLine();
String second_line = reader.readLine();
if (second_line != null) {
if (name_idx_int >= 0) {
String[] parts = second_line.split(",");
if (parts.length > name_idx_int) {
taxon_name = parts[name_idx_int];
}
}
}
else {
throw new RuntimeException("The input file provided for species occurrence points has no other lines after the header.");
}
|
csv_to_xml_list |
beanshell |
Scriptimport java.io.StringReader;
import java.io.BufferedReader;
BufferedReader reader = new BufferedReader(new StringReader(csv_points));
int id_idx_int = Integer.parseInt(id_idx);
int long_idx_int = Integer.parseInt(long_idx);
int lat_idx_int = Integer.parseInt(lat_idx);
int max_idx = Math.max(id_idx_int, Math.max(long_idx_int, lat_idx_int));
String id;
int count = 0;
ArrayList all_points = new ArrayList();
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
count++;
String[] parts = line.split(",");
if (parts.length > max_idx) {
if (id_idx_int == -1) {
id = String.valueOf(count);
}
else {
id = parts[id_idx_int];
}
String point = "";
all_points.add(point);
}
}
num_points = all_points.size();
|
Merge_String_List_to_a_String |
localworker |
ScriptString seperatorString = "\n";
if (seperator != void) {
seperatorString = seperator;
}
StringBuffer sb = new StringBuffer();
for (Iterator i = stringlist.iterator(); i.hasNext();) {
String item = (String) i.next();
sb.append(item);
if (i.hasNext()) {
sb.append(seperatorString);
}
}
concatenated = sb.toString();
|
Beanshells (4)
Name |
Description |
Inputs |
Outputs |
parse_header |
|
csv_content
|
name_idx
id_idx
long_idx
lat_idx
|
extract_taxon_points |
|
csv_content
name_idx
taxon_name
|
taxon_points
|
get_first_taxon |
|
csv_content
name_idx
|
taxon_name
|
csv_to_xml_list |
|
csv_points
id_idx
long_idx
lat_idx
|
all_points
num_points
|
Outputs (6)
Name |
Description |
id_idx |
Index of the occurrenceID field in the header (starting with 0).
|
long_idx |
Index of the decimalLongitude field in the header (starting with 0).
|
lat_idx |
Index of the decimalLatitude field in the header (starting with 0).
|
first_taxon_name |
First taxon name found in the csv content.
|
all_points_xml |
List of all points (separated by new line) already in XML format for openModeller.
|
num_points |
Number of points.
|
Datalinks (16)
Source |
Sink |
csv_content |
parse_header:csv_content |
parse_header:name_idx |
extract_taxon_points:name_idx |
csv_content |
extract_taxon_points:csv_content |
csv_content |
get_first_taxon:csv_content |
parse_header:name_idx |
get_first_taxon:name_idx |
parse_header:id_idx |
csv_to_xml_list:id_idx |
parse_header:lat_idx |
csv_to_xml_list:lat_idx |
parse_header:long_idx |
csv_to_xml_list:long_idx |
extract_taxon_points:taxon_points |
csv_to_xml_list:csv_points |
csv_to_xml_list:all_points |
Merge_String_List_to_a_String:stringlist |
parse_header:id_idx |
id_idx |
parse_header:long_idx |
long_idx |
parse_header:lat_idx |
lat_idx |
get_first_taxon:taxon_name |
first_taxon_name |
Merge_String_List_to_a_String:concatenated |
all_points_xml |
csv_to_xml_list:num_points |
num_points |
Uploader
Component Validity
Loading
License
All versions of this Workflow are
licensed under:
Version 1 (earliest)
(of 4)
Credits (0)
(People/Groups)
None
Attributions (0)
(Workflows/Files)
None
Shared with Groups (1)
Featured In Packs (1)
Log in to add to one of your Packs
Attributed By (0)
(Workflows/Files)
None
Favourited By (0)
No one
Statistics
Other workflows that use similar services
(0)
There are no workflows in myExperiment that use similar services to this Workflow.
Comments (0)
No comments yet
Log in to make a comment