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();
}
}
}
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();
}
}
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();
}
Aggregations