use of gov.nih.nci.ctd2.dashboard.impl.TissueSampleImpl in project nci-ctd2-dashboard by CBIIT.
the class DashboardDaoImpl method ontologySearchOneTerm.
private List<SubjectResult> ontologySearchOneTerm(String oneTerm, final Set<Integer> observations) {
long t1 = System.currentTimeMillis();
List<Integer> list = ontologySearchDiseaseContext(oneTerm);
List<SubjectResult> entities = new ArrayList<SubjectResult>();
Session session = getSession();
@SuppressWarnings("unchecked") org.hibernate.query.Query<TissueSample> query = session.createQuery("from TissueSampleImpl where code = :code");
List<Integer> subjectIds = new ArrayList<Integer>();
for (Integer i : list) {
query.setParameter("code", i);
TissueSample result = null;
try {
result = query.getSingleResult();
} catch (NoResultException e) {
log.info("Tissue sample not available for code " + i);
continue;
}
int observationNumber = observationCountForTissueSample(i);
int centerCount = centerCountForTissueSample(i);
Set<String> roles = getRolesForSubjectId(result.getId());
SubjectResult x = new SubjectResult(result, observationNumber, centerCount, 1, roles);
entities.add(x);
subjectIds.add(result.getId());
}
long t2 = System.currentTimeMillis();
log.debug("disease context ontology search for '" + oneTerm + "' took " + (t2 - t1) + " milliseconds");
log.debug("tissue sample results count: " + entities.size());
if (observations != null) {
List<Integer> observationIds = observationIdsForSubjectIds(subjectIds);
observations.addAll(observationIds);
log.debug("observations count: " + observations.size());
}
List<ECOTerm> ecoterms = findECOTerms(oneTerm);
List<Integer> eco_list = ontologySearchExperimentalEvidence(ecoterms);
int eco_list_size = eco_list.size();
log.debug("eco list size:" + eco_list_size);
if (eco_list_size > 0) {
@SuppressWarnings("unchecked") org.hibernate.query.Query<ECOTerm> query2 = session.createQuery("FROM ECOTermImpl WHERE code in (:codes)");
List<String> codes = eco_list.stream().map(x -> String.format("ECO:%07d", x)).collect(Collectors.toList());
query2.setParameterList("codes", codes);
List<ECOTerm> list2 = query2.list();
for (ECOTerm x : list2) {
int observationNumber = observationCountForEcoCode(x.getCode());
int centerCount = centerCountForEcoCode(x.getCode());
// no matchNumber, no roles
SubjectResult subjectResult = new SubjectResult(x, observationNumber, centerCount, null, null);
entities.add(subjectResult);
if (observations != null) {
List<Integer> observationIdsForOneECOTerm = observationIdsForEcoCode(x.getCode());
observations.addAll(observationIdsForOneECOTerm);
}
}
}
log.debug("tissue sample results count after getting ECO term: " + entities.size());
if (observations != null) {
log.debug("observations count after getting ECO term: " + observations.size());
}
if (observations != null) {
searchSubjectsToUpdateObservations(oneTerm, observations);
log.debug("observationIds count after getting other subjects: " + observations.size());
}
session.close();
return entities;
}
Aggregations