-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtaxa.js
49 lines (43 loc) · 1.41 KB
/
taxa.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const d3= require('d3-dsv');
const fs = require('fs');
const byScientific = {};
const treeSearch = {};
function init() {
// from https://biodiversity.org.au/nsl/services/export/index
const text = fs.readFileSync('APC-taxon-2020-02-20-5349.csv', 'utf-8');
const rows = d3.csvParse(text);
const includeTaxa = {
Species: true,
Subspecies: true,
Varietas: true,
Genus: true
}
for (const row of rows) {
if (row.taxonomicStatus === 'accepted' && row.nameType === 'scientific' && row.taxonRank in includeTaxa) {
byScientific[row.canonicalName] = row;
}
}
console.log(`${Object.keys(byScientific).length} taxa records kept out of ${rows.length}.`);
}
function loadTreeSearch() {
// from https://tools.bgci.org/global_tree_search.php
const text = fs.readFileSync('global_tree_search_trees_1_3.csv', 'utf-8');
const rows = d3.csvParse(text);
for (const row of rows) {
treeSearch[row['Taxon name']] = true;
}
console.log(`${Object.keys(treeSearch).length} rows loaded for Global Tree Search.`);
}
init();
loadTreeSearch();
module.exports = {
taxaForScientific(scientific) {
return byScientific[scientific];
},
hyphens() {
return Object.keys(byScientific).filter(k => k.indexOf('-') >= 0);
},
inGlobalTreeSearch(scientific) {
return treeSearch[scientific];
}
}