Search in sources :

Example 61 with Specimen

use of org.eol.globi.domain.Specimen 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 62 with Specimen

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

the class StudyImporterForSPIRETest method assertSingleImport.

private void assertSingleImport(String spireHabitat, String envoId, String envoLabel) throws NodeFactoryException {
    StudyImporterForSPIRE studyImporterForSPIRE = createImporter();
    HashMap<String, String> properties = new HashMap<String, String>();
    properties.put(StudyConstant.TITLE, "the study of men eating dogs");
    properties.put(StudyImporterForSPIRE.PREY_NAME, "dog");
    properties.put(StudyImporterForSPIRE.PREDATOR_NAME, "man");
    properties.put(StudyImporterForSPIRE.LOCALITY_ORIGINAL, "something");
    properties.put(StudyImporterForSPIRE.OF_HABITAT, spireHabitat);
    studyImporterForSPIRE.importTrophicLink(properties);
    resolveNames();
    Taxon dog = taxonIndex.findTaxonByName("dog");
    assertThat(dog, is(notNullValue()));
    Taxon man = taxonIndex.findTaxonByName("man");
    assertThat(man, is(notNullValue()));
    Iterable<Relationship> specimenRels = ((NodeBacked) man).getUnderlyingNode().getRelationships(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
    int count = 0;
    for (Relationship specimenRel : specimenRels) {
        count++;
        Specimen specimen = new SpecimenNode(specimenRel.getStartNode());
        assertThat(specimen.getSampleLocation().getLatitude(), is(1.0));
        assertThat(specimen.getSampleLocation().getLongitude(), is(2.0));
        List<Environment> environments = specimen.getSampleLocation().getEnvironments();
        assertThat(environments.size(), is(1));
        Environment environment = environments.get(0);
        assertThat(environment.getExternalId(), is(envoId));
        assertThat(environment.getName(), is(envoLabel));
    }
    assertThat(count, is(1));
}
Also used : Specimen(org.eol.globi.domain.Specimen) HashMap(java.util.HashMap) Taxon(org.eol.globi.domain.Taxon) Relationship(org.neo4j.graphdb.Relationship) Environment(org.eol.globi.domain.Environment) SpecimenNode(org.eol.globi.domain.SpecimenNode)

Example 63 with Specimen

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

the class StudyImporterForWrastTest method createAndPopulateStudyFromLavacaBay.

@Test
public void createAndPopulateStudyFromLavacaBay() throws StudyImporterException, ParseException {
    String csvString = "\"Month\",\"Day\",\"Year\",\"Region\",\"Season\",\"Habitat\",\"Site\",\"Family\",\"Predator Species\",\"TL (mm)\",\"Prey Item Species\",\"Prey item\",\"Number\",\"Condition Index\",\"Volume\",\"Percent Content\",\"Prey Item Trophic Level\",\"Notes\",\"Call #\"\n";
    csvString += "7,24,2001,\"Lower\",\"Fall\",\"Marsh\",1,\"Sciaenidae\",\"Sciaenops ocellatus\",420,\"Acrididae spp. \",\"Acrididae \",1,\"III\",0.4,3.2520325203,2.5,,1\n";
    csvString += "7,25,2001,\"Lower\",\"Spring\",\"Non-Veg \",1,\"Ariidae\",\"Arius felis\",176,\"Aegathoa oculata \",\"Aegathoa oculata\",4,\"I\",0.01,3.3333333333,2.1,,2\n";
    csvString += "7,26,2001,\"Upper\",\"Spring\",\"Reef\",2,\"Depth\",\"Missing depth\",176,\"Aegathoa oculata \",\"Aegathoa oculata\",4,\"I\",0.01,3.3333333333,2.1,,2\n";
    Map<String, String> contentMap = new HashMap<String, String>();
    String locationString = "\"Location\",\"Latitude\",\"Longitude\",,\"Region\",\"Habitat\",\"Site\"\n" + "\"LM1\",28.595267,-96.477033,,\"Lower\",\"Marsh edge\",1\n" + "\"LSG1\",28.596233,-96.476483,,\"Lower\",\"Marsh edge\",1\n" + "\"LM2\",28.593150,-96.474633,,\"Lower\",\"Marsh edge\",2\n" + "\"LSG2\",28.594833,-96.473967,,\"Lower\",\"Marsh edge\",2\n" + "\"LNV1A\",28.608417,-96.475517,,\"Lower\",\"Non-Veg \",1\n" + "\"LNV1B\",28.607217,-96.474500,,\"Lower\",\"Non-Veg \",1\n" + "\"LNV2A\",28.592400,-96.483033,,\"Lower\",\"Non-Veg \",2\n" + "\"LNV2B\",28.590883,-96.484133,,\"Lower\",\"Non-Veg \",2\n" + "\"UR2B\",28.656483,-96.597217,,\"Upper\",\"Reef\",2";
    String envString = "\"Date\",\"Season\",\"Upper/Lower\",\"Habitat\",\"Site\",\"Air Temp (ºC)\",\"Wind Chill (ºC)\",\"Relative Humidity (%)\",\"Heat Index (ºC)\",\"Dew Point (ºC)\",\"Max Wind intensity (mph)\",\"Ave Wind intensity (mph)\",\"Wind Direction\",\"Cloud Cover (%)\",\"Rain?\",\"Depth (m)\",\"Temp (ºC) Surface\",\"Temp (ºC) Bottom\",\"Mean Temp Surface/Bottom\",\"pH Surface\",\"pH Bottom\",\"Mean pH Surface/Bottom\",\"DO (mg/L) Surface\",\"DO (mg/L) Bottom\",\"Mean DO Surface/Bottom\",\"Sal (o/oo) Surface\",\"Sal (o/oo) Bottom\",\"Mean Sal Surface/Bottom\",\"Secchi (m)\"\n" + "7/24/2006,\"Summer\",\"L\",\"R\",1,\"81.3 (F)\",\"81.5 (F)\",71.8,\"86.2 (F)\",\"70.6 (F)\",8.5,8.1,\"SE\",75,\"Yes\",1.9,30.79,30.34,30.565,8.11,8.13,8.12,5.16,4.8,4.98,22.8,23.07,22.935,0.4\n" + "7/24/2006,\"Summer\",\"L\",\"R\",2,\"81.3 (F)\",\"81.5 (F)\",71.8,\"86.2 (F)\",\"70.6 (F)\",8.5,8.1,\"SE\",75,\"Yes\",2.1,31.07,30.14,30.605,8.11,8.1,8.105,5.14,4.64,4.89,23.37,23.84,23.605,0.48\n" + "10/26/2006,\"Fall\",\"L\",\"M\",1,26.8,26.5,78,30,22.4,17.9,15,\"S \",95,\"No\",0.8,25.57,,25.57,8.29,,8.29,8.32,,8.32,21.26,,21.26,\"Bottom\"\n" + "10/26/2006,\"Fall\",\"L\",\"M\",2,26.8,26.5,78,30,22.4,17.9,15,\"S \",95,\"No\",0.4,25.84,,25.84,8.32,,8.32,8.21,,8.21,21.47,,21.47,\"Bottom\"\n" + "10/26/2006,\"Fall\",\"L\",\"SG\",1,26.8,26.5,78,30,22.4,17.9,15,\"S \",95,\"No\",0.8,25.57,,25.57,8.29,,8.29,8.32,,8.32,21.26,,21.26,\"Bottom\"\n" + "4/27/2007,\"Spring\",\"L\",\"R\",1,22.4,22.3,75,23.1,18.1,10.4,9.1,\"NW\",98,\"No\",1.6,23.43,23.39,23.41,,,,7.31,7.09,7.2,14.64,14.64,14.64,0.32\n" + "4/27/2007,\"Spring\",\"L\",\"R\",2,22.4,22.3,75,23.1,18.1,10.4,9.1,\"NW\",98,\"No\",2,23.77,23.77,23.77,,,,7.01,6.82,6.915,15.04,15.04,15.04,0.38\n" + "4/27/2007,\"Spring\",\"L\",\"NV\",1,22.4,22.3,75,23.1,18.1,10.4,9.1,\"NW\",98,\"No\",2,23.85,23.85,23.85,,,,6.96,6.81,6.885,14.65,14.65,14.65,0.48\n" + "4/27/2007,\"Spring\",\"L\",\"NV\",2,22.4,22.3,75,23.1,18.1,10.4,9.1,\"NW\",98,\"No\",1.8,23.78,23.78,23.78,,,,6.87,6.65,6.76,15.11,15.18,15.145,0.45";
    contentMap.put(StudyImporterForWrast.LAVACA_BAY_LOCATIONS, locationString);
    contentMap.put(StudyImporterForWrast.LAVACA_BAY_DATA_SOURCE, csvString);
    contentMap.put(StudyImporterForWrast.LAVACA_BAY_ENVIRONMENTAL, envString);
    StudyImporterForWrast importer = new StudyImporterForWrast(new TestParserFactory(contentMap), nodeFactory);
    importStudy(importer);
    Study study = getStudySingleton(getGraphDb());
    int specimenCount = 0;
    for (Relationship specimen : NodeUtil.getSpecimens(study)) {
        specimenCount++;
    }
    assertThat(specimenCount, is(5));
    assertNotNull(taxonIndex.findTaxonByName("Sciaenops ocellatus"));
    assertNotNull(taxonIndex.findTaxonByName("Arius felis"));
    assertNotNull(taxonIndex.findTaxonByName("Aegathoa oculata"));
    assertNotNull(nodeFactory.findSeason("spring"));
    assertNotNull(nodeFactory.findSeason("fall"));
    Study foundStudy = nodeFactory.findStudy("Wrast 2008");
    assertNotNull(foundStudy);
    for (Relationship rel : NodeUtil.getSpecimens(study)) {
        Date unixEpochProperty = nodeFactory.getUnixEpochProperty(new SpecimenNode(rel.getEndNode()));
        SimpleDateFormat simpleDateFormat = StudyImporterForWrast.getSimpleDateFormat();
        Date endDate = simpleDateFormat.parse("7/27/2001");
        Date startDate = simpleDateFormat.parse("7/23/2001");
        assertThat(unixEpochProperty.before(endDate), is(true));
        assertThat(unixEpochProperty.after(startDate), is(true));
        Specimen specimen = new SpecimenNode(rel.getEndNode());
        for (Relationship ateRel : NodeUtil.getStomachContents(specimen)) {
            TaxonNode taxon = new TaxonNode(rel.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode());
            String scientificName = taxon.getName();
            if ("Sciaenops ocellatus".equals(scientificName)) {
                Location location = specimen.getSampleLocation();
                assertThat(location, is(not(nullValue())));
                assertThat(location.getLatitude(), is((28.595267 + 28.596233) / 2.0));
                assertThat(location.getLongitude(), is((-96.477033 - 96.476483) / 2.0));
                assertThat(location.getAltitude(), is(-0.8));
                Iterable<Relationship> stomachContents = NodeUtil.getStomachContents(specimen);
                int count = 0;
                for (Relationship containsRel : stomachContents) {
                    Node endNode = containsRel.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode();
                    Object name = endNode.getProperty("name");
                    String name1 = (String) name;
                    assertThat(name1.replaceAll("\\W", ""), is("Acrididae"));
                    count++;
                }
                assertEquals(1, count);
                Season season = specimen.getSeason();
                assertEquals("fall", season.getTitle());
                assertEquals(420.0d, specimen.getLengthInMm());
            } else if ("Arius felis".equals(scientificName)) {
                Location location = specimen.getSampleLocation();
                assertThat(location, is(not(nullValue())));
                assertThat(location.getLatitude(), is((28.608417 + 28.607217) / 2.0));
                assertThat(location.getLongitude(), is((-96.475517 - 96.474500) / 2.0));
                assertThat(location.getAltitude(), is(-2.0d));
                Iterable<Relationship> stomachContents = NodeUtil.getStomachContents(specimen);
                int count = 0;
                for (Relationship containsRel : stomachContents) {
                    Object name = containsRel.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode().getProperty("name");
                    assertEquals("Aegathoa oculata", name);
                    count++;
                }
                assertEquals(2, count);
                Season season = specimen.getSeason();
                assertEquals("spring", season.getTitle());
                assertEquals(176.0d, specimen.getLengthInMm());
            } else if ("Missing depth".equals(scientificName)) {
                Location location = specimen.getSampleLocation();
                assertThat(location, is(not(nullValue())));
                assertThat(location.getAltitude(), is(nullValue()));
            } else {
                fail("unexpected scientificName of predator [" + scientificName + "]");
            }
        }
    }
}
Also used : Study(org.eol.globi.domain.Study) TaxonNode(org.eol.globi.domain.TaxonNode) HashMap(java.util.HashMap) Node(org.neo4j.graphdb.Node) SpecimenNode(org.eol.globi.domain.SpecimenNode) TaxonNode(org.eol.globi.domain.TaxonNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) Date(java.util.Date) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) Season(org.eol.globi.domain.Season) SimpleDateFormat(java.text.SimpleDateFormat) Location(org.eol.globi.domain.Location) Test(org.junit.Test)

Example 64 with Specimen

use of org.eol.globi.domain.Specimen 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 65 with Specimen

use of org.eol.globi.domain.Specimen 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

Specimen (org.eol.globi.domain.Specimen)91 TaxonImpl (org.eol.globi.domain.TaxonImpl)59 Study (org.eol.globi.domain.Study)38 StudyImpl (org.eol.globi.domain.StudyImpl)34 Location (org.eol.globi.domain.Location)31 LocationImpl (org.eol.globi.domain.LocationImpl)22 Test (org.junit.Test)17 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)15 IOException (java.io.IOException)15 Date (java.util.Date)14 Relationship (org.neo4j.graphdb.Relationship)12 HashMap (java.util.HashMap)11 Taxon (org.eol.globi.domain.Taxon)11 SpecimenNode (org.eol.globi.domain.SpecimenNode)9 TermImpl (org.eol.globi.domain.TermImpl)9 ArrayList (java.util.ArrayList)8 InteractType (org.eol.globi.domain.InteractType)7 LatLng (org.eol.globi.geo.LatLng)6 Map (java.util.Map)5 TaxonNode (org.eol.globi.domain.TaxonNode)5