Search in sources :

Example 1 with StudyNodeListener

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

the class ReportGenerator method generateReportForStudySources.

void generateReportForStudySources(SourceHandler sourceHandler) {
    final Set<String> groupByKeys = new HashSet<String>();
    NodeUtil.findStudies(getGraphDb(), new StudyNodeListener() {

        @Override
        public void onStudy(StudyNode study) {
            String groupByKey = sourceHandler.parse(study);
            if (StringUtils.isNotBlank(groupByKey)) {
                groupByKeys.add(groupByKey);
            }
        }
    });
    for (final String groupByKey : groupByKeys) {
        final Set<Long> distinctTaxonIds = new HashSet<>();
        final Set<Long> distinctTaxonIdsNoMatch = new HashSet<>();
        final Counter counter = new Counter();
        final Counter studyCounter = new Counter();
        final Set<String> distinctSources = new HashSet<String>();
        final Set<String> distinctDatasets = new HashSet<String>();
        NodeUtil.findStudies(getGraphDb(), new StudyNodeListener() {

            @Override
            public void onStudy(StudyNode study) {
                if (sourceHandler.matches(study, groupByKey)) {
                    Iterable<Relationship> specimens = NodeUtil.getSpecimens(study);
                    countInteractionsAndTaxa(specimens, distinctTaxonIds, counter, distinctTaxonIdsNoMatch);
                    studyCounter.count();
                    distinctSources.add(study.getSource());
                    distinctDatasets.add(study.getSourceId());
                }
            }
        });
        Transaction tx = getGraphDb().beginTx();
        try {
            final Node node = getGraphDb().createNode();
            node.setProperty(sourceHandler.getGroupByKeyName(), groupByKey);
            node.setProperty(PropertyAndValueDictionary.COLLECTION, GLOBI_COLLECTION_NAME);
            node.setProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS, counter.getCount() / 2);
            node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA, distinctTaxonIds.size());
            node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH, distinctTaxonIdsNoMatch.size());
            node.setProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES, studyCounter.getCount());
            node.setProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES, distinctSources.size());
            node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS, distinctDatasets.size());
            getGraphDb().index().forNodes("reports").add(node, sourceHandler.getGroupByKeyName(), groupByKey);
            tx.success();
        } finally {
            tx.finish();
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) StudyNodeListener(org.eol.globi.util.StudyNodeListener) HashSet(java.util.HashSet) StudyNode(org.eol.globi.domain.StudyNode)

Example 2 with StudyNodeListener

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

the class ReportGenerator method generateReportForCollection.

void generateReportForCollection() {
    final Set<Long> distinctTaxonIds = new HashSet<Long>();
    final Set<Long> distinctTaxonIdsNoMatch = new HashSet<Long>();
    final Counter counter = new Counter();
    final Counter studyCounter = new Counter();
    final Set<String> distinctSources = new HashSet<String>();
    final Set<String> distinctDatasets = new HashSet<String>();
    NodeUtil.findStudies(getGraphDb(), new StudyNodeListener() {

        @Override
        public void onStudy(StudyNode study) {
            Iterable<Relationship> specimens = NodeUtil.getSpecimens(study);
            countInteractionsAndTaxa(specimens, distinctTaxonIds, counter, distinctTaxonIdsNoMatch);
            studyCounter.count();
            distinctSources.add(study.getSource());
            distinctDatasets.add(study.getSourceId());
        }
    });
    Transaction tx = getGraphDb().beginTx();
    try {
        final Node node = getGraphDb().createNode();
        node.setProperty(PropertyAndValueDictionary.COLLECTION, GLOBI_COLLECTION_NAME);
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_INTERACTIONS, counter.getCount() / 2);
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA, distinctTaxonIds.size());
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DISTINCT_TAXA_NO_MATCH, distinctTaxonIdsNoMatch.size());
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_STUDIES, studyCounter.getCount());
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_SOURCES, distinctSources.size());
        node.setProperty(PropertyAndValueDictionary.NUMBER_OF_DATASETS, distinctDatasets.size());
        getGraphDb().index().forNodes("reports").add(node, PropertyAndValueDictionary.COLLECTION, GLOBI_COLLECTION_NAME);
        tx.success();
    } finally {
        tx.finish();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) StudyNode(org.eol.globi.domain.StudyNode) Node(org.neo4j.graphdb.Node) TaxonNode(org.eol.globi.domain.TaxonNode) StudyNodeListener(org.eol.globi.util.StudyNodeListener) HashSet(java.util.HashSet) StudyNode(org.eol.globi.domain.StudyNode)

Example 3 with StudyNodeListener

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

the class ExporterAggregateUtil method exportDistinctInteractionsByStudy.

public static void exportDistinctInteractionsByStudy(Writer writer, GraphDatabaseService graphDatabase, RowWriter rowWriter) throws IOException {
    DB db = DBMaker.newMemoryDirectDB().compressionEnable().transactionDisable().make();
    final Map<Fun.Tuple3<Long, String, String>, List<String>> studyOccAggregate = db.createTreeMap("studyOccAggregate").make();
    NodeUtil.findStudies(graphDatabase, new StudyNodeListener() {

        @Override
        public void onStudy(StudyNode aStudy) {
            collectDistinctInteractions(aStudy, studyOccAggregate);
        }
    });
    for (Map.Entry<Fun.Tuple3<Long, String, String>, List<String>> distinctInteractions : studyOccAggregate.entrySet()) {
        rowWriter.writeRow(writer, new StudyNode(graphDatabase.getNodeById(distinctInteractions.getKey().a)), distinctInteractions.getKey().b, distinctInteractions.getKey().c, distinctInteractions.getValue());
    }
    db.close();
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) StudyNodeListener(org.eol.globi.util.StudyNodeListener) Map(java.util.Map) DB(org.mapdb.DB) StudyNode(org.eol.globi.domain.StudyNode)

Aggregations

StudyNode (org.eol.globi.domain.StudyNode)3 StudyNodeListener (org.eol.globi.util.StudyNodeListener)3 HashSet (java.util.HashSet)2 TaxonNode (org.eol.globi.domain.TaxonNode)2 Node (org.neo4j.graphdb.Node)2 Transaction (org.neo4j.graphdb.Transaction)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 DB (org.mapdb.DB)1