Search in sources :

Example 31 with Study

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

the class StudyImporterForGoMexSI2 method addObservations.

private void addObservations(Map<String, Map<String, String>> predatorIdToPredatorSpecimen, Map<String, Study> refIdToStudyMap, Map<String, List<Map<String, String>>> predatorUIToPreyLists, Study metaStudy) throws StudyImporterException {
    String locationResource = getLocationsResourcePath();
    try {
        TermLookupService cmecsService = new CMECSService();
        LabeledCSVParser parser = parserFactory.createParser(locationResource, CharsetConstant.UTF8);
        while (parser.getLine() != null) {
            String refId = getMandatoryValue(locationResource, parser, "DATA_ID");
            if (!refIdToStudyMap.containsKey(refId)) {
                getLogger().warn(metaStudy, "failed to find study for ref id [" + refId + "] on related to observation location in [" + locationResource + ":" + parser.getLastLineNumber() + "]");
            } else {
                Study study = refIdToStudyMap.get(refId);
                String specimenId = getMandatoryValue(locationResource, parser, "PRED_ID");
                Location location = parseLocation(locationResource, parser);
                Location locationNode = nodeFactory.getOrCreateLocation(location);
                enrichLocation(metaStudy, locationResource, cmecsService, parser, locationNode);
                String predatorId = refId + specimenId;
                Map<String, String> predatorProperties = predatorIdToPredatorSpecimen.get(predatorId);
                if (predatorProperties == null) {
                    getLogger().warn(study, "failed to lookup predator [" + refId + ":" + specimenId + "] for location at [" + locationResource + ":" + (parser.getLastLineNumber() + 1) + "]");
                } else {
                    addObservation(predatorUIToPreyLists, parser, study, locationNode, predatorId, predatorProperties);
                }
            }
        }
    } catch (IOException e) {
        throw new StudyImporterException("failed to open resource [" + locationResource + "]", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) TermLookupService(org.eol.globi.service.TermLookupService) LabeledCSVParser(com.Ostermiller.util.LabeledCSVParser) IOException(java.io.IOException) Location(org.eol.globi.domain.Location)

Example 32 with Study

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

the class NodeFactoryWithDatasetContextTest method getOrCreateStudy.

@Test
public void getOrCreateStudy() throws NodeFactoryException {
    NodeFactory factory = Mockito.mock(NodeFactory.class);
    Dataset dataset = new DatasetImpl("some/namespace", URI.create("some:uri"));
    NodeFactoryWithDatasetContext factoryWithDS = new NodeFactoryWithDatasetContext(factory, dataset);
    factoryWithDS.getOrCreateStudy(new StudyImpl("some title"));
    ArgumentCaptor<Study> argument = ArgumentCaptor.forClass(Study.class);
    verify(factory).getOrCreateStudy(argument.capture());
    assertEquals("globi:some/namespace", argument.getValue().getSourceId());
    assertEquals("some title", argument.getValue().getTitle());
}
Also used : Study(org.eol.globi.domain.Study) Dataset(org.eol.globi.service.Dataset) StudyImpl(org.eol.globi.domain.StudyImpl) DatasetImpl(org.eol.globi.service.DatasetImpl) Test(org.junit.Test)

Example 33 with Study

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

the class GraphExporterImpl method exportDataOntology.

private void exportDataOntology(List<Study> studies, String baseDir) throws StudyImporterException {
    try {
        ExporterRDF studyExporter = new ExporterRDF();
        OutputStreamWriter writer = openStream(baseDir + "globi.nq.gz");
        int total = studies.size();
        int count = 1;
        for (Study study : studies) {
            studyExporter.exportStudy(study, writer, true);
            if (count % 50 == 0) {
                LOG.info("added triples for [" + count + "] of [" + total + "] studies...");
            }
            count++;
        }
        LOG.info("adding triples for [" + total + "] of [" + total + "] studies.");
        LOG.info("writing nquads archive...");
        closeStream(baseDir + "globi.nq.gz", writer);
    } catch (IOException e) {
        throw new StudyImporterException("failed to export as owl", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImporterException(org.eol.globi.data.StudyImporterException)

Example 34 with Study

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

the class GraphExporterImpl method exportNames.

private void exportNames(List<Study> studies, String baseDir, StudyExporter exporter, String filename) throws StudyImporterException {
    try {
        String filePath = baseDir + filename;
        OutputStreamWriter writer = openStream(filePath);
        for (Study study : studies) {
            boolean includeHeader = studies.indexOf(study) == 0;
            exporter.exportStudy(study, writer, includeHeader);
        }
        closeStream(filePath, writer);
    } catch (IOException e) {
        throw new StudyImporterException("failed to export unmatched source taxa", e);
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImporterException(org.eol.globi.data.StudyImporterException)

Example 35 with Study

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

the class ExporterSiteMapForNames method export.

@Override
public void export(GraphDatabaseService graphDatabase, String baseDir) throws StudyImporterException {
    Set<String> names = new HashSet<String>();
    names.add("Homo sapiens");
    // just do it once
    final List<Study> allStudies = NodeUtil.findAllStudies(graphDatabase);
    for (Study allStudy : allStudies) {
        final Iterable<Relationship> specimens = NodeUtil.getSpecimens(allStudy);
        for (Relationship specimen : specimens) {
            final Iterable<Relationship> relationships = specimen.getEndNode().getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.CLASSIFIED_AS));
            if (relationships.iterator().hasNext()) {
                final Node endNode = relationships.iterator().next().getEndNode();
                final TaxonNode taxonNode = new TaxonNode(endNode);
                names.add(taxonNode.getName());
            }
        }
    }
    final String queryParamName = "interactionType=interactsWith&sourceTaxon=";
    final String siteMapLocation = "https://depot.globalbioticinteractions.org/snapshot/target/data/sitemap/names/";
    SiteMapUtils.generateSiteMap(names, baseDir, queryParamName, siteMapLocation);
}
Also used : Study(org.eol.globi.domain.Study) TaxonNode(org.eol.globi.domain.TaxonNode) Relationship(org.neo4j.graphdb.Relationship) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) HashSet(java.util.HashSet)

Aggregations

Study (org.eol.globi.domain.Study)141 Test (org.junit.Test)84 StudyImpl (org.eol.globi.domain.StudyImpl)61 Specimen (org.eol.globi.domain.Specimen)38 Relationship (org.neo4j.graphdb.Relationship)33 TaxonImpl (org.eol.globi.domain.TaxonImpl)32 IOException (java.io.IOException)30 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)24 Location (org.eol.globi.domain.Location)24 StringWriter (java.io.StringWriter)21 LocationImpl (org.eol.globi.domain.LocationImpl)20 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)16 Taxon (org.eol.globi.domain.Taxon)16 SpecimenNode (org.eol.globi.domain.SpecimenNode)14 Date (java.util.Date)13 DatasetImpl (org.eol.globi.service.DatasetImpl)13 Node (org.neo4j.graphdb.Node)12 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)10 InteractType (org.eol.globi.domain.InteractType)9