Commit a04ecafa authored by Matija Obreza's avatar Matija Obreza
Browse files

Refuse to run if source CSV contains _check columns (fixes #11)

parent cb4f854b
......@@ -203,6 +203,23 @@ public class GGTC {
String[] headers = reader.readNext();
LOG.debug("Input CSV headers: {}", Arrays.toString(headers));
{
// Check for _check headers and exit if necessary
boolean err = false;
for (String header : new String[] { HEADER_GENUS_CHECK, HEADER_SPECIES_CHECK, HEADER_SPAUTHOR_CHECK, HEADER_SUBTAXA_CHECK, HEADER_SUBTAUTHOR_CHECK }) {
LOG.info("Looking for header {} in {}", header, Arrays.asList(headers));
int pos = ArrayUtils.indexOf(headers, header);
if (pos >= 0) {
LOG.error("Header {} found in input CSV.", header);
err = true;
}
}
if (err) {
throw new IOException("_check headers found in input file. Refusing to run.");
}
}
List<String> outputHeaders = new ArrayList<>(Arrays.asList(headers));
LOG.debug("Starting output headers: {}", outputHeaders);
......@@ -276,8 +293,7 @@ public class GGTC {
if (outputHeaders.indexOf(HEADER_GENUS_CHECK) >= 0) {
String genus = sourceLine[sourceMapping.get(HEADER_GENUS)];
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"));
......@@ -289,8 +305,7 @@ public class GGTC {
String genus = sourceLine[sourceMapping.get(HEADER_GENUS)];
String species = sourceLine[sourceMapping.get(HEADER_SPECIES)];
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"));
......@@ -332,7 +347,7 @@ public class GGTC {
outputLine[outputHeaders.indexOf(HEADER_SUBTAXA_CHECK)] = StringUtils.equals(subtaxa, subtaxa_check) ? null : subtaxa_check;
}
if (outputHeaders.indexOf(HEADER_SUBTAUTHOR_CHECK) >= 0) {
String genus = sourceLine[sourceMapping.get(HEADER_GENUS)];
String species = sourceLine[sourceMapping.get(HEADER_SPECIES)];
......
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