Commit 05c4aaf8 authored by Matija Obreza's avatar Matija Obreza
Browse files

Added --no-current flag to ignore the bit of code for obsolete names (fixes #22)

parent 9eaf4d18
......@@ -93,6 +93,7 @@ public class GGTC {
String outputName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
boolean toCurrentTaxa = false;
if (args.length == 0) {
printHelp();
......@@ -108,6 +109,10 @@ public class GGTC {
logger.setLevel(nextLevel(logger.getLevel()));
LOG.info("Increasing loglevel to {}", logger.getLevel());
} else if ("--to-current".equals(arg)) {
LOG.info("Will include CURRENT names");
toCurrentTaxa = true;
} else if ("-csv".equals(arg)) {
char[] csv = args[++i].toCharArray();
LOG.info("Setting CSV chars to {}", csv);
......@@ -165,7 +170,7 @@ public class GGTC {
LOG.info("Loading databases");
ggtc.readDatabase("taxonomy_data");
ggtc.run(inputStream, outputStream);
ggtc.run(inputStream, outputStream, toCurrentTaxa);
} catch (Throwable e) {
LOG.error(e.getMessage(), e);
......@@ -192,6 +197,7 @@ public class GGTC {
System.out.println("\nOptions:");
System.out.println("<inputFile> File name or - to read CSV from STDIN");
System.out.println("<outputFile> File name or - to write CSV to STDOUT");
System.out.println("--to-current Print current values for replaced names");
System.out.println("-v Increase log level.");
System.out.println("-v Increase log level.");
System.out.println("-csv ',\"\\' Set input CSV separator, quote and escape chars");
......@@ -220,7 +226,7 @@ public class GGTC {
}
}
private void run(InputStream inputStream, OutputStream outputStream) throws UnsupportedEncodingException, FileNotFoundException, IOException {
private void run(InputStream inputStream, OutputStream outputStream, boolean toCurrentTaxa) throws UnsupportedEncodingException, FileNotFoundException, IOException {
taxonomyChecker.setTaxonomyDatabase(taxonomyDatabase);
LOG.info("Running the validation against {}", taxonomyDatabase);
......@@ -334,7 +340,8 @@ public class GGTC {
String subtAuthor = sourceMapping.get(HEADER_SUBTAUTHOR) == null ? null : sourceLine[sourceMapping.get(HEADER_SUBTAUTHOR)];
if (outputHeaders.indexOf(HEADER_GENUS_CHECK) >= 0) {
String genus_check = taxonomyChecker.suggestGenus(genus, 5).stream().reduce(null, (prev, suggestion) -> prev == null ? suggestion : prev + ";" + suggestion);
String genus_check = taxonomyChecker.suggestGenus(genus, 5).stream().reduce(null,
(prev, suggestion) -> prev == null ? suggestion : prev + ";" + suggestion);
if (LOG.isTraceEnabled())
LOG.trace("GENUS_check: {}", StringUtils.defaultIfBlank(genus_check, "NULL"));
......@@ -343,7 +350,8 @@ public class GGTC {
}
if (outputHeaders.indexOf(HEADER_SPECIES_CHECK) >= 0) {
String species_check = taxonomyChecker.suggestSpecies(genus, species, 5).stream().reduce(null, (prev, suggestion) -> prev == null ? suggestion : prev + ";" + suggestion);
String species_check = taxonomyChecker.suggestSpecies(genus, species, 5).stream().reduce(null,
(prev, suggestion) -> prev == null ? suggestion : prev + ";" + suggestion);
if (LOG.isTraceEnabled())
LOG.trace("SPECIES_check: {}", StringUtils.defaultIfBlank(species_check, "NULL"));
......@@ -398,19 +406,19 @@ public class GGTC {
SpeciesRow speciesRow = speciesRows.get(0);
outputLine[outputHeaders.indexOf(HEADER_GRINTAX_SPECIESID)] = speciesRow.getSpeciesId().toString();
outputLine[outputHeaders.indexOf(HEADER_GRINTAX_SPECIESCURRENT)] = Boolean.toString(speciesRow.isCurrent());
if (!speciesRow.isCurrent()) {
if (!speciesRow.isCurrent() && toCurrentTaxa) {
LOG.debug("{} is not current", speciesRow);
SpeciesRow currentSpecies = taxonomyDatabase.getSpeciesRow(speciesRow.getCurrentSpeciesId());
String currentGenus = taxonomyDatabase.getGenus(currentSpecies.getGenusId());
// LOG.warn("Result: {}", Arrays.toString(outputLine));
updateOutputColumn(outputLine, outputHeaders.indexOf(HEADER_GENUS_CHECK), currentGenus, genus, CURRENT_SUFFIX);
updateOutputColumn(outputLine, outputHeaders.indexOf(HEADER_SPECIES_CHECK), currentSpecies.getSpeciesName(), species, CURRENT_SUFFIX);
updateOutputColumn(outputLine, outputHeaders.indexOf(HEADER_SPAUTHOR_CHECK), StringUtils.defaultIfBlank(currentSpecies.getSpeciesAuthority(), SUGGESTION_BLANK),
spAuthor, CURRENT_SUFFIX);
updateOutputColumn(outputLine, outputHeaders.indexOf(HEADER_SUBTAXA_CHECK), StringUtils.defaultIfBlank(currentSpecies.getSubtaxa(), SUGGESTION_BLANK), subtaxa,
CURRENT_SUFFIX);
updateOutputColumn(outputLine, outputHeaders.indexOf(HEADER_SUBTAUTHOR_CHECK), StringUtils.defaultIfBlank(currentSpecies.getSubtaxaAuthority(), SUGGESTION_BLANK),
subtAuthor, CURRENT_SUFFIX);
updateOutputColumn(outputLine, outputHeaders.indexOf(HEADER_SPAUTHOR_CHECK),
StringUtils.defaultIfBlank(currentSpecies.getSpeciesAuthority(), SUGGESTION_BLANK), spAuthor, CURRENT_SUFFIX);
updateOutputColumn(outputLine, outputHeaders.indexOf(HEADER_SUBTAXA_CHECK),
StringUtils.defaultIfBlank(currentSpecies.getSubtaxa(), SUGGESTION_BLANK), subtaxa, CURRENT_SUFFIX);
updateOutputColumn(outputLine, outputHeaders.indexOf(HEADER_SUBTAUTHOR_CHECK),
StringUtils.defaultIfBlank(currentSpecies.getSubtaxaAuthority(), SUGGESTION_BLANK), subtAuthor, CURRENT_SUFFIX);
}
} else {
LOG.debug("Multiple speciesRows match genus={} species={} subtaxa={}", genus, species, subtaxa);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment