Search in sources :

Example 6 with MSKConcept

use of org.mskcc.oncotree.crosswalk.MSKConcept in project oncotree by cBioPortal.

the class OncotreeTestConfig method mskConceptCache.

@Bean
public MSKConceptCache mskConceptCache() {
    MSKConceptCache mskConceptCache = Mockito.mock(MSKConceptCache.class);
    MSKConcept mskConcept = new MSKConcept();
    mskConcept.setConceptIds(Arrays.asList("MSK00001", "MSK00002"));
    Mockito.when(mskConceptCache.get(any(String.class))).thenReturn(mskConcept);
    return mskConceptCache;
}
Also used : MSKConcept(org.mskcc.oncotree.crosswalk.MSKConcept) MSKConceptCache(org.mskcc.oncotree.crosswalk.MSKConceptCache) Bean(org.springframework.context.annotation.Bean)

Example 7 with MSKConcept

use of org.mskcc.oncotree.crosswalk.MSKConcept in project oncotree by cBioPortal.

the class OncotreeMappingsApi method getMappings.

@RequestMapping(value = "api/crosswalk", method = RequestMethod.GET)
public OncotreeMappingsResp getMappings(@RequestParam(value = "vocabularyId", required = false) String vocabularyId, @RequestParam(value = "conceptId", required = false) String conceptId, @RequestParam(value = "histologyCode", required = false) String histologyCode, @RequestParam(value = "siteCode", required = false) String siteCode) {
    String cleanVocabularyId = apiUtil.cleanArgument(vocabularyId);
    String cleanConceptId = apiUtil.cleanArgument(conceptId);
    String cleanHistologyCode = apiUtil.cleanArgument(histologyCode);
    String cleanSiteCode = apiUtil.cleanArgument(siteCode);
    if (!mappingParametersAreValid(cleanVocabularyId, cleanConceptId, cleanHistologyCode, cleanSiteCode)) {
        throw new InvalidOncotreeMappingsParameters("Your query parameters, vocabularyId: " + cleanVocabularyId + ", conceptId: " + cleanConceptId + ", histologyCode: " + cleanHistologyCode + ", siteCode: " + cleanSiteCode + " are not valid. Please refer to the documentation");
    }
    MSKConcept mskConcept = crosswalkRepository.queryCVS(cleanVocabularyId, cleanConceptId, cleanHistologyCode, cleanSiteCode);
    return extractOncotreeMappings(mskConcept);
}
Also used : InvalidOncotreeMappingsParameters(org.mskcc.oncotree.error.InvalidOncotreeMappingsParameters) MSKConcept(org.mskcc.oncotree.crosswalk.MSKConcept) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with MSKConcept

use of org.mskcc.oncotree.crosswalk.MSKConcept in project oncotree by cBioPortal.

the class OncoTreePersistentCache method backupMSKConceptPersistentCache.

public synchronized void backupMSKConceptPersistentCache(MSKConcept mskConcept, String oncoTreeCode) throws Exception {
    CacheManager cacheManager = null;
    Cache<String, MSKConcept> cache = null;
    try {
        cacheManager = getCacheManager(BACKUP_CACHE_CONFIG_FILENAME);
        cache = cacheManager.getCache(MSKCONCEPT_CACHE);
        cache.put(oncoTreeCode, mskConcept);
    } catch (Exception e) {
        logger.warn("exception in mskConcept backup " + mskConcept + " exception: " + e);
        throw e;
    } finally {
        if (cacheManager != null) {
            // closes all caches it knows about
            cacheManager.close();
        }
    }
}
Also used : MSKConcept(org.mskcc.oncotree.crosswalk.MSKConcept) CacheManager(javax.cache.CacheManager) TopBraidException(org.mskcc.oncotree.topbraid.TopBraidException)

Example 9 with MSKConcept

use of org.mskcc.oncotree.crosswalk.MSKConcept in project oncotree by cBioPortal.

the class TumorTypesUtil method getAllTumorTypesFromOncoTreeNodes.

public Map<String, TumorType> getAllTumorTypesFromOncoTreeNodes(List<OncoTreeNode> oncoTreeNodes, Version version, HashMap<String, ArrayList<String>> topBraidURIsToOncotreeCodes) throws InvalidOncoTreeDataException {
    Map<String, TumorType> allNodes = new HashMap<>();
    HashSet<String> rootNodeCodeSet = new HashSet<>();
    HashSet<String> duplicateCodeSet = new HashSet<>();
    // construct basic nodes
    for (OncoTreeNode thisNode : oncoTreeNodes) {
        logger.debug("OncoTreeNode: code='" + thisNode.getCode() + "', name='" + thisNode.getName() + "'");
        TumorType tumorType = initTumorType(thisNode, version);
        String thisNodeCode = tumorType.getCode();
        if (allNodes.containsKey(thisNodeCode)) {
            duplicateCodeSet.add(thisNodeCode);
        }
        allNodes.put(thisNodeCode, tumorType);
        if (hasNoParent(tumorType)) {
            rootNodeCodeSet.add(thisNodeCode);
        }
        // get all codes defined so far for this topbraid uri and save in history
        if (topBraidURIsToOncotreeCodes.containsKey(thisNode.getURI())) {
            // do not add this code to the history, but add any others
            HashSet<String> allButThisNode = new HashSet<String>(topBraidURIsToOncotreeCodes.get(thisNode.getURI()));
            allButThisNode.remove(thisNode.getCode());
            tumorType.setHistory(new ArrayList<String>(allButThisNode));
        } else {
            topBraidURIsToOncotreeCodes.put(thisNode.getURI(), new ArrayList<String>());
        }
        for (String topBraidURI : thisNode.getRevocations()) {
            String fullTopBraidURI = TOPBRAID_BASE_URI + topBraidURI;
            if (topBraidURIsToOncotreeCodes.containsKey(fullTopBraidURI)) {
                ArrayList<String> nodeHistory = topBraidURIsToOncotreeCodes.get(fullTopBraidURI);
                // last node is most recent for this URI
                tumorType.addRevocations(nodeHistory.get(nodeHistory.size() - 1));
            } else {
                logger.error("loadFromRepository() -- unknown topBraidURI " + fullTopBraidURI + " in revocations field for topBraidURI " + thisNode.getURI());
                throw new InvalidOncoTreeDataException("Unknown topBraidURI " + fullTopBraidURI + " in revocations field for topBraidURI " + thisNode.getURI());
            }
        }
        for (String topBraidURI : thisNode.getPrecursors()) {
            String fullTopBraidURI = TOPBRAID_BASE_URI + topBraidURI;
            if (topBraidURIsToOncotreeCodes.containsKey(fullTopBraidURI)) {
                ArrayList<String> nodeHistory = topBraidURIsToOncotreeCodes.get(fullTopBraidURI);
                // last node is most recent for this URI
                tumorType.addPrecursors(nodeHistory.get(nodeHistory.size() - 1));
            } else {
                logger.error("loadFromRepository() -- unknown topBraidURI " + fullTopBraidURI + " in precursors field for topBraidURI " + thisNode.getURI());
                throw new InvalidOncoTreeDataException("Unknown topBraidURI " + fullTopBraidURI + " in precursors field for topBraidURI " + thisNode.getURI());
            }
        }
        // now save this as onoctree code history for this topbraid uri
        topBraidURIsToOncotreeCodes.get(thisNode.getURI()).add(thisNode.getCode());
    }
    validateOncoTreeOrThrowException(rootNodeCodeSet, duplicateCodeSet, allNodes);
    // also set NCI and UMLS codes
    for (TumorType tumorType : allNodes.values()) {
        String thisNodeCode = tumorType.getCode();
        MSKConcept mskConcept = mskConceptCache.get(thisNodeCode);
        if (mskConcept != null) {
            HashMap<String, List<String>> crosswalks = mskConcept.getCrosswalks();
            if (crosswalks != null && crosswalks.containsKey("NCI")) {
                tumorType.setExternalReference("NCI", crosswalks.get("NCI"));
            }
            if (mskConcept.getConceptIds() != null) {
                for (String mskConceptId : mskConcept.getConceptIds()) {
                    tumorType.addExternalReference("UMLS", mskConceptId.replace("MSK", "C"));
                }
            }
        }
        if (rootNodeCodeSet.contains(thisNodeCode)) {
            // root node has no parent
            continue;
        }
        TumorType parent = allNodes.get(tumorType.getParent());
        parent.addChild(tumorType);
    }
    // set depth and tissue properties (root has tissue = null)
    String rootCode = rootNodeCodeSet.iterator().next();
    TumorType rootNode = allNodes.get(rootCode);
    setDepthAndTissue(rootNode, 0, null);
    // now that all children have a path of references to them from the root, return only the root node.
    allNodes.clear();
    allNodes.put(rootCode, rootNode);
    return allNodes;
}
Also used : TumorType(org.mskcc.oncotree.model.TumorType) MSKConcept(org.mskcc.oncotree.crosswalk.MSKConcept) InvalidOncoTreeDataException(org.mskcc.oncotree.error.InvalidOncoTreeDataException) OncoTreeNode(org.mskcc.oncotree.topbraid.OncoTreeNode)

Aggregations

MSKConcept (org.mskcc.oncotree.crosswalk.MSKConcept)9 CacheManager (javax.cache.CacheManager)3 TumorType (org.mskcc.oncotree.model.TumorType)2 OncoTreeNode (org.mskcc.oncotree.topbraid.OncoTreeNode)2 TopBraidException (org.mskcc.oncotree.topbraid.TopBraidException)2 Bean (org.springframework.context.annotation.Bean)2 CrosswalkRepository (org.mskcc.oncotree.crosswalk.CrosswalkRepository)1 MSKConceptCache (org.mskcc.oncotree.crosswalk.MSKConceptCache)1 InvalidOncoTreeDataException (org.mskcc.oncotree.error.InvalidOncoTreeDataException)1 InvalidOncotreeMappingsParameters (org.mskcc.oncotree.error.InvalidOncotreeMappingsParameters)1 CachePut (org.springframework.cache.annotation.CachePut)1 Cacheable (org.springframework.cache.annotation.Cacheable)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1