Search in sources :

Example 1 with Evidence

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]);
}
Also used : BigInteger(java.math.BigInteger) BigInteger(java.math.BigInteger) Summary(gov.nih.nci.ctd2.dashboard.util.Summary) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Example 2 with Evidence

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);
}
Also used : HashMap(java.util.HashMap) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) SubjectRole(gov.nih.nci.ctd2.dashboard.model.SubjectRole) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) ObservedEvidenceRole(gov.nih.nci.ctd2.dashboard.model.ObservedEvidenceRole) ObservedEvidenceRole(gov.nih.nci.ctd2.dashboard.model.ObservedEvidenceRole) EvidenceRole(gov.nih.nci.ctd2.dashboard.model.EvidenceRole)

Example 3 with Evidence

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);
}
Also used : ObservedEvidence(gov.nih.nci.ctd2.dashboard.model.ObservedEvidence) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) StableURL(gov.nih.nci.ctd2.dashboard.util.StableURL) ArrayList(java.util.ArrayList) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) Evidence(gov.nih.nci.ctd2.dashboard.model.Evidence) ObservedEvidence(gov.nih.nci.ctd2.dashboard.model.ObservedEvidence) SimpleDateFormat(java.text.SimpleDateFormat) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject)

Example 4 with Evidence

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) SubjectResponse(gov.nih.nci.ctd2.dashboard.api.SubjectResponse) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) Xref(gov.nih.nci.ctd2.dashboard.model.Xref) ResponseEntity(org.springframework.http.ResponseEntity) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) Gene(gov.nih.nci.ctd2.dashboard.model.Gene) List(java.util.List) XrefImpl(gov.nih.nci.ctd2.dashboard.impl.XrefImpl) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Evidence

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;
}
Also used : EvidenceItem(gov.nih.nci.ctd2.dashboard.api.EvidenceItem) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) Evidence(gov.nih.nci.ctd2.dashboard.model.Evidence) ObservedEvidence(gov.nih.nci.ctd2.dashboard.model.ObservedEvidence) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session)

Aggregations

DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)2 Evidence (gov.nih.nci.ctd2.dashboard.model.Evidence)2 Gene (gov.nih.nci.ctd2.dashboard.model.Gene)2 ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)2 ObservedEvidence (gov.nih.nci.ctd2.dashboard.model.ObservedEvidence)2 Subject (gov.nih.nci.ctd2.dashboard.model.Subject)2 Xref (gov.nih.nci.ctd2.dashboard.model.Xref)2 StableURL (gov.nih.nci.ctd2.dashboard.util.StableURL)2 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 Session (org.hibernate.Session)2 FullTextSession (org.hibernate.search.FullTextSession)2 JSONSerializer (flexjson.JSONSerializer)1 EvidenceItem (gov.nih.nci.ctd2.dashboard.api.EvidenceItem)1 SubjectResponse (gov.nih.nci.ctd2.dashboard.api.SubjectResponse)1 XrefImpl (gov.nih.nci.ctd2.dashboard.impl.XrefImpl)1 AnimalModel (gov.nih.nci.ctd2.dashboard.model.AnimalModel)1 Annotation (gov.nih.nci.ctd2.dashboard.model.Annotation)1 CellSample (gov.nih.nci.ctd2.dashboard.model.CellSample)1 Compound (gov.nih.nci.ctd2.dashboard.model.Compound)1