Search in sources :

Example 46 with StudyImpl

use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForStrona method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    LabeledCSVParser dataParser;
    try {
        dataParser = parserFactory.createParser(RESOURCE_PATH, CharsetConstant.UTF8);
    } catch (IOException e) {
        throw new StudyImporterException("failed to read resource [" + RESOURCE_PATH + "]", e);
    }
    try {
        Study study = nodeFactory.getOrCreateStudy(new StudyImpl("strona2013", SOURCE + " . " + CitationUtil.createLastAccessedString(RESOURCE_PATH), "http://dx.doi.org/10.1890/12-1419.1", SOURCE));
        while (dataParser.getLine() != null) {
            if (importFilter.shouldImportRecord((long) dataParser.getLastLineNumber())) {
                try {
                    String parasiteName = StringUtils.trim(dataParser.getValueByLabel("P_SP"));
                    String hostName = StringUtils.trim(dataParser.getValueByLabel("H_SP"));
                    if (areNamesAvailable(parasiteName, hostName)) {
                        Specimen parasite = nodeFactory.createSpecimen(study, new TaxonImpl(parasiteName, null));
                        Specimen host = nodeFactory.createSpecimen(study, new TaxonImpl(hostName, null));
                        parasite.interactsWith(host, InteractType.PARASITE_OF);
                    }
                } catch (NodeFactoryException | NumberFormatException e) {
                    throw new StudyImporterException("failed to import line [" + (dataParser.lastLineNumber() + 1) + "]", e);
                }
            }
        }
    } catch (IOException | NodeFactoryException e) {
        throw new StudyImporterException("problem importing [" + RESOURCE_PATH + "]", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException)

Example 47 with StudyImpl

use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForSimons method importStudy.

private Study importStudy(ParserFactory parserFactory, String studyResource) throws StudyImporterException {
    Study study = nodeFactory.getOrCreateStudy(new StudyImpl("Simons 1997", StudyImporterForGoMexSI2.GOMEXI_SOURCE_DESCRIPTION, null, ExternalIdUtil.toCitation("James D. Simons", "Food habits and trophic structure of the demersal fish assemblages on the Mississippi-Alabama continental shelf.", "1997")));
    try {
        LabeledCSVParser csvParser = parserFactory.createParser(studyResource, CharsetConstant.UTF8);
        Map<String, String> columnMapper = COLUMN_MAPPER;
        LengthParser parser = new LengthRangeParserImpl(columnMapper.get(LENGTH_RANGE_IN_MM));
        while (csvParser.getLine() != null) {
            addNextRecordToStudy(csvParser, study, COLUMN_MAPPER, parser);
        }
    } catch (IOException e) {
        throw new StudyImporterException("failed to createTaxon study [" + studyResource + "]", e);
    }
    return study;
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException)

Example 48 with StudyImpl

use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.

the class StudyImporterForSIAD method downloadAndImportResource.

private void downloadAndImportResource(String resource, String source) throws StudyImporterException {
    try {
        LabeledCSVParser labeledCSVParser = parserFactory.createParser(resource, "UTF-8");
        labeledCSVParser.changeDelimiter('\t');
        while (labeledCSVParser.getLine() != null) {
            String name = labeledCSVParser.getValueByLabel("name");
            String ref = labeledCSVParser.getValueByLabel("source");
            String title = "SIAD-" + ref;
            String citation = "ABRS 2009. Australian Faunal Directory. " + name + ". Australian Biological Resources StudyNode, Canberra. " + CitationUtil.createLastAccessedString(ref);
            StudyImpl study1 = new StudyImpl(title, source, null, citation);
            study1.setExternalId(ref);
            Study study = nodeFactory.getOrCreateStudy(study1);
            Specimen specimen = nodeFactory.createSpecimen(study, new TaxonImpl(name, null));
            String hostName = labeledCSVParser.getValueByLabel("host name");
            Specimen hostSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(hostName, null));
            InteractType type = map.get(labeledCSVParser.getValueByLabel("interaction"));
            specimen.interactsWith(hostSpecimen, type);
        }
    } catch (FileNotFoundException e) {
        throw new StudyImporterException("failed to open tmp file", e);
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to map data", e);
    } catch (IOException e) {
        throw new StudyImporterException("failed to read resource [" + resource + "]", e);
    }
}
Also used : InteractType(org.eol.globi.domain.InteractType) Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) FileNotFoundException(java.io.FileNotFoundException) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException)

Example 49 with StudyImpl

use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.

the class TaxonInteractionIndexerTest method indexNoNameNoMatch.

@Test
public void indexNoNameNoMatch() throws NodeFactoryException {
    Specimen human = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Homo sapiens", PropertyAndValueDictionary.NO_MATCH));
    Specimen animal = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Canis lupus", PropertyAndValueDictionary.NO_MATCH));
    human.ate(animal);
    for (int i = 0; i < 10; i++) {
        Specimen fish = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Arius felis", null));
        human.ate(fish);
    }
    assertNull(taxonIndex.findTaxonById(PropertyAndValueDictionary.NO_MATCH));
    assertNull(taxonIndex.findTaxonByName("Homo sapiens"));
    new NameResolver(getGraphDb(), new NonResolvingTaxonIndex(getGraphDb())).resolve();
    assertNotNull(taxonIndex.findTaxonByName("Homo sapiens"));
    assertNull(taxonIndex.findTaxonById(PropertyAndValueDictionary.NO_MATCH));
    assertNull(taxonIndex.findTaxonByName(PropertyAndValueDictionary.NO_NAME));
}
Also used : Specimen(org.eol.globi.domain.Specimen) NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) TaxonImpl(org.eol.globi.domain.TaxonImpl) StudyImpl(org.eol.globi.domain.StudyImpl) Test(org.junit.Test)

Example 50 with StudyImpl

use of org.eol.globi.domain.StudyImpl in project eol-globi-data by jhpoelen.

the class TaxonInteractionIndexerTest method buildTaxonInterIndex.

@Test
public void buildTaxonInterIndex() throws NodeFactoryException, PropertyEnricherException {
    Specimen human = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Homo sapiens", "NCBI:9606"));
    Specimen animal = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Canis lupus", "WORMS:2"));
    human.ate(animal);
    for (int i = 0; i < 10; i++) {
        Specimen fish = nodeFactory.createSpecimen(nodeFactory.createStudy(new StudyImpl("bla", null, null, null)), new TaxonImpl("Arius felis", "WORMS:158711"));
        human.ate(fish);
    }
    assertNull(taxonIndex.findTaxonById("WORMS:2"));
    assertNull(taxonIndex.findTaxonByName("Homo sapiens"));
    new NameResolver(getGraphDb(), new NonResolvingTaxonIndex(getGraphDb())).resolve();
    new TaxonInteractionIndexer(getGraphDb()).index();
    Taxon homoSapiens = taxonIndex.findTaxonByName("Homo sapiens");
    assertNotNull(homoSapiens);
    Iterable<Relationship> rels = ((NodeBacked) homoSapiens).getUnderlyingNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(InteractType.ATE));
    List<String> humanFood = new ArrayList<String>();
    List<Long> counts = new ArrayList<Long>();
    List<String> labels = new ArrayList<>();
    for (Relationship rel : rels) {
        humanFood.add((String) rel.getEndNode().getProperty("name"));
        counts.add((Long) rel.getProperty("count"));
        labels.add((String) rel.getProperty("label"));
    }
    assertThat(humanFood.size(), is(4));
    assertThat(humanFood, hasItems("Arius felis", "Canis lupus"));
    assertThat(counts, hasItems(10L, 1L));
    assertThat(labels, hasItems("eats"));
}
Also used : NonResolvingTaxonIndex(org.eol.globi.taxon.NonResolvingTaxonIndex) TaxonImpl(org.eol.globi.domain.TaxonImpl) Taxon(org.eol.globi.domain.Taxon) StudyImpl(org.eol.globi.domain.StudyImpl) ArrayList(java.util.ArrayList) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Aggregations

StudyImpl (org.eol.globi.domain.StudyImpl)82 Study (org.eol.globi.domain.Study)60 Test (org.junit.Test)40 Specimen (org.eol.globi.domain.Specimen)33 TaxonImpl (org.eol.globi.domain.TaxonImpl)33 IOException (java.io.IOException)20 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)17 Location (org.eol.globi.domain.Location)15 StringWriter (java.io.StringWriter)12 LocationImpl (org.eol.globi.domain.LocationImpl)12 Date (java.util.Date)9 HashMap (java.util.HashMap)9 Taxon (org.eol.globi.domain.Taxon)9 StudyNode (org.eol.globi.domain.StudyNode)7 Node (org.neo4j.graphdb.Node)7 File (java.io.File)6 TermImpl (org.eol.globi.domain.TermImpl)6 DatasetImpl (org.eol.globi.service.DatasetImpl)6 InteractType (org.eol.globi.domain.InteractType)5 NonResolvingTaxonIndex (org.eol.globi.taxon.NonResolvingTaxonIndex)5