use of gov.nih.nci.ctd2.dashboard.model.Evidence in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method summarizeECO.
private Summary summarizeECO() {
Session session = getSession();
@SuppressWarnings("unchecked") org.hibernate.query.Query<BigInteger> query = session.createNativeQuery("SELECT COUNT(*) FROM submission" + " JOIN observation_template ON submission.observationTemplate_id=observation_template.id" + " WHERE ecoCode <> ''");
BigInteger submissions = query.getSingleResult();
String tierQuery = "SELECT tier, COUNT(*) FROM observation" + " JOIN submission ON observation.submission_id=submission.id" + " JOIN observation_template ON submission.observationTemplate_id=observation_template.id" + " WHERE ecoCode <> ''" + " GROUP BY tier";
@SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> query2 = session.createNativeQuery(tierQuery);
int[] tierCount = new int[3];
List<Object[]> result = query2.list();
for (Object[] obj : result) {
Integer tier = (Integer) obj[0];
BigInteger count = (BigInteger) obj[1];
tierCount[tier - 1] = count.intValue();
}
session.close();
return new Summary("Evidence Types", submissions.intValue(), tierCount[0], tierCount[1], tierCount[2]);
}
use of gov.nih.nci.ctd2.dashboard.model.Evidence in project nci-ctd2-dashboard by CBIIT.
the class ControlledVocabularyPerColumnFieldSetMapper method mapFieldSet.
public ControlledVocabulary mapFieldSet(FieldSet fieldSet) throws BindException {
String templateName = fieldSet.readString(TEMPLATE_NAME);
ObservationTemplate observationTemplate = observationTemplateNameMap.get(templateName);
if (observationTemplate == null)
return new ControlledVocabulary(null, null, null);
if (subjectRoleCache == null)
subjectRoleCache = new HashMap<String, SubjectRole>();
if (evidenceRoleCache == null)
evidenceRoleCache = new HashMap<String, EvidenceRole>();
String subject = fieldSet.readString(SUBJECT);
String evidence = fieldSet.readString(EVIDENCE);
if (subject.length() > 0) {
String subjectRoleStr = fieldSet.readString(ROLE);
SubjectRole subjectRole = subjectRoleCache.get(subjectRoleStr);
if (subjectRole == null) {
subjectRole = dashboardFactory.create(SubjectRole.class);
subjectRole.setDisplayName(subjectRoleStr);
subjectRoleCache.put(subjectRoleStr, subjectRole);
}
ObservedSubjectRole observedSubjectRole = dashboardFactory.create(ObservedSubjectRole.class);
observedSubjectRole.setSubjectRole(subjectRole);
observedSubjectRole.setColumnName(fieldSet.readString(COLUMN_NAME));
observedSubjectRole.setDisplayText(fieldSet.readString(DISPLAY_TEXT));
observedSubjectRole.setObservationTemplate(observationTemplate);
return new ControlledVocabulary(observationTemplate, subjectRole, observedSubjectRole);
} else if (evidence.length() > 0) {
String evidenceRoleStr = fieldSet.readString(ROLE);
EvidenceRole evidenceRole = evidenceRoleCache.get(evidenceRoleStr);
if (evidenceRole == null) {
evidenceRole = dashboardFactory.create(EvidenceRole.class);
evidenceRole.setDisplayName(evidenceRoleStr);
evidenceRoleCache.put(evidenceRoleStr, evidenceRole);
}
ObservedEvidenceRole observedEvidenceRole = dashboardFactory.create(ObservedEvidenceRole.class);
observedEvidenceRole.setEvidenceRole(evidenceRole);
observedEvidenceRole.setColumnName(fieldSet.readString(COLUMN_NAME));
observedEvidenceRole.setDisplayText(fieldSet.readString(DISPLAY_TEXT));
observedEvidenceRole.setObservationTemplate(observationTemplate);
observedEvidenceRole.setAttribute(getObservedEvidenceRoleAttribute(fieldSet.readString(MIME_TYPE), fieldSet.readString(NUMERIC_UNITS)));
return new ControlledVocabulary(observationTemplate, evidenceRole, observedEvidenceRole);
}
return new ControlledVocabulary(null, null, null);
}
use of gov.nih.nci.ctd2.dashboard.model.Evidence in project nci-ctd2-dashboard by CBIIT.
the class ObservationDataWriter method write.
public void write(List<? extends ObservationData> items) throws Exception {
// calls) (2) there is at least one observation in each call
if (items.size() == 0) {
// this might happen when some suject is rejected
log.debug("no item");
return;
}
final Submission submission = items.get(0).observation.getSubmission();
final String submissionName = submission.getDisplayName();
StableURL stableURL = new StableURL();
synchronized (submission) {
log.debug("[" + ++counter + "]SUBMISSION " + submissionName + ": " + items.size() + " observation(s)");
final String submissionCacheKey = submissionName + new SimpleDateFormat("yyyy.MM.dd").format(submission.getSubmissionDate()) + submission.getObservationTemplate().getDisplayName();
if (!submissionCache.contains(submissionCacheKey)) {
submission.setStableURL(stableURL.createURLWithPrefix("submission", submissionName));
dashboardDao.save(submission);
submissionCache.add(submissionCacheKey);
observationIndex.put(submissionName, 0);
}
}
List<Observation> observations = new ArrayList<Observation>();
List<Evidence> evidences = new ArrayList<Evidence>();
List<ObservedSubject> observedSubjects = new ArrayList<ObservedSubject>();
List<ObservedEvidence> observedEvidences = new ArrayList<ObservedEvidence>();
for (ObservationData observationData : items) {
Observation observation = observationData.observation;
int index = observationIndex.get(submissionName);
observation.setStableURL(stableURL.createURLWithPrefix("observation", submissionName) + "-" + index);
observations.add(observation);
observationIndex.put(submissionName, index + 1);
for (DashboardEntity e : observationData.evidence) {
evidences.add((Evidence) e);
}
for (DashboardEntity e : observationData.observedEntities) {
String className = e.getClass().getName();
switch(className) {
case "gov.nih.nci.ctd2.dashboard.impl.ObservedSubjectImpl":
observedSubjects.add((ObservedSubject) e);
break;
case "gov.nih.nci.ctd2.dashboard.impl.ObservedEvidenceImpl":
observedEvidences.add((ObservedEvidence) e);
break;
default:
log.error("unexpected type " + className);
}
}
}
// use a smaller batch size to prevent 'lock wait timeout'
int batchSize = 100;
log.debug("observations to write " + observations.size());
dashboardDao.batchSave(observations, batchSize);
log.debug("observedSubjects to write " + observedSubjects.size());
dashboardDao.batchSave(observedSubjects, batchSize);
log.debug("evidences to write " + evidences.size());
dashboardDao.batchSave(evidences, batchSize);
log.debug("observedEvidences to write " + observedEvidences.size());
dashboardDao.batchSave(observedEvidences, batchSize);
log.debug("ALL WRITTEN: " + submissionName);
}
use of gov.nih.nci.ctd2.dashboard.model.Evidence in project nci-ctd2-dashboard by CBIIT.
the class BrowseAPI method getSubmission.
@Transactional
@RequestMapping(value = "{subjectClass}/{subjectName}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getSubmission(@PathVariable String subjectClass, @PathVariable String subjectName, @RequestParam(value = "center", required = false, defaultValue = "") String center, @RequestParam(value = "role", required = false, defaultValue = "") String role, @RequestParam(value = "tier", required = false, defaultValue = "") String tiers, @RequestParam(value = "maximum", required = false, defaultValue = "") String maximum) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
SubjectResponse.Filter filter = SubjectResponse.createFilter(center, role, tiers, maximum);
DashboardEntity subject = null;
if (subjectClass.equalsIgnoreCase("evidence") || subjectClass.equalsIgnoreCase("eco")) {
/* API spec asks for Evidence but stable URL uses eco */
var obj = dashboardDao.getEntityByStableURL("eco", "eco/" + subjectName);
if (obj instanceof ECOTerm) {
subject = (ECOTerm) obj;
} else {
log.error("unexpected subject type:" + obj.getClass().getName());
}
} else if (subjectClass.equalsIgnoreCase("gene")) {
List<Gene> genes = dashboardDao.findGenesBySymbol(subjectName);
if (genes.size() > 0) {
Gene gene = genes.get(0);
List<Protein> p = dashboardDao.findProteinByGene(gene);
Xref xref = new XrefImpl();
xref.setDatabaseId(p.get(0).getUniprotId());
xref.setDatabaseName("UniProt");
gene.getXrefs().add(xref);
subject = gene;
}
} else {
var obj = dashboardDao.getEntityByStableURL(subjectClass, subjectClass + "/" + subjectName);
if (obj instanceof Subject) {
subject = (Subject) obj;
} else {
log.error("unexpected subject type: " + (obj == null ? null : obj.getClass().getName()));
}
}
if (subject == null) {
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
SubjectResponse subjectResponse = SubjectResponse.createInstance(subject, filter, dashboardDao);
log.debug("ready to serialize");
JSONSerializer jsonSerializer = CTD2Serializer.createJSONSerializer();
String json = "{}";
try {
json = jsonSerializer.deepSerialize(subjectResponse);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}
return new ResponseEntity<String>(json, headers, HttpStatus.OK);
}
use of gov.nih.nci.ctd2.dashboard.model.Evidence in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method createObservedEvidenceInfo.
private List<EvidenceItem> createObservedEvidenceInfo(Integer observationId) {
Session session = getSession();
@SuppressWarnings("unchecked") org.hibernate.query.Query<Object[]> query = session.createNativeQuery("SELECT d2.displayName AS type, observed_evidence_role.displayText AS description, evidence.id, columnName" + " FROM observed_evidence join evidence on observed_evidence.evidence_id=evidence.id" + " JOIN observed_evidence_role ON observed_evidence.observedEvidenceRole_id=observed_evidence_role.id" + " JOIN evidence_role ON observed_evidence_role.evidenceRole_id=evidence_role.id" + " JOIN dashboard_entity AS d2 ON evidence_role.id=d2.id WHERE observation_id=" + observationId);
List<EvidenceItem> list = new ArrayList<EvidenceItem>();
List<Object[]> evidences = query.list();
for (Object[] obj : evidences) {
String type = (String) obj[0];
String description = (String) obj[1];
Integer evidenceId = (Integer) obj[2];
Evidence evidence = getEntityById(Evidence.class, evidenceId);
String evidenceName = evidence.getDisplayName();
String columnName = (String) obj[3];
EvidenceItem evidenceItem = new EvidenceItem(evidence, type, description, evidenceName, columnName);
list.add(evidenceItem);
}
session.close();
return list;
}
Aggregations