Skip to content

Commit

Permalink
Updates to name assignment, commenting
Browse files Browse the repository at this point in the history
  • Loading branch information
amb26 committed Oct 30, 2023
1 parent f98735b commit 3a6af09
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
31 changes: 21 additions & 10 deletions src/assignNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ fluid.setLogging(true);

const parsedArgs = minimist(process.argv.slice(2));

const outputFile = parsedArgs.o || "assigned.csv";
// fluid.module.resolvePath("%imerss-bioinfo/data/Comprehensive Lists/San_Juan_Dunwiddie_List.csv");
// fluid.module.resolvePath("%imerss-bioinfo/data/Galiano 2022/Tracheophyta_review_summary_reviewed_2022-10-29.csv")
// fluid.module.resolvePath("%imerss-bioinfo/data/Squamish/Tracheophyta_review_summary_2022-12-14.csv")
Expand All @@ -31,6 +30,13 @@ const reader = hortis.csvReaderWithoutMap({
inputFile: inputFile
});

hortis.assignedFromInput = function (inputFile) {
const lastDotPos = inputFile.lastIndexOf(".");
return inputFile.substring(0, lastDotPos) + "-assigned" + inputFile.substring(lastDotPos);
};

const outputFile = parsedArgs.o || hortis.assignedFromInput(inputFile);

const source = hortis.iNatTaxonSource();

hortis.highRanks = ["kingdom", "phylum", "subphylum", "superclass", "class", "subclass", "superorder", "order",
Expand Down Expand Up @@ -63,7 +69,7 @@ hortis.queryFromGBIFRow = function (row) {
const frontRank = rawRank.substring(rawRank.indexOf(" ") + 1);
const rank = hortis.capitalize(frontRank);
return {name, rank};
}
};

hortis.obsIdFromSummaryRow2022 = function (row) {
const obsLink = row["iNaturalist Link"];
Expand All @@ -86,8 +92,8 @@ hortis.obsIdFromSummaryRow2023 = function (row) {
// One-off script to update taxonomies and iNaturalist ids from files produced in Andrew's 2022 run of Galiano data

hortis.applyName = async function (row) {
//const query = hortis.queryFromSummaryRow2023(row);
const query = hortis.queryFromGBIFRow(row);
const query = hortis.queryFromSummaryRow2023(row);
//const query = hortis.queryFromGBIFRow(row);
const looked = await source.get(query);
// console.log("Got document ", looked);
if (looked && looked.doc) {
Expand All @@ -114,10 +120,15 @@ hortis.applyName = async function (row) {
if (obsId) {
row["Observation Taxon Name"] = "error";
if (+obsId > 0) {
const obs = await source.get({obsId: obsId});
if (obs.doc.results.length === 1) {
const name = obs.doc.results[0].taxon.name;
row["Observation Taxon Name"] = name;
try {
const obs = await source.get({obsId: obsId});
if (obs.doc.results.length === 1) {
const name = obs.doc.results[0].taxon.name;
row["Observation Taxon Name"] = name;
}
}
catch (e) {
console.log(`Got error for obsId ${obsId}`, e);
}
}
}
Expand All @@ -141,14 +152,14 @@ Promise.all([reader.completionPromise, source.events.onCreate]).then(async funct
const row = reader.rows[i];
await hortis.applyName(row);
// TODO: produce mapping functions for these older forms of data
/*
/*
if (row.infraTaxonName) {
await hortis.applyName(row, row.infraTaxonName);
}
if (!row.infraTaxonName || row["Name Status"] === "unknown") {
await hortis.applyName(row, hortis.unscrewGBIFName(row.scientificName)); // taxonName for Dunwiddie data, scientificName for DwC
}
*/
*/
mapped.push(row);
}
hortis.writeCSV(fluid.module.resolvePath(outputFile), Object.keys(mapped[0]), mapped, fluid.promise());
Expand Down
28 changes: 14 additions & 14 deletions src/materialise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

"use strict";

var fluid = require("infusion");
var glob = require("glob");
var kettle = require("kettle");
var fs = require("fs");
const fluid = require("infusion");
const glob = require("glob");
const kettle = require("kettle");
const fs = require("fs");
fluid.require("%imerss-bioinfo");

var baseDir = fluid.module.resolvePath("%imerss-bioinfo/data/dataPaper-I-in/Animalia/");
const baseDir = fluid.module.resolvePath("%imerss-bioinfo/data/dataPaper-I-in/Animalia/");

fs.mkdirSync(baseDir, {
recursive: true
});

// Used during preparation of data paper to materialise an entire folder full of Google Sheets as CSV.
// Will need to updated to use Google Sheets API directrly and not rely on a Google Drive mapping
// Will need to updated to use Google Sheets API directly and not rely on a Google Drive mapping

var dir = process.argv[2] || "e:/data/Google Drive/Galiano Data Paper 2021/Marine Life/Animalia";
var source = kettle.dataSource.URL({
const dir = process.argv[2] || "e:/data/Google Drive/Galiano Data Paper 2021/Marine Life/Animalia";
const source = kettle.dataSource.URL({
url: "https://docs.google.com/spreadsheets/d/%id/export?format=csv&id=%id&gid=0",
port: 443,
termMap: {
Expand All @@ -35,19 +35,19 @@ var source = kettle.dataSource.URL({
}
});

var getSegment = function (path) {
var lastSlash = path.lastIndexOf("/");
var lastDot = path.lastIndexOf(".");
const getSegment = function (path) {
const lastSlash = path.lastIndexOf("/");
const lastDot = path.lastIndexOf(".");
return path.substring(lastSlash + 1, lastDot);
};

fluid.setLogging(true);

glob(dir + "/*.gsheet", function (er, files) {
console.log("Got files ", files);
var records = files.map(function (oneFile) {
var promise = kettle.JSON.readFileSync(oneFile);
var parsed;
const records = files.map(function (oneFile) {
const promise = kettle.JSON.readFileSync(oneFile);
let parsed;
promise.then(function (result) {
parsed = result;
});
Expand Down
3 changes: 3 additions & 0 deletions src/reintegrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var swaps = hortis.readJSONSync("data/taxon-swaps.json5", "reading taxon swaps f

// Long disused script to output a taxon-swaps JSON5 file given a CSV taxon resolution file

// 24/10/23 - Interesting - forgot that swaps used to be accepted in CSV - which we think we plan to do
// again. Did AS ever generate these?

hortis.copyCSVProps = function (props, target, source) {
props.forEach(function (prop) {
if (fluid.isValue(source[prop]) && source[prop] !== "") {
Expand Down

0 comments on commit 3a6af09

Please sign in to comment.