Search in sources :

Example 1 with SubjectRole

use of gov.nih.nci.ctd2.dashboard.model.SubjectRole 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 2 with SubjectRole

use of gov.nih.nci.ctd2.dashboard.model.SubjectRole in project nci-ctd2-dashboard by CBIIT.

the class SubjectScorer method scoreAllRoles.

@Transactional
public void scoreAllRoles() {
    log.info("Removing all role-based scores...");
    List<SubjectWithSummaries> oldEntities = dashboardDao.findEntities(SubjectWithSummaries.class);
    for (SubjectWithSummaries subjectWithSummaries : oldEntities) {
        dashboardDao.delete(subjectWithSummaries);
    }
    log.info("Removed " + oldEntities.size() + " old scores.");
    log.info("Re-scoring all roles...");
    List<SubjectWithSummaries> subjectWithSummariesList = new ArrayList<SubjectWithSummaries>();
    List<SubjectRole> entities = dashboardDao.findEntities(SubjectRole.class);
    for (SubjectRole subjectRole : entities) {
        String keyword = subjectRole.getDisplayName();
        log.info("Scoring subject with role: " + keyword);
        HashMap<Subject, SubjectWithSummaries> subjectToSummaries = new HashMap<Subject, SubjectWithSummaries>();
        HashMap<Subject, HashSet<SubmissionCenter>> subjectToCenters = new HashMap<Subject, HashSet<SubmissionCenter>>();
        HashMap<Subject, HashMap<SubmissionCenter, Integer>> centerBasedScores = new HashMap<Subject, HashMap<SubmissionCenter, Integer>>();
        for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectByRole(keyword)) {
            Subject subject = observedSubject.getSubject();
            SubjectWithSummaries withSummaries = subjectToSummaries.get(subject);
            ObservationTemplate observationTemplate = observedSubject.getObservation().getSubmission().getObservationTemplate();
            SubmissionCenter submissionCenter = observationTemplate.getSubmissionCenter();
            Integer tier = observationTemplate.getTier();
            if (withSummaries == null) {
                withSummaries = new SubjectWithSummaries();
                withSummaries.setRole(keyword);
                withSummaries.setSubject(subject);
                withSummaries.setMaxTier(tier);
                withSummaries.setNumberOfObservations(1);
                HashSet<SubmissionCenter> centers = new HashSet<SubmissionCenter>();
                centers.add(submissionCenter);
                withSummaries.setNumberOfSubmissionCenters(1);
                withSummaries.addSubmission(tier, submissionCenter.getId());
                subjectToCenters.put(subject, centers);
                subjectToSummaries.put(subject, withSummaries);
                HashMap<SubmissionCenter, Integer> cScores = new HashMap<>();
                cScores.put(submissionCenter, tier);
                centerBasedScores.put(subject, cScores);
            } else {
                withSummaries.setMaxTier(Math.max(withSummaries.getMaxTier(), tier));
                withSummaries.setNumberOfObservations(withSummaries.getNumberOfObservations() + 1);
                HashSet<SubmissionCenter> submissionCenters = subjectToCenters.get(subject);
                submissionCenters.add(submissionCenter);
                withSummaries.setNumberOfSubmissionCenters(submissionCenters.size());
                withSummaries.addSubmission(tier, submissionCenter.getId());
                HashMap<SubmissionCenter, Integer> cScores = centerBasedScores.get(subject);
                Integer previousScore = cScores.get(submissionCenter);
                cScores.put(submissionCenter, previousScore == null ? tier : Math.max(tier, previousScore));
            }
        }
        Collection<SubjectWithSummaries> perRole = subjectToSummaries.values();
        for (SubjectWithSummaries subjectWithSummaries : perRole) {
            Integer totalScore = 0;
            for (Integer aScore : centerBasedScores.get(subjectWithSummaries.getSubject()).values()) {
                totalScore += aScore;
            }
            subjectWithSummaries.setScore(totalScore);
        }
        subjectWithSummariesList.addAll(perRole);
        log.info("Done scoring role: " + keyword);
    }
    dashboardDao.batchSave(subjectWithSummariesList, 0);
    log.info("Done scoring all roles...");
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) SubmissionCenter(gov.nih.nci.ctd2.dashboard.model.SubmissionCenter) SubjectRole(gov.nih.nci.ctd2.dashboard.model.SubjectRole) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SubjectRole

use of gov.nih.nci.ctd2.dashboard.model.SubjectRole in project nci-ctd2-dashboard by CBIIT.

the class ObservationController method getBySubjectId.

private List<Observation> getBySubjectId(Integer subjectId, String role, Integer tier) {
    Subject subject = dashboardDao.getEntityById(Subject.class, subjectId);
    if (subject != null) {
        Set<Observation> observations = new HashSet<Observation>();
        for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
            ObservedSubjectRole observedSubjectRole = observedSubject.getObservedSubjectRole();
            String subjectRole = observedSubjectRole.getSubjectRole().getDisplayName();
            Integer observationTier = observedSubject.getObservation().getSubmission().getObservationTemplate().getTier();
            if ((role.equals("") || role.equals(subjectRole)) && (tier == 0 || tier == observationTier)) {
                observations.add(observedSubject.getObservation());
            }
        }
        List<Observation> list = new ArrayList<Observation>(observations);
        Collections.sort(list, new Comparator<Observation>() {

            @Override
            public int compare(Observation o1, Observation o2) {
                Integer tier2 = o2.getSubmission().getObservationTemplate().getTier();
                Integer tier1 = o1.getSubmission().getObservationTemplate().getTier();
                return tier2 - tier1;
            }
        });
        return list;
    } else {
        return new ArrayList<Observation>();
    }
}
Also used : BigInteger(java.math.BigInteger) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) ArrayList(java.util.ArrayList) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) HashSet(java.util.HashSet)

Example 4 with SubjectRole

use of gov.nih.nci.ctd2.dashboard.model.SubjectRole in project nci-ctd2-dashboard by CBIIT.

the class SubjectResponse method createInstance.

private static SubjectResponse createInstance(final Subject subject, final Filter filter, DashboardDao dashboardDao) {
    int[] tierCount = new int[3];
    Set<Integer> set = new HashSet<Integer>();
    for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
        ObservedSubjectRole observedSubjectRole = observedSubject.getObservedSubjectRole();
        String subjectRole = observedSubjectRole.getSubjectRole().getDisplayName();
        if (filter.rolesIncluded.size() > 0 && !filter.rolesIncluded.contains(subjectRole))
            continue;
        ObservationTemplate observatinoTemplate = observedSubject.getObservation().getSubmission().getObservationTemplate();
        Integer observationTier = observatinoTemplate.getTier();
        String centerNameBrief = observatinoTemplate.getSubmissionCenter().getStableURL().substring(7);
        if (filter.centerIncluded.size() > 0 && !filter.centerIncluded.contains(centerNameBrief))
            continue;
        if ((Arrays.asList(filter.tiersIncluded).contains(observationTier))) {
            set.add(observedSubject.getObservation().getId());
            tierCount[observationTier.intValue() - 1]++;
            if (filter.limit > 0 && set.size() >= filter.limit) {
                break;
            }
        }
    }
    List<ObservationItem> observations = dashboardDao.findObservationInfo(new ArrayList<Integer>(set));
    Set<String> roles = new TreeSet<String>();
    for (int i = 0; i < observations.size(); i++) {
        for (SubjectItem sub : observations.get(i).subject_list) {
            if (sub.getName().equals(subject.getDisplayName())) {
                roles.add(sub.getRole());
                break;
            }
        }
    }
    String[] uris = observations.stream().map(x -> x.uri).toArray(String[]::new);
    SubjectResponse subjectResponse = new SubjectResponse(subject, uris, roles.toArray(new String[0]), tierCount);
    return subjectResponse;
}
Also used : Arrays(java.util.Arrays) DashboardDao(gov.nih.nci.ctd2.dashboard.dao.DashboardDao) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservationURIsAndTiers(gov.nih.nci.ctd2.dashboard.util.ObservationURIsAndTiers) Set(java.util.Set) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Xref(gov.nih.nci.ctd2.dashboard.model.Xref) Synonym(gov.nih.nci.ctd2.dashboard.model.Synonym) DashboardEntity(gov.nih.nci.ctd2.dashboard.model.DashboardEntity) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) TreeSet(java.util.TreeSet) ObservedSubjectRole(gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole) ObservationTemplate(gov.nih.nci.ctd2.dashboard.model.ObservationTemplate) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) HashSet(java.util.HashSet)

Example 5 with SubjectRole

use of gov.nih.nci.ctd2.dashboard.model.SubjectRole in project nci-ctd2-dashboard by CBIIT.

the class ObservationController method getObservationsBySubmissionIdAndSubjuectId.

/*
     * For a given submission, tier is decided so there is point of further
     * specifiying tier.
     */
@Transactional
@RequestMapping(value = "bySubmissionAndSubject", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> getObservationsBySubmissionIdAndSubjuectId(@RequestParam("submissionId") Integer submissionId, @RequestParam("subjectId") Integer subjectId, @RequestParam(value = "role", required = false, defaultValue = "") String role) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    String summaryTemplate = null;
    Set<Observation> observations = new HashSet<Observation>();
    Subject subject = dashboardDao.getEntityById(Subject.class, subjectId);
    for (ObservedSubject observedSubject : dashboardDao.findObservedSubjectBySubject(subject)) {
        Observation observation = observedSubject.getObservation();
        Submission submission = observation.getSubmission();
        if (!submission.getId().equals(submissionId)) {
            continue;
        } else if (summaryTemplate == null) {
            summaryTemplate = submission.getObservationTemplate().getObservationSummary();
        }
        String subjectRole = observedSubject.getObservedSubjectRole().getSubjectRole().getDisplayName();
        if ((role.equals("") || role.equals(subjectRole))) {
            observations.add(observation);
        }
    }
    List<ObservationWithSummary> list = new ArrayList<ObservationWithSummary>();
    for (Observation observation : observations) {
        String expanded = dashboardDao.expandSummary(observation.getId(), summaryTemplate) + " (<a class='button-link' href='#" + observation.getStableURL() + "'>details &raquo;</a>)";
        list.add(new ObservationWithSummary(observation, expanded));
    }
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.serialize(list), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Submission(gov.nih.nci.ctd2.dashboard.model.Submission) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) ArrayList(java.util.ArrayList) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) Subject(gov.nih.nci.ctd2.dashboard.model.Subject) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) ResponseEntity(org.springframework.http.ResponseEntity) Observation(gov.nih.nci.ctd2.dashboard.model.Observation) ObservedSubject(gov.nih.nci.ctd2.dashboard.model.ObservedSubject) HashSet(java.util.HashSet) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Subject (gov.nih.nci.ctd2.dashboard.model.Subject)6 ObservedSubject (gov.nih.nci.ctd2.dashboard.model.ObservedSubject)5 ArrayList (java.util.ArrayList)5 ObservationTemplate (gov.nih.nci.ctd2.dashboard.model.ObservationTemplate)4 ObservedSubjectRole (gov.nih.nci.ctd2.dashboard.model.ObservedSubjectRole)4 HashSet (java.util.HashSet)4 Observation (gov.nih.nci.ctd2.dashboard.model.Observation)3 HashMap (java.util.HashMap)3 SubjectRole (gov.nih.nci.ctd2.dashboard.model.SubjectRole)2 Submission (gov.nih.nci.ctd2.dashboard.model.Submission)2 Xref (gov.nih.nci.ctd2.dashboard.model.Xref)2 BigInteger (java.math.BigInteger)2 Transactional (org.springframework.transaction.annotation.Transactional)2 JSONSerializer (flexjson.JSONSerializer)1 DashboardDao (gov.nih.nci.ctd2.dashboard.dao.DashboardDao)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 DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)1