Skip to content

Commit

Permalink
ignore whitespaces for ncbi taxon id resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpoelen committed Oct 23, 2018
1 parent ac2c999 commit fa0aeb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ public Map<String, String> enrich(Map<String, String> properties) throws Propert
String externalId = properties.get(PropertyAndValueDictionary.EXTERNAL_ID);

if (PREFIXES.stream().anyMatch(x -> StringUtils.startsWith(externalId, x))) {
String tsn = PREFIXES.stream().reduce(externalId, (x, y) -> StringUtils.replace(x, y, ""));
if (tsn.matches("\\d+")) {
String tsn = PREFIXES
.stream()
.reduce(externalId, (x, y) -> StringUtils.trim(StringUtils.replace(x, y, "")));

if (tsn.matches("^\\d+$")) {
String fullHierarchy = getResponse("db=taxonomy&id=" + tsn);
if (fullHierarchy.contains("<Taxon>")) {
parseAndPopulate(enriched, tsn, fullHierarchy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ public void lookupPathByTaxonIdNCBIPurl() throws PropertyEnricherException {
assertThat(enrich.get(PropertyAndValueDictionary.EXTERNAL_ID), is("NCBI:9606"));
}

@Test
public void lookupPathByTaxonIdNCBIPurlWhitespaces() throws PropertyEnricherException {
PropertyEnricher enricher = new NCBIService();
HashMap<String, String> props = new HashMap<String, String>() {{
put(PropertyAndValueDictionary.EXTERNAL_ID, "http://purl.obolibrary.org/obo/NCBITaxon_9606 ");
}};
Map<String, String> enrich = enricher.enrich(props);
assertThat(enrich.get(PropertyAndValueDictionary.NAME), is("Homo sapiens"));
assertThat(enrich.get(PropertyAndValueDictionary.EXTERNAL_ID), is("NCBI:9606"));
}


@Test
public void parseInconsistentWithAltNCBI191217() throws PropertyEnricherException {
Expand Down

0 comments on commit fa0aeb4

Please sign in to comment.