Search in sources :

Example 6 with RelationshipListener

use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.

the class InteractionImporterTest method assertSymbiotaDateString.

public void assertSymbiotaDateString(String symbiotaTime, String expectedUTC) throws StudyImporterException {
    final InteractionListener listener = getAssertingInteractionImporter();
    final TreeMap<String, String> link = new TreeMap<>();
    link.put(SOURCE_TAXON_NAME, "donald");
    link.put(DatasetImporterForTSV.INTERACTION_TYPE_ID, "http://purl.obolibrary.org/obo/RO_0002470");
    link.put(TARGET_TAXON_NAME, "mini");
    link.put(DatasetImporterForMetaTable.EVENT_DATE, symbiotaTime);
    link.put(REFERENCE_ID, "123");
    link.put(DATASET_CITATION, "some source ref");
    link.put(REFERENCE_CITATION, "");
    listener.on(link);
    AtomicBoolean foundSpecimen = new AtomicBoolean(false);
    RelationshipListener someListener = relationship -> {
        final SpecimenNode someSpecimen = new SpecimenNode(relationship.getEndNode());
        assertTrue(someSpecimen.getUnderlyingNode().hasRelationship(Direction.INCOMING, NodeUtil.asNeo4j(RelTypes.COLLECTED)));
        try {
            Date eventDate = nodeFactory.getUnixEpochProperty(someSpecimen);
            assertThat(DateUtil.printDate(eventDate), is(expectedUTC));
        } catch (NodeFactoryException e) {
            fail(e.getMessage());
        }
        foundSpecimen.set(true);
    };
    handleRelations(someListener, RelTypes.COLLECTED);
    assertThat(foundSpecimen.get(), is(true));
}
Also used : Arrays(java.util.Arrays) NodeUtil(org.eol.globi.util.NodeUtil) SOURCE_BODY_PART_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_BODY_PART_ID) Date(java.util.Date) Direction(org.neo4j.graphdb.Direction) TARGET_SEX_ID(org.eol.globi.data.DatasetImporterForTSV.TARGET_SEX_ID) DatasetImporterForMetaTable(org.eol.globi.data.DatasetImporterForMetaTable) NullImportLogger(org.eol.globi.tool.NullImportLogger) InteractType(org.eol.globi.domain.InteractType) TARGET_TAXON_RANK(org.eol.globi.service.TaxonUtil.TARGET_TAXON_RANK) StudyImporterException(org.eol.globi.data.StudyImporterException) TARGET_TAXON_PATH_IDS(org.eol.globi.service.TaxonUtil.TARGET_TAXON_PATH_IDS) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DECIMAL_LONGITUDE(org.eol.globi.data.DatasetImporterForTSV.DECIMAL_LONGITUDE) COLLECTION_CODE(org.eol.globi.domain.PropertyAndValueDictionary.COLLECTION_CODE) TARGET_TAXON_ID(org.eol.globi.service.TaxonUtil.TARGET_TAXON_ID) SOURCE_TAXON_ID(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_ID) Is.is(org.hamcrest.core.Is.is) SOURCE_LIFE_STAGE_NAME(org.eol.globi.data.DatasetImporterForTSV.SOURCE_LIFE_STAGE_NAME) LatLng(org.eol.globi.geo.LatLng) Assert.fail(org.junit.Assert.fail) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) TARGET_OCCURRENCE_ID(org.eol.globi.data.DatasetImporterForTSV.TARGET_OCCURRENCE_ID) SOURCE_TAXON_NAME(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_NAME) TARGET_INSTITUTION_CODE(org.eol.globi.data.DatasetImporterForTSV.TARGET_INSTITUTION_CODE) LOCALITY_NAME(org.eol.globi.data.DatasetImporterForTSV.LOCALITY_NAME) REFERENCE_ID(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_ID) SOURCE_COLLECTION_CODE(org.eol.globi.data.DatasetImporterForTSV.SOURCE_COLLECTION_CODE) LocationNode(org.eol.globi.domain.LocationNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) List(java.util.List) SOURCE_COLLECTION_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_COLLECTION_ID) SOURCE_TAXON_SPECIFIC_EPITHET(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_SPECIFIC_EPITHET) Assert.assertFalse(org.junit.Assert.assertFalse) SOURCE_CATALOG_NUMBER(org.eol.globi.data.DatasetImporterForTSV.SOURCE_CATALOG_NUMBER) SOURCE_TAXON_PATH(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_PATH) TARGET_COLLECTION_CODE(org.eol.globi.data.DatasetImporterForTSV.TARGET_COLLECTION_CODE) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) SpecimenNode(org.eol.globi.domain.SpecimenNode) TARGET_BODY_PART_NAME(org.eol.globi.data.DatasetImporterForTSV.TARGET_BODY_PART_NAME) DATASET_CITATION(org.eol.globi.data.DatasetImporterForTSV.DATASET_CITATION) SOURCE_TAXON_RANK(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_RANK) DateUtil(org.eol.globi.util.DateUtil) LogContext(org.eol.globi.domain.LogContext) COLLECTION_ID(org.eol.globi.domain.PropertyAndValueDictionary.COLLECTION_ID) OCCURRENCE_ID(org.eol.globi.domain.PropertyAndValueDictionary.OCCURRENCE_ID) TARGET_CATALOG_NUMBER(org.eol.globi.data.DatasetImporterForTSV.TARGET_CATALOG_NUMBER) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RelTypes(org.eol.globi.domain.RelTypes) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) SOURCE_SEX_NAME(org.eol.globi.data.DatasetImporterForTSV.SOURCE_SEX_NAME) SOURCE_BODY_PART_NAME(org.eol.globi.data.DatasetImporterForTSV.SOURCE_BODY_PART_NAME) SOURCE_TAXON_PATH_NAMES(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_PATH_NAMES) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CATALOG_NUMBER(org.eol.globi.domain.PropertyAndValueDictionary.CATALOG_NUMBER) StringStartsWith.startsWith(org.hamcrest.core.StringStartsWith.startsWith) SOURCE_OCCURRENCE_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_OCCURRENCE_ID) ARGUMENT_TYPE_ID(org.eol.globi.data.DatasetImporterForTSV.ARGUMENT_TYPE_ID) SOURCE_INSTITUTION_CODE(org.eol.globi.data.DatasetImporterForTSV.SOURCE_INSTITUTION_CODE) SOURCE_LIFE_STAGE_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_LIFE_STAGE_ID) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) StudyNode(org.eol.globi.domain.StudyNode) TARGET_TAXON_NAME(org.eol.globi.service.TaxonUtil.TARGET_TAXON_NAME) TARGET_COLLECTION_ID(org.eol.globi.data.DatasetImporterForTSV.TARGET_COLLECTION_ID) INSTITUTION_CODE(org.eol.globi.domain.PropertyAndValueDictionary.INSTITUTION_CODE) SOURCE_TAXON_PATH_IDS(org.eol.globi.service.TaxonUtil.SOURCE_TAXON_PATH_IDS) LOCALITY_ID(org.eol.globi.data.DatasetImporterForTSV.LOCALITY_ID) SOURCE_SEX_ID(org.eol.globi.data.DatasetImporterForTSV.SOURCE_SEX_ID) DatasetImporterForTSV(org.eol.globi.data.DatasetImporterForTSV) GeoNamesService(org.eol.globi.service.GeoNamesService) TARGET_SEX_NAME(org.eol.globi.data.DatasetImporterForTSV.TARGET_SEX_NAME) Relationship(org.neo4j.graphdb.Relationship) TreeMap(java.util.TreeMap) NodeFactoryException(org.eol.globi.data.NodeFactoryException) DECIMAL_LATITUDE(org.eol.globi.data.DatasetImporterForTSV.DECIMAL_LATITUDE) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) REFERENCE_DOI(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_DOI) TARGET_BODY_PART_ID(org.eol.globi.data.DatasetImporterForTSV.TARGET_BODY_PART_ID) TaxonNode(org.eol.globi.domain.TaxonNode) REFERENCE_CITATION(org.eol.globi.data.DatasetImporterForTSV.REFERENCE_CITATION) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodeFactoryException(org.eol.globi.data.NodeFactoryException) TreeMap(java.util.TreeMap) SpecimenNode(org.eol.globi.domain.SpecimenNode) Date(java.util.Date) RelationshipListener(org.eol.globi.util.RelationshipListener)

Example 7 with RelationshipListener

use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.

the class StudyTest method populateStudy.

@Test
public void populateStudy() throws NodeFactoryException {
    Study study = nodeFactory.createStudy(new StudyImpl("Our first study", null, null));
    taxonIndex.getOrCreateTaxon(new TaxonImpl(CARCHARODON_CARCHARIAS, null));
    Specimen goldFish = nodeFactory.createSpecimen(study, new TaxonImpl(CARASSIUS_AURATUS_AURATUS, null));
    Specimen shark = nodeFactory.createSpecimen(study, new TaxonImpl(CARCHARODON_CARCHARIAS, null));
    Specimen fuzzyShark = nodeFactory.createSpecimen(study, new TaxonImpl(CARCHARODON, null));
    shark.ate(goldFish);
    fuzzyShark.ate(goldFish);
    Location bolinasBay = nodeFactory.getOrCreateLocation(new LocationImpl(12.2d, 12.1d, -100.0d, null));
    shark.caughtIn(bolinasBay);
    Season winter = nodeFactory.createSeason("winter");
    shark.caughtDuring(winter);
    shark.setLengthInMm(1.2d);
    resolveNames();
    StudyNode foundStudy = getStudySingleton(getGraphDb());
    assertEquals(study.getTitle(), foundStudy.getTitle());
    RelationshipListener handler = rel -> {
        Specimen specimen = new SpecimenNode(rel.getEndNode());
        Relationship caughtDuringRel = rel.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CAUGHT_DURING), Direction.OUTGOING);
        if (caughtDuringRel != null) {
            Node seasonNode = caughtDuringRel.getEndNode();
            if (seasonNode != null && seasonNode.getProperty(SeasonNode.TITLE).equals("winter")) {
                Relationship next = NodeUtil.getClassifications(specimen).iterator().next();
                Node endNode = next.getEndNode();
                String speciesName = (String) endNode.getProperty("name");
                assertEquals(CARCHARODON_CARCHARIAS, speciesName);
                assertEquals(new Double(-100.0d), specimen.getSampleLocation().getAltitude());
                assertEquals(new Double(1.2d), specimen.getLengthInMm());
            } else {
                fail("expected to findNamespaces a specimen");
            }
        } else if (specimen.equals(goldFish)) {
            Node genusNode = NodeUtil.getClassifications(specimen).iterator().next().getEndNode();
            assertEquals(CARASSIUS_AURATUS_AURATUS, genusNode.getProperty("name"));
        } else if (specimen.equals(fuzzyShark)) {
            Node genusNode = NodeUtil.getClassifications(specimen).iterator().next().getEndNode();
            assertEquals(CARCHARODON, genusNode.getProperty("name"));
        } else {
            fail("found unexpected specimen [" + specimen + "] in study");
        }
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(foundStudy.getUnderlyingNode()), handler);
}
Also used : NodeUtil(org.eol.globi.util.NodeUtil) Relationship(org.neo4j.graphdb.Relationship) NodeFactoryException(org.eol.globi.data.NodeFactoryException) RelationshipListener(org.eol.globi.util.RelationshipListener) Direction(org.neo4j.graphdb.Direction) Test(org.junit.Test) Assert.fail(org.junit.Assert.fail) GraphDBTestCase(org.eol.globi.data.GraphDBTestCase) Node(org.neo4j.graphdb.Node) Assert.assertEquals(org.junit.Assert.assertEquals) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Node(org.neo4j.graphdb.Node) RelationshipListener(org.eol.globi.util.RelationshipListener) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 8 with RelationshipListener

use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForBlewettTest method importLines.

@Test
public void importLines() throws StudyImporterException {
    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 = (studyResource, characterEncoding) -> {
        LabeledCSVParser parser;
        if (studyResource.toString().contains("abundance")) {
            parser = preyPredatorFactory.createParser(studyResource, characterEncoding);
        } else {
            parser = dateLocationFactory.createParser(studyResource, characterEncoding);
        }
        return parser;
    };
    DatasetImporter importer = new StudyImporterTestFactory(testFactory, nodeFactory).instantiateImporter(DatasetImporterForBlewett.class);
    importStudy(importer);
    StudyNode study = getStudySingleton(getGraphDb());
    AtomicBoolean success = new AtomicBoolean(false);
    RelationshipListener handler1 = collectedRel -> {
        Date unixEpochProperty = null;
        try {
            unixEpochProperty = nodeFactory.getUnixEpochProperty(new SpecimenNode(collectedRel.getEndNode()));
        } catch (NodeFactoryException e) {
            fail(e.getMessage());
        }
        assertThat(unixEpochProperty, is(not(nullValue())));
        String actual = dateToString(unixEpochProperty);
        Node predatorNode = collectedRel.getEndNode();
        if (StringUtils.equals(actual, "2000-03-01T10:55:00.000-06:00") && predatorNode.hasProperty(SpecimenConstant.LIFE_STAGE_LABEL) && predatorNode.hasRelationship(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING)) {
            assertThat(predatorNode.getProperty(SpecimenConstant.LIFE_STAGE_LABEL), is("post-juvenile adult stage"));
            assertThat(predatorNode.getProperty(SpecimenConstant.LIFE_STAGE_ID), is("UBERON:0000113"));
            Node predatorTaxonNode = predatorNode.getRelationships(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING).iterator().next().getEndNode();
            assertThat(predatorTaxonNode.getProperty(PropertyAndValueDictionary.NAME), is("Centropomus undecimalis"));
            Set<String> preyNames = new HashSet<>();
            Iterable<Relationship> ate = predatorNode.getRelationships(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING);
            for (Relationship preyRels : ate) {
                Node preyNode = preyRels.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())));
                preyNames.add((String) taxonNode.getProperty(PropertyAndValueDictionary.NAME));
            }
            assertThat(preyNames, hasItem("Lag rhomboides"));
            success.set(true);
        }
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler1);
    assertTrue(success.get());
    success.set(false);
    RelationshipListener handler2 = collectedRel -> {
        Node predatorNode = collectedRel.getEndNode();
        if (predatorNode.hasProperty(SpecimenConstant.LENGTH_IN_MM) && (Double) predatorNode.getProperty(SpecimenConstant.LENGTH_IN_MM) == 548.0) {
            Iterable<Relationship> ate = predatorNode.getRelationships(NodeUtil.asNeo4j(InteractType.ATE), Direction.OUTGOING);
            assertThat(ate.iterator().hasNext(), is(false));
            Location location = null;
            try {
                location = nodeFactory.findLocation(new LocationImpl(26.651833, -82.103833, 0.0, null));
            } catch (NodeFactoryException e) {
                fail(e.getMessage());
            }
            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));
            success.set(true);
        }
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler2);
    assertTrue(success.get());
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) NodeUtil(org.eol.globi.util.NodeUtil) Location(org.eol.globi.domain.Location) Date(java.util.Date) Direction(org.neo4j.graphdb.Direction) LocationImpl(org.eol.globi.domain.LocationImpl) CoreMatchers.not(org.hamcrest.CoreMatchers.not) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TermLookupService(org.eol.globi.service.TermLookupService) StringUtils(org.apache.commons.lang3.StringUtils) RelTypes(org.eol.globi.domain.RelTypes) Node(org.neo4j.graphdb.Node) InteractType(org.eol.globi.domain.InteractType) HashSet(java.util.HashSet) Calendar(java.util.Calendar) RelationshipListener(org.eol.globi.util.RelationshipListener) Is.is(org.hamcrest.core.Is.is) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ParseException(java.text.ParseException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Taxon(org.eol.globi.domain.Taxon) ISODateTimeFormat(org.joda.time.format.ISODateTimeFormat) Iterator(java.util.Iterator) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) UberonLookupService(org.eol.globi.taxon.UberonLookupService) Assert.assertNotNull(org.junit.Assert.assertNotNull) DateTime(org.joda.time.DateTime) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) StudyNode(org.eol.globi.domain.StudyNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Relationship(org.neo4j.graphdb.Relationship) Matchers.hasItem(org.hamcrest.Matchers.hasItem) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) SpecimenNode(org.eol.globi.domain.SpecimenNode) HashSet(java.util.HashSet) Set(java.util.Set) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) SpecimenNode(org.eol.globi.domain.SpecimenNode) Date(java.util.Date) StudyNode(org.eol.globi.domain.StudyNode) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Relationship(org.neo4j.graphdb.Relationship) Iterator(java.util.Iterator) LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location) Test(org.junit.Test)

Example 9 with RelationshipListener

use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForCookTest method importFirstFewLines.

@Test
public void importFirstFewLines() throws IOException, NodeFactoryException, StudyImporterException {
    String firstFiveLines = "\"Date\",\"Individual\",\"Fish Length\",\"Infected\",\"Iso 1\",\"Iso 2\",\"Iso 3\",\"Iso 4 \",\"Iso 5\",\"Iso #\",,\n" + "8/10/2010,22,15.6,1,\"NA\",\"NA\",0,0,0,2,,\"Notes: All fish collected were Atlantic Croaker (Micropogonias undulatus) and measured in total length (cm). Isopods collected were Cymothoa excisa. For the Infected column 1= infected and 0= not infected. Numbers for the isopods are total length in cm and the Iso# represents the number of isopods found per fish. \"\n" + "8/10/2010,1,14.7,1,1.6,0.67,0,0,0,2,,\n" + "8/10/2010,5,14.2,1,1.53,0.7,0,0,0,2,,\n" + "8/10/2010,2,13.2,1,1.42,0.71,0.52,0.45,0,4,,\n";
    DatasetImporterForCook importer = new DatasetImporterForCook(new TestParserFactory(firstFiveLines), nodeFactory);
    importStudy(importer);
    StudyNode study = getStudySingleton(getGraphDb());
    Taxon hostTaxon = taxonIndex.findTaxonByName("Micropogonias undulatus");
    assertThat(hostTaxon, is(notNullValue()));
    Taxon parasiteTaxon = taxonIndex.findTaxonByName("Cymothoa excisa");
    assertThat(parasiteTaxon, is(notNullValue()));
    assertThat("missing location", nodeFactory.findLocation(new LocationImpl(27.85, -(97.0 + 8.0 / 60.0), -3.0, null)), is(notNullValue()));
    AtomicInteger count = new AtomicInteger(0);
    AtomicBoolean foundFirstHost = new AtomicBoolean(false);
    RelationshipListener handler = relationship -> {
        assertThat(relationship.getProperty(SpecimenConstant.EVENT_DATE), is(notNullValue()));
        Node specimen = relationship.getEndNode();
        if (specimen.hasProperty(SpecimenConstant.LENGTH_IN_MM)) {
            Object property = specimen.getProperty(SpecimenConstant.LENGTH_IN_MM);
            if (new Double(156.0).equals(property)) {
                assertTaxonClassification(specimen, ((NodeBacked) hostTaxon).getUnderlyingNode());
                foundFirstHost.set(true);
                Iterable<Relationship> parasiteRel = specimen.getRelationships(Direction.INCOMING, NodeUtil.asNeo4j(InteractType.PARASITE_OF));
                for (Relationship rel : parasiteRel) {
                    Node parasite = rel.getStartNode();
                    assertThat(parasite.hasProperty(SpecimenConstant.LENGTH_IN_MM), is(false));
                    assertTaxonClassification(parasite, ((NodeBacked) parasiteTaxon).getUnderlyingNode());
                }
            }
        }
        count.incrementAndGet();
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study.getUnderlyingNode()), handler);
    assertThat(count.get(), is(14));
    assertThat(foundFirstHost.get(), is(true));
}
Also used : Taxon(org.eol.globi.domain.Taxon) NodeBacked(org.eol.globi.domain.NodeBacked) NodeUtil(org.eol.globi.util.NodeUtil) Direction(org.neo4j.graphdb.Direction) LocationImpl(org.eol.globi.domain.LocationImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) IOException(java.io.IOException) StudyNode(org.eol.globi.domain.StudyNode) RelTypes(org.eol.globi.domain.RelTypes) Node(org.neo4j.graphdb.Node) InteractType(org.eol.globi.domain.InteractType) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Relationship(org.neo4j.graphdb.Relationship) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) Is.is(org.hamcrest.core.Is.is) SpecimenConstant(org.eol.globi.domain.SpecimenConstant) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Taxon(org.eol.globi.domain.Taxon) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) RelationshipListener(org.eol.globi.util.RelationshipListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodeBacked(org.eol.globi.domain.NodeBacked) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Relationship(org.neo4j.graphdb.Relationship) LocationImpl(org.eol.globi.domain.LocationImpl) Test(org.junit.Test)

Example 10 with RelationshipListener

use of org.eol.globi.util.RelationshipListener in project eol-globi-data by jhpoelen.

the class DatasetImporterForBioInfoTest method parseSomeRelations.

@Test
public void parseSomeRelations() throws IOException, StudyImporterException {
    assertThat(taxonIndex.findTaxonByName("Homo sapiens"), is(nullValue()));
    LabeledCSVParser labeledCSVParser = createParser(RELATIONS_STRING);
    DatasetImporterForBioInfo importer = new DatasetImporterForBioInfo(new ParserFactoryLocal(), nodeFactory);
    importer.createRelations(labeledCSVParser, new TreeMap<String, String>() {

        {
            put("60527", "citation A");
            put("60536", "citation B");
        }
    }, new TreeMap<>());
    resolveNames();
    StudyImpl study2 = new StudyImpl(TaxonomyProvider.BIO_INFO + "ref:60536");
    study2.setExternalId("http://bioinfo.org.uk/html/b60536.htm");
    Study study = nodeFactory.findStudy(study2);
    assertNotNull(study);
    assertThat(study.getExternalId(), is("http://bioinfo.org.uk/html/b60536.htm"));
    assertNull(nodeFactory.findStudy(new StudyImpl(TaxonomyProvider.BIO_INFO + "ref:bla")));
    StudyImpl study3 = new StudyImpl(TaxonomyProvider.BIO_INFO + "ref:60527");
    study3.setExternalId("http://bioinfo.org.uk/html/b60527.htm");
    StudyNode study1 = (StudyNode) nodeFactory.findStudy(study3);
    assertThat(study1.getCitation(), is("citation A"));
    assertThat(study1, is(notNullValue()));
    List<Node> specimenList = new ArrayList<Node>();
    RelationshipListener handler = relationship -> {
        assertThat(relationship.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING), is(notNullValue()));
        assertThat(relationship.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(InteractType.INTERACTS_WITH), Direction.OUTGOING), is(notNullValue()));
        assertThat(relationship.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(InteractType.INTERACTS_WITH), Direction.INCOMING), is(notNullValue()));
        assertThat(relationship.getEndNode().getSingleRelationship(NodeUtil.asNeo4j(InteractType.INTERACTS_WITH), Direction.INCOMING), is(notNullValue()));
        specimenList.add(relationship.getEndNode());
    };
    NodeUtil.handleCollectedRelationships(new NodeTypeDirection(study1.getUnderlyingNode()), handler);
    assertThat(specimenList.size(), is(16));
    Relationship classifiedAs = specimenList.get(0).getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING);
    assertThat(classifiedAs, is(notNullValue()));
    assertThat((String) classifiedAs.getEndNode().getProperty(PropertyAndValueDictionary.EXTERNAL_ID), startsWith("NBN:NBNSYS"));
    assertThat(specimenList.get(1).getSingleRelationship(NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS), Direction.OUTGOING), is(notNullValue()));
    assertThat(taxonIndex.findTaxonById(TaxonomyProvider.NBN.getIdPrefix() + "NBNSYS0000024889"), is(notNullValue()));
    assertThat(taxonIndex.findTaxonById(TaxonomyProvider.NBN.getIdPrefix() + "NBNSYS0000024891"), is(notNullValue()));
}
Also used : CSVTSVUtil(org.eol.globi.util.CSVTSVUtil) CoreMatchers(org.hamcrest.CoreMatchers) ResourceIterator(org.neo4j.graphdb.ResourceIterator) LogContext(org.eol.globi.domain.LogContext) NodeUtil(org.eol.globi.util.NodeUtil) Direction(org.neo4j.graphdb.Direction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StringUtils(org.apache.commons.lang3.StringUtils) RelTypes(org.eol.globi.domain.RelTypes) StudyImpl(org.eol.globi.domain.StudyImpl) Node(org.neo4j.graphdb.Node) InteractType(org.eol.globi.domain.InteractType) ArrayList(java.util.ArrayList) IsNull.nullValue(org.hamcrest.core.IsNull.nullValue) RelationshipListener(org.eol.globi.util.RelationshipListener) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) StringStartsWith.startsWith(org.hamcrest.core.StringStartsWith.startsWith) TaxonomyProvider(org.eol.globi.domain.TaxonomyProvider) Taxon(org.eol.globi.domain.Taxon) Result(org.neo4j.graphdb.Result) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) StudyNode(org.eol.globi.domain.StudyNode) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) List(java.util.List) Relationship(org.neo4j.graphdb.Relationship) Assert.assertNull(org.junit.Assert.assertNull) StringReader(java.io.StringReader) TreeMap(java.util.TreeMap) PropertyAndValueDictionary(org.eol.globi.domain.PropertyAndValueDictionary) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) SpecimenNode(org.eol.globi.domain.SpecimenNode) Study(org.eol.globi.domain.Study) Study(org.eol.globi.domain.Study) NodeTypeDirection(org.eol.globi.util.NodeTypeDirection) Node(org.neo4j.graphdb.Node) StudyNode(org.eol.globi.domain.StudyNode) SpecimenNode(org.eol.globi.domain.SpecimenNode) StudyImpl(org.eol.globi.domain.StudyImpl) ArrayList(java.util.ArrayList) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) StudyNode(org.eol.globi.domain.StudyNode) RelationshipListener(org.eol.globi.util.RelationshipListener) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Aggregations

NodeTypeDirection (org.eol.globi.util.NodeTypeDirection)22 RelationshipListener (org.eol.globi.util.RelationshipListener)22 Node (org.neo4j.graphdb.Node)22 Relationship (org.neo4j.graphdb.Relationship)22 NodeUtil (org.eol.globi.util.NodeUtil)21 StudyNode (org.eol.globi.domain.StudyNode)20 Direction (org.neo4j.graphdb.Direction)19 Test (org.junit.Test)18 RelTypes (org.eol.globi.domain.RelTypes)17 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 InteractType (org.eol.globi.domain.InteractType)14 Is.is (org.hamcrest.core.Is.is)14 IOException (java.io.IOException)13 Assert.assertTrue (org.junit.Assert.assertTrue)13 SpecimenConstant (org.eol.globi.domain.SpecimenConstant)12 SpecimenNode (org.eol.globi.domain.SpecimenNode)12 List (java.util.List)11 TreeMap (java.util.TreeMap)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 TaxonNode (org.eol.globi.domain.TaxonNode)11