Search in sources :

Example 71 with Specimen

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

the class StudyImporterForHechinger method addLink.

private void addLink(Study study, Map<Integer, Term> stageForNode, Map<Integer, String> taxonForNode, LabeledCSVParser links, Location location) throws StudyImporterException, NodeFactoryException {
    Integer consumerNodeID = Integer.parseInt(links.getValueByLabel("ConsumerNodeID"));
    Integer resourceNodeID = Integer.parseInt(links.getValueByLabel("ResourceNodeID"));
    String linkType = links.getValueByLabel("LinkType");
    InteractType interactType = interactionMapping.get(StringUtils.trim(StringUtils.lowerCase(linkType)));
    if (interactType == null) {
        throw new StudyImporterException("failed to map interaction type [" + linkType + "] in line [" + links.lastLineNumber() + "]");
    }
    Specimen consumer = nodeFactory.createSpecimen(study, new TaxonImpl(taxonForNode.get(consumerNodeID), null));
    consumer.setLifeStage(stageForNode.get(consumerNodeID));
    consumer.setExternalId(getNamespace() + ":NodeID:" + consumerNodeID);
    consumer.caughtIn(location);
    String resourceName = taxonForNode.get(resourceNodeID);
    Specimen resource = nodeFactory.createSpecimen(study, new TaxonImpl(resourceName, null));
    resource.setLifeStage(stageForNode.get(resourceNodeID));
    resource.setExternalId(getNamespace() + ":NodeID:" + resourceNodeID);
    resource.caughtIn(location);
    consumer.interactsWith(resource, interactType);
}
Also used : InteractType(org.eol.globi.domain.InteractType) Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl)

Example 72 with Specimen

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

the class StudyImporterForGoMexSI2 method addObservation.

private void addObservation(Map<String, List<Map<String, String>>> predatorUIToPreyLists, LabeledCSVParser parser, Study study, Location location, String predatorId, Map<String, String> predatorProperties) throws StudyImporterException {
    try {
        Specimen predatorSpecimen = createSpecimen(study, predatorProperties);
        setBasisOfRecordAsLiterature(predatorSpecimen);
        predatorSpecimen.setExternalId(predatorId);
        if (location == null) {
            getLogger().warn(study, "no location for predator with id [" + predatorSpecimen.getExternalId() + "]");
        } else {
            predatorSpecimen.caughtIn(location);
        }
        List<Map<String, String>> preyList = predatorUIToPreyLists.get(predatorId);
        checkStomachDataConsistency(predatorId, predatorProperties, preyList, study);
        if (preyList != null) {
            for (Map<String, String> preyProperties : preyList) {
                if (preyProperties != null) {
                    try {
                        Specimen prey = createSpecimen(study, preyProperties);
                        setBasisOfRecordAsLiterature(prey);
                        prey.caughtIn(location);
                        predatorSpecimen.ate(prey);
                    } catch (NodeFactoryException e) {
                        getLogger().warn(study, "failed to add prey [" + preyProperties + "] for predator with id + [" + predatorId + "]: [" + predatorProperties + "]: [" + e.getMessage() + "]");
                    }
                }
            }
        }
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to create specimen for location on line [" + parser.getLastLineNumber() + "]", e);
    }
}
Also used : Specimen(org.eol.globi.domain.Specimen) HashMap(java.util.HashMap) Map(java.util.Map)

Example 73 with Specimen

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

the class StudyImporterForICES method addPredator.

private Specimen addPredator(LabeledCSVParser parser, Study study) throws StudyImporterException {
    Specimen predatorSpecimen;
    predatorSpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(parser.getValueByLabel("Predator"), null));
    predatorSpecimen.setLengthInMm(parseDoubleField(parser, "Predator (mean) Lengh"));
    return predatorSpecimen;
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl)

Example 74 with Specimen

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

the class StudyImporterForICES method atePrey.

private Specimen atePrey(Specimen predatorSpecimen, String preyName, Study study) throws NodeFactoryException {
    Specimen preySpecimen = nodeFactory.createSpecimen(study, new TaxonImpl(preyName, null));
    predatorSpecimen.ate(preySpecimen);
    return preySpecimen;
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonImpl(org.eol.globi.domain.TaxonImpl)

Example 75 with Specimen

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

the class StudyImporterForAkinTest method importHeaderAndASingleSpecimen.

@Test
public void importHeaderAndASingleSpecimen() throws StudyImporterException, ParseException {
    String csvString = ",\"Fish No\",\"Fish Species\",\"Date \",,\"Site \",\"SL(mm)\",\"Stomach volume\",\"Stomach status\",\"C. Method\",\"Detritus\",\"Sand\",\"Diatoms\",\"Centric diatoms\",\"Pennate diatoms\",\"Oscillatoria \",\"Filamentous algae\",\"Green algae\",\"Other blue green algae\",\"Unicellular green algae\",\"Brown algae\",\"Golden brown algae\",\"Nostocales (Blue green algae)\",\"Chara\",\"Ruppia maritima\",\"Other macrophytes\",\"Seeds\",\"Invertebrate eggs \",\"Fish bones\",\"Lucania parva eggs\",\"Other fish eggs\",\"Catfish egg\",\"Unidentified bone\",\"Fish eyes\",\"Fish otolith\",\"Ctenoid fish scale\",\"Cycloid fish scale\",\"Dinoflagellates (Noctiluca spp.)\",\"Protozoa\",\"Bivalvia\",\"Gastropoda\",\"Nematode\",\"Nemotode(Parasite)\",\"Calanoida copepoda\",\"Harpacticoida copepoda\",\"Copepoda nauplii\",\"Cyclopoid copepoda\",\"Cladocera\",\"Rotifera\",\"Unidefined zooplankton\",\"Chironomidae larvae\",\"Diptera 1\",\"Diptera 2\",\"Diptera midges(pupa)\",\"Polycheate worm\",\"Other annelid worms\",\"Amphipoda(Gammarus spp.)\",\"Corophium sp(amphipoda)\",\"Decopoda larvae\",\"Isopoda\",\"Unidentified invertebrate\",\"Other Ephemeroptera(Mayfly)\",\"Ephemeroptera(Baetidae)\",\"Coleoptera\",\"Other Hymenoptera\",\"Odonate\",\"Damselfly\",\"Other Thrips\",\"Thysanoptera (thrips)\",\"Pteromalitidae(Hymenoptera)\",\"Hemiptera\",\"Homoptera\",\"Unidentified insect larvae\",\"Arachnida \",\"Unidentified insects\",\"Mollusks (Oyster)\",\"Other Mollusks\",\"Ostracoda\",\"Brachyura (Crab zoea)\",\"Mysidacea\",\"Penneid shrimp post larvae\",\"Unidentified shrimp\",\"Palaemonotes pugio\",\"Peneaus setiferus\",\"Peneaus aztecus\",\"Callinectes sapidus\",\"Other crabs\",\"Neopunope sayi(mud crab)\",\"Myrophis punctatus (speckled worm eel)\",\"Mugil cephalus\",\"Brevoortia patronus\",\"Lepisosteus osseus \",\"Fundulus  grandis\",\"Other fundulus species\",\"Cyprinodon variegatus\",\"Pogonias cromis\",\"Menidia beryllina\",\"Anchoa mitchilli\",\"Other Sciaenidae species\",\"Lagodon rhomboides\",\"Arius felis\",\"Leiostomus xanthurus\",\"Gobiosoma bosc\",\"Lucania parva\",\"Micropogonias undulatus\",\"Cynoscion nebulosus\",\"Poecilia latipinna\",\"Unidentified fish\",\"Unidentified fish larvae\",\"Other Gobiidae \",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + ",1,\"Pogonias cromis\",\"03.07.98\",,1,226,3,,\"Gillnet\",,0.15,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0.6,,,,,,0.45,,,,,,,,,,,,,,,,,,1.35,0.45,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,";
    StudyImporter importer = new StudyImporterTestFactory(new TestParserFactory(csvString), nodeFactory).instantiateImporter((Class) StudyImporterForAkin.class);
    importStudy(importer);
    Study study = getStudySingleton(getGraphDb());
    Taxon taxon = taxonIndex.findTaxonByName("Pogonias cromis");
    assertNotNull(taxon);
    Iterable<Relationship> specimens = NodeUtil.getSpecimens(study);
    Relationship rel = specimens.iterator().next();
    assertThat(rel, is(not(nullValue())));
    Date expectedDate = DateUtil.parsePatternUTC("1998-03-07", "yyyy-MM-dd").toDate();
    assertThat(rel.getProperty(SpecimenConstant.DATE_IN_UNIX_EPOCH), is(expectedDate.getTime()));
    Node specimenNode = rel.getEndNode();
    assertThat(specimenNode.getProperty(SpecimenConstant.LENGTH_IN_MM), is(226.0));
    assertThat(specimenNode.getProperty(SpecimenConstant.STOMACH_VOLUME_ML), is(3.0));
    Specimen specimen = new SpecimenNode(specimenNode);
    assertThat(specimen.getSampleLocation().getAltitude(), is(-0.7));
    Node speciesNode = specimenNode.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode();
    assertThat((String) speciesNode.getProperty("name"), is("Pogonias cromis"));
    Iterable<Relationship> ateRels = specimenNode.getRelationships(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING);
    Map<String, Map<String, Object>> preys = new HashMap<String, Map<String, Object>>();
    for (Relationship ateRel : ateRels) {
        Node preyNode = ateRel.getEndNode();
        Node taxonNode = preyNode.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).getEndNode();
        String name = (String) taxonNode.getProperty("name");
        HashMap<String, Object> propertyMap = new HashMap<String, Object>();
        propertyMap.put("name", name);
        propertyMap.put(SpecimenConstant.VOLUME_IN_ML, preyNode.getProperty(SpecimenConstant.VOLUME_IN_ML));
        preys.put(name, propertyMap);
    }
    Map<String, Object> sand = preys.get("Sand");
    assertThat(sand, is(notNullValue()));
    assertThat((String) sand.get("name"), is("Sand"));
    assertThat((Double) sand.get(SpecimenConstant.VOLUME_IN_ML), is(0.15d));
    Map<String, Object> chironomidae = preys.get("Chironomidae larvae");
    assertThat(chironomidae, is(notNullValue()));
    assertThat((String) chironomidae.get("name"), is("Chironomidae larvae"));
    assertThat((Double) chironomidae.get(SpecimenConstant.VOLUME_IN_ML), is(0.6d));
    Map<String, Object> amphipoda = preys.get("Amphipoda(Gammarus spp.)");
    assertThat(amphipoda, is(notNullValue()));
    assertThat((String) amphipoda.get("name"), is("Amphipoda(Gammarus spp.)"));
    assertThat((Double) amphipoda.get(SpecimenConstant.VOLUME_IN_ML), is(0.45d));
    Map<String, Object> insecta = preys.get("Unidentified insects");
    assertThat(insecta, is(notNullValue()));
    assertThat((String) insecta.get("name"), is("Unidentified insects"));
    assertThat((Double) insecta.get(SpecimenConstant.VOLUME_IN_ML), is(1.35d));
    Map<String, Object> mollusca = preys.get("Mollusks (Oyster)");
    assertThat(mollusca, is(notNullValue()));
    assertThat((String) mollusca.get("name"), is("Mollusks (Oyster)"));
    assertThat((Double) mollusca.get(SpecimenConstant.VOLUME_IN_ML), is(0.45d));
    Node locationNode = specimenNode.getSingleRelationship(NodeUtil.asNeo4j(RelTypes.COLLECTED_AT), Direction.OUTGOING).getEndNode();
    assertThat((Double) locationNode.getProperty(LocationConstant.LATITUDE), is(28.645202d));
    assertThat((Double) locationNode.getProperty(LocationConstant.LONGITUDE), is(-96.099923d));
}
Also used : Study(org.eol.globi.domain.Study) HashMap(java.util.HashMap) Taxon(org.eol.globi.domain.Taxon) Node(org.neo4j.graphdb.Node) SpecimenNode(org.eol.globi.domain.SpecimenNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) Date(java.util.Date) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) HashMap(java.util.HashMap) Map(java.util.Map) 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