This repository was archived by the owner on Sep 24, 2024. It is now read-only.
forked from ezwelty/opentrees-harvester
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcol.js
More file actions
63 lines (59 loc) · 1.95 KB
/
col.js
File metadata and controls
63 lines (59 loc) · 1.95 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Load Catalogue of Life taxa.
*
* @module
* @private
*/
const Source = require('./source')
const helpers = require('./helpers')
const names = require('./names')
const PROPERTIES = {
id: 'taxa',
// Catalogue of Life: Tracheophyta (vascular plants)
download: 'http://www.catalogueoflife.org/DCA_Export/zip/archive-kingdom-plantae-phylum-tracheophyta-bl2.zip',
// HACK: Rename *.txt to *.tsv for GDAL
execute: `mv taxa.txt taxa.tsv`,
filename: 'taxa.tsv',
// Keep only genus, species, and infraspecies rank
delFunc: x => !(new Set(['genus', 'species', 'infraspecies']).has(x['taxonRank'])),
crosswalk: {
id: 'taxonID',
// parentId: 'parentNameUsageID',
// acceptedId: 'acceptedNameUsageID',
// accepted name, ambiguous synonym, misapplied name, provisionally accepted name, synonym
status: 'taxonomicStatus',
genus: x => x['genericName'].replace('ö', 'o'),
species: x => x['specificEpithet'].replace('ë', 'e'),
infraspecies: x => x['infraspecificEpithet'].replace(' ', '-').replace('×', ''),
// subsp., var., f., ...
infraspeciesRank: 'verbatimTaxonRank',
}
}
const INPUT = 'taxa/input'
const OUTPUT = 'taxa/output/taxa.csv'
async function loadTaxa() {
const source = new Source(PROPERTIES, INPUT)
await source.get()
source.process(OUTPUT, { creation: [], allowEmptyGeometry: true })
let taxa = await helpers.readCSV(OUTPUT)
taxa.forEach(t => {
if (t.infraspecies) {
t.infraspecies = [{ epithet: t.infraspecies }]
if (t.infraspeciesRank) {
t.infraspecies.rank = t.infraspeciesRank
}
} else {
delete t.infraspecies
}
delete t.infraspeciesRank
})
// Remove taxa with same name as an accepted name
const accepted = new Set(taxa.filter(t => t.status === 'accepted name').
map(names.printScientificName))
return taxa.filter(t => {
return (t.status === 'accepted name') || !accepted.has(names.printScientificName(t))
})
}
module.exports = {
loadTaxa
}