Search in sources :

Example 11 with SpecimenNode

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

Example 12 with SpecimenNode

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

the class StudyImporterForBlewettTest method importLines.

@Test
public void importLines() throws StudyImporterException, NodeFactoryException {
    String predatorPreyMapping = "\"Collection #\",\"Sp#\",\"Standard Length\",\"ID\",\"Far duoraum\",\"Cal sapidus\",\"Unid fish\",\"Anchoa spp\",\"Mug gyrans\",\"Bai chrysoura\",\"Portunus spp\",\"Bivalves\",\"Portunidae\",\"Lag rhomboides\",\"Xanthidae\",\"Palaemonidae\",\"Eucinostomus spp\",\"Mugil spp\",\"Alpheidae\",\"Atherinidae\",\"Syn foetens\",\"Ort chrysoptera\",\"Snails\",\"Euc gula\",\"Cynoscion spp\",\"Cyp. Variegatus\",\"Fun majalis\",\"Poe latipinna\",\"Unid crab\",\"Har jaguana\",\"Arm mierii\",\"Fun grandis\",\"Mic gulosus\",\"Ari felis\",\"Clupeidae\",\"Fundulus spp\",\"Diapterus/Eugerres spp\",\"Isopods\",\"Cyn nebulosus\",\"Opi oglinum\",\"Flo carpio\",\"Luc parva\",\"Uca spp\",\"Majidae\",\"Mug cephalus\",\"Squ empusa\",\"Opi robinsi\",\"Ariidae\",\"Sci ocellatus\",\"Unid shrimp\",\"Uca thayeri\",\"Grapsidae\",\"Lei xanthurus\",\"Elo saurus\",\"Brevoortia spp\"\n" + "\"CHD01101502\",1,549,,,,,,,,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHD01102504\",1,548,\"E\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHD01102504\",2,550,,3,,,,,,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHM000152\",1,580,\"E\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n" + "\"CHM000152\",2,556,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,";
    String dateLocationString = "\"Collection #\",\"Longitude\",\"Latitude\",\"Time\",\"Date\",\"Temperature\",\"Salinity\"\n" + "\"CHD01101502\",-82.1625,26.72,10:55:00,1-Mar-00,22.4,33.8\n" + "\"CHD01102504\",-82.1625,26.72,10:55:00,1-Mar-00,22.4,33.8\n" + "\"CHM000151\",-82.1625,26.72,10:55:00,1-Mar-00,22.4,33.8\n" + "\"CHM000152\",-82.103833,26.651833,12:40:00,1-Mar-00,24.8,30.3\n" + "\"CHM000153\",-82.087333,26.644833,13:40:00,1-Mar-00,25.1,30.1\n" + "\"CHM000154\",-82.083167,26.671167,14:40:00,1-Mar-00,26,30.4\n" + "\"CHM000175\",-82.197833,26.688167,10:00:00,8-Mar-00,22.2,35.05\n" + "\"CHM000176\",-82.191333,26.667333,11:00:00,8-Mar-00,22.7,35.25";
    final TestParserFactory preyPredatorFactory = new TestParserFactory(predatorPreyMapping);
    final TestParserFactory dateLocationFactory = new TestParserFactory(dateLocationString);
    ParserFactory testFactory = new ParserFactory() {

        @Override
        public LabeledCSVParser createParser(String studyResource, String characterEncoding) throws IOException {
            LabeledCSVParser parser = null;
            if (studyResource.contains("abundance")) {
                parser = preyPredatorFactory.createParser(studyResource, characterEncoding);
            } else {
                parser = dateLocationFactory.createParser(studyResource, characterEncoding);
            }
            return parser;
        }
    };
    StudyImporter importer = new StudyImporterTestFactory(testFactory, nodeFactory).instantiateImporter((Class) StudyImporterForBlewett.class);
    importStudy(importer);
    Study study = getStudySingleton(getGraphDb());
    Iterable<Relationship> collectedRels = NodeUtil.getSpecimens(study);
    Relationship collectedRel = collectedRels.iterator().next();
    Date unixEpochProperty = nodeFactory.getUnixEpochProperty(new SpecimenNode(collectedRel.getEndNode()));
    assertThat(unixEpochProperty, is(not(nullValue())));
    assertThat(dateToString(unixEpochProperty), is("2000-03-01T10:55:00.000-06:00"));
    Node predatorNode = collectedRel.getEndNode();
    assertThat((String) predatorNode.getProperty(SpecimenConstant.LIFE_STAGE_LABEL), is("post-juvenile adult stage"));
    assertThat((String) predatorNode.getProperty(SpecimenConstant.LIFE_STAGE_ID), is("UBERON:0000113"));
    assertThat((Double) predatorNode.getProperty(SpecimenConstant.LENGTH_IN_MM), is(549.0));
    Node predatorTaxonNode = predatorNode.getRelationships(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).iterator().next().getEndNode();
    assertThat((String) predatorTaxonNode.getProperty(PropertyAndValueDictionary.NAME), is("Centropomus undecimalis"));
    Iterable<Relationship> ate = predatorNode.getRelationships(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING);
    Node preyNode = ate.iterator().next().getEndNode();
    assertThat(preyNode, is(not(nullValue())));
    Node taxonNode = preyNode.getRelationships(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).iterator().next().getEndNode();
    assertThat(taxonNode, is(not(nullValue())));
    assertThat((String) taxonNode.getProperty(PropertyAndValueDictionary.NAME), is("Lag rhomboides"));
    Iterator<Relationship> i = collectedRels.iterator();
    i.next();
    collectedRel = i.next();
    predatorNode = collectedRel.getEndNode();
    assertThat((Double) predatorNode.getProperty(SpecimenConstant.LENGTH_IN_MM), is(548.0));
    ate = predatorNode.getRelationships(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING);
    assertThat(ate.iterator().hasNext(), is(false));
    Location location = nodeFactory.findLocation(new LocationImpl(26.651833, -82.103833, 0.0, null));
    assertThat(location, is(not(nullValue())));
    Iterable<Relationship> specimenCaughtHere = NodeUtil.getSpecimenCaughtHere(location);
    Iterator<Relationship> iterator = specimenCaughtHere.iterator();
    assertThat(iterator.hasNext(), is(true));
    iterator.next();
    assertThat(iterator.hasNext(), is(true));
    iterator.next();
    assertThat(iterator.hasNext(), is(true));
    iterator.next();
    assertThat(iterator.hasNext(), is(false));
}
Also used : Study(org.eol.globi.domain.Study) Node(org.neo4j.graphdb.Node) SpecimenNode(org.eol.globi.domain.SpecimenNode) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) SpecimenNode(org.eol.globi.domain.SpecimenNode) Date(java.util.Date) Relationship(org.neo4j.graphdb.Relationship) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location) Test(org.junit.Test)

Example 13 with SpecimenNode

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

the class InteractionListenerImplTest method importBlankCitation.

@Test
public void importBlankCitation() throws StudyImporterException {
    final InteractionListenerImpl listener = new InteractionListenerImpl(nodeFactory, null, null);
    final HashMap<String, String> link = new HashMap<String, String>();
    link.put(SOURCE_TAXON_NAME, "donald");
    link.put(SOURCE_TAXON_ID, "duck");
    link.put(SOURCE_BODY_PART_ID, "bla:123");
    link.put(SOURCE_BODY_PART_NAME, "snout");
    link.put(TARGET_TAXON_NAME, "mini");
    link.put(TARGET_TAXON_ID, "mouse");
    link.put(TARGET_BODY_PART_ID, "bla:345");
    link.put(TARGET_BODY_PART_NAME, "tail");
    link.put(StudyImporterForMetaTable.EVENT_DATE, "20160404T21:31:40Z");
    link.put(StudyImporterForMetaTable.LATITUDE, "12.1");
    link.put(StudyImporterForMetaTable.LONGITUDE, "13.2");
    link.put(StudyImporterForTSV.INTERACTION_TYPE_ID, "http://purl.obolibrary.org/obo/RO_0002470");
    link.put(REFERENCE_ID, "123");
    link.put(STUDY_SOURCE_CITATION, "some source ref");
    link.put(REFERENCE_CITATION, "");
    link.put(REFERENCE_DOI, "doi:1234");
    listener.newLink(link);
    final List<Study> allStudies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(allStudies.size(), is(1));
    final Study study = allStudies.get(0);
    assertThat(study.getCitation(), is(""));
    boolean foundPair = false;
    for (Relationship specimenRel : NodeUtil.getSpecimens(study)) {
        final SpecimenNode predator = new SpecimenNode(specimenRel.getEndNode());
        for (Relationship stomachRel : NodeUtil.getStomachContents(predator)) {
            final SpecimenNode prey = new SpecimenNode(stomachRel.getEndNode());
            final TaxonNode preyTaxon = getOrigTaxon(prey);
            final TaxonNode predTaxon = getOrigTaxon(predator);
            assertThat(preyTaxon.getName(), is("mini"));
            assertThat(preyTaxon.getExternalId(), is("mouse"));
            assertThat(predTaxon.getName(), is("donald"));
            assertThat(predTaxon.getExternalId(), is("duck"));
            assertLocation(predator.getSampleLocation());
            assertLocation(prey.getSampleLocation());
            foundPair = true;
            assertThat(specimenRel.getProperty(SpecimenConstant.DATE_IN_UNIX_EPOCH), is(notNullValue()));
            List<SpecimenNode> specimens = Arrays.asList(predator, prey);
            for (SpecimenNode specimen : specimens) {
                assertThat(specimen.getBodyPart().getId(), is(notNullValue()));
                assertThat(specimen.getBodyPart().getName(), is(notNullValue()));
            }
        }
    }
    assertThat(foundPair, is(true));
}
Also used : Study(org.eol.globi.domain.Study) TaxonNode(org.eol.globi.domain.TaxonNode) HashMap(java.util.HashMap) Relationship(org.neo4j.graphdb.Relationship) SpecimenNode(org.eol.globi.domain.SpecimenNode) Test(org.junit.Test)

Example 14 with SpecimenNode

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

the class StudyImporterForLifeWatchGreeceTest method addTaxonNameForSpecimenNode.

private void addTaxonNameForSpecimenNode(Set<String> taxa, Node startNode) {
    Specimen predatorSpecimen = new SpecimenNode(startNode);
    Iterable<Relationship> classifications = NodeUtil.getClassifications(predatorSpecimen);
    for (Relationship classification : classifications) {
        taxa.add(new TaxonNode(classification.getEndNode()).getName());
    }
}
Also used : Specimen(org.eol.globi.domain.Specimen) TaxonNode(org.eol.globi.domain.TaxonNode) Relationship(org.neo4j.graphdb.Relationship) SpecimenNode(org.eol.globi.domain.SpecimenNode)

Example 15 with SpecimenNode

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

the class StudyImporterForLifeWatchGreeceTest method readAssociations.

@Test
public void readAssociations() throws StudyImporterException {
    List<Study> studies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(studies.size(), is(0));
    ParserFactoryLocal parserFactory = new ParserFactoryLocal();
    StudyImporterForLifeWatchGreece importer = new StudyImporterForLifeWatchGreece(parserFactory, nodeFactory);
    importer.setDataset(new DatasetLocal());
    importStudy(importer);
    studies = NodeUtil.findAllStudies(getGraphDb());
    assertThat(studies.size(), is(146));
    Set<String> taxa = new HashSet<String>();
    int totalPredatorPreyRelationships = 0;
    for (Study study : studies) {
        assertThat(study.getCitation(), is(notNullValue()));
        assertThat(study.getTitle(), containsString("greece"));
        Iterable<Relationship> specimens = NodeUtil.getSpecimens(study);
        for (Relationship collectedRel : specimens) {
            addTaxonNameForSpecimenNode(taxa, collectedRel.getEndNode());
            Specimen predatorSpecimen = new SpecimenNode(collectedRel.getEndNode());
            Iterable<Relationship> prey = NodeUtil.getStomachContents(predatorSpecimen);
            for (Relationship ateRel : prey) {
                totalPredatorPreyRelationships++;
                addTaxonNameForSpecimenNode(taxa, ateRel.getEndNode());
            }
        }
    }
    assertThat(taxa.contains("Aves"), is(true));
    assertThat(totalPredatorPreyRelationships, is(793));
}
Also used : Study(org.eol.globi.domain.Study) Matchers.containsString(org.hamcrest.Matchers.containsString) SpecimenNode(org.eol.globi.domain.SpecimenNode) DatasetLocal(org.eol.globi.service.DatasetLocal) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SpecimenNode (org.eol.globi.domain.SpecimenNode)18 Relationship (org.neo4j.graphdb.Relationship)17 Study (org.eol.globi.domain.Study)13 Test (org.junit.Test)11 Specimen (org.eol.globi.domain.Specimen)9 Node (org.neo4j.graphdb.Node)7 HashMap (java.util.HashMap)6 JsonNode (org.codehaus.jackson.JsonNode)5 Location (org.eol.globi.domain.Location)5 Taxon (org.eol.globi.domain.Taxon)4 TaxonNode (org.eol.globi.domain.TaxonNode)4 Date (java.util.Date)3 Environment (org.eol.globi.domain.Environment)3 LocationImpl (org.eol.globi.domain.LocationImpl)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 LogContext (org.eol.globi.domain.LogContext)2 Term (org.eol.globi.domain.Term)2 DatasetImpl (org.eol.globi.service.DatasetImpl)2