Search in sources :

Example 6 with ECOTerm

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

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

the class ECOTermAPI method getECOTermFromCode.

@Transactional
@RequestMapping(value = "{ecocode}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getECOTermFromCode(@PathVariable String ecocode) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    ECOTerm ecoterm = dashboardDao.getEcoTerm(ecocode);
    if (ecoterm == null) {
        return new ResponseEntity<String>("{\"name\":\"(not available)\"}", headers, HttpStatus.OK);
    }
    log.debug("ECO term name: " + ecoterm);
    // CTD2Serializer.createJSONSerializer();
    JSONSerializer jsonSerializer = new JSONSerializer().transform(new FieldNameTransformer("name"), "displayName");
    String json = jsonSerializer.deepSerialize(ecoterm);
    return new ResponseEntity<String>(json, headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) FieldNameTransformer(gov.nih.nci.ctd2.dashboard.api.FieldNameTransformer) 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 8 with ECOTerm

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

the class DashboardDaoImpl method findECOTerms.

@SuppressWarnings("unchecked")
private List<ECOTerm> findECOTerms(String queryString) {
    // search ECO codes first
    Pattern ECOCodePattern = Pattern.compile("(eco[:_])?(\\d{7})");
    Matcher matcher = ECOCodePattern.matcher(queryString);
    List<String> codes = new ArrayList<String>();
    while (matcher.find()) {
        codes.add("ECO:" + matcher.group(2));
    }
    org.hibernate.query.Query<?> query = null;
    List<ECOTerm> list = null;
    Session session = getSession();
    if (codes.size() > 0) {
        query = session.createQuery("FROM ECOTermImpl WHERE code in (:codes)");
        query.setParameterList("codes", codes);
        list = (List<ECOTerm>) query.list();
    } else {
        String[] words = queryString.trim().split(" (?=([^\"]*\"[^\"]*\")*[^\"]*$)");
        Set<ECOTerm> set = new HashSet<ECOTerm>();
        for (String w : words) {
            String x = w.replaceAll("^\"|\"$", "");
            if (x.length() == 0) {
                continue;
            }
            query = session.createQuery("FROM ECOTermImpl WHERE displayName LIKE :name OR synonyms LIKE :synonym");
            query.setParameter("name", x);
            query.setParameter("synonym", x);
            set.addAll((List<ECOTerm>) query.list());
        }
        list = new ArrayList<ECOTerm>(set);
    }
    log.debug("eco term number " + list.size());
    session.close();
    return list;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm) FullTextSession(org.hibernate.search.FullTextSession) Session(org.hibernate.Session) HashSet(java.util.HashSet)

Example 9 with ECOTerm

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

the class DashboardDaoImpl method ontologySearchExperimentalEvidence.

private List<Integer> ontologySearchExperimentalEvidence(final List<ECOTerm> ecoterms) {
    List<Integer> list = new ArrayList<Integer>();
    for (ECOTerm t : ecoterms) {
        int code = Integer.parseInt(t.getCode().substring(4));
        log.debug("eco code:" + code);
        list.addAll(searchEEChildren(code));
    }
    return list;
}
Also used : BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm)

Example 10 with ECOTerm

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

the class EcoController method term.

@Transactional
@RequestMapping(value = "term/{id}", method = { RequestMethod.GET, RequestMethod.POST }, headers = "Accept=application/json")
public ResponseEntity<String> term(@PathVariable final String id) {
    log.debug("request received by EcoController for " + id);
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    final ECOTerm ecoterm = dashboardDao.getEntityByStableURL("eco", "eco/" + id);
    log.debug(ecoterm);
    final JSONSerializer jsonSerializer = new JSONSerializer().transform(new ImplTransformer(), Class.class).transform(new DateTransformer(), Date.class);
    return new ResponseEntity<String>(jsonSerializer.deepSerialize(ecoterm), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ImplTransformer(gov.nih.nci.ctd2.dashboard.util.ImplTransformer) DateTransformer(gov.nih.nci.ctd2.dashboard.util.DateTransformer) ECOTerm(gov.nih.nci.ctd2.dashboard.model.ECOTerm) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ECOTerm (gov.nih.nci.ctd2.dashboard.model.ECOTerm)11 Session (org.hibernate.Session)5 FullTextSession (org.hibernate.search.FullTextSession)5 JSONSerializer (flexjson.JSONSerializer)3 DashboardEntity (gov.nih.nci.ctd2.dashboard.model.DashboardEntity)3 Gene (gov.nih.nci.ctd2.dashboard.model.Gene)3 Subject (gov.nih.nci.ctd2.dashboard.model.Subject)3 Xref (gov.nih.nci.ctd2.dashboard.model.Xref)3 EcoBrowse (gov.nih.nci.ctd2.dashboard.util.EcoBrowse)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 NoResultException (javax.persistence.NoResultException)3 EvidenceItem (gov.nih.nci.ctd2.dashboard.api.EvidenceItem)2 ObservationItem (gov.nih.nci.ctd2.dashboard.api.ObservationItem)2 SubjectItem (gov.nih.nci.ctd2.dashboard.api.SubjectItem)2 XRefItem (gov.nih.nci.ctd2.dashboard.api.XRefItem)2 DashboardDao (gov.nih.nci.ctd2.dashboard.dao.DashboardDao)2 DashboardEntityImpl (gov.nih.nci.ctd2.dashboard.impl.DashboardEntityImpl)2 ObservationTemplateImpl (gov.nih.nci.ctd2.dashboard.impl.ObservationTemplateImpl)2 SubjectImpl (gov.nih.nci.ctd2.dashboard.impl.SubjectImpl)2