Search in sources :

Example 1 with MSKConcept

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

the class OncoTreePersistentCache method backupMSKConceptPersistentCache.

public synchronized void backupMSKConceptPersistentCache(Map<String, MSKConcept> oncoTreeCodesToMSKConcepts) throws Exception {
    CacheManager cacheManager = null;
    Cache<String, MSKConcept> cache = null;
    try {
        if (oncoTreeCodesToMSKConcepts == null) {
            System.out.println("null argument passed to backupMSKConceptPersistentCache");
            return;
        }
        cacheManager = getCacheManager(BACKUP_CACHE_CONFIG_FILENAME);
        cache = cacheManager.getCache(MSKCONCEPT_CACHE);
        cache.putAll(oncoTreeCodesToMSKConcepts);
    } catch (Exception e) {
        logger.warn("exception in oncotreeCocdesToMSKConcepts -- 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 2 with MSKConcept

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

the class OncoTreePersistentCache method updateMSKConceptInPersistentCache.

// Updating MSKConcepts
@CachePut(value = "mskConceptEHCache", key = "#oncoTreeCode", unless = "#result==null")
public MSKConcept updateMSKConceptInPersistentCache(String oncoTreeCode) {
    logger.info("updating EHCache with updated MSKConcept from Crosswalk");
    MSKConcept mskConcept = crosswalkRepository.getByOncotreeCode(oncoTreeCode);
    if (mskConcept != null) {
        return mskConcept;
    }
    return new MSKConcept();
}
Also used : MSKConcept(org.mskcc.oncotree.crosswalk.MSKConcept) CachePut(org.springframework.cache.annotation.CachePut)

Example 3 with MSKConcept

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

the class OncotreeTestConfig method crosswalkRepository.

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

Example 4 with MSKConcept

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

the class OncoTreePersistentCache method getMSKConceptFromPersistentCacheBackup.

@Cacheable(value = "mskConceptEHCache", key = "#oncoTreeCode", unless = "#result==null")
private synchronized MSKConcept getMSKConceptFromPersistentCacheBackup(String oncoTreeCode) throws Exception {
    CacheManager cacheManager = null;
    Cache<String, MSKConcept> cache = null;
    MSKConcept mskConcept = null;
    try {
        cacheManager = getCacheManager(BACKUP_CACHE_CONFIG_FILENAME);
        cache = cacheManager.getCache(MSKCONCEPT_CACHE);
        mskConcept = cache.get(oncoTreeCode);
    } finally {
        if (cacheManager != null) {
            // closes all caches it knows about
            cacheManager.close();
        }
    }
    return mskConcept;
}
Also used : MSKConcept(org.mskcc.oncotree.crosswalk.MSKConcept) CacheManager(javax.cache.CacheManager) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 5 with MSKConcept

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

the class TumorTypesUtil method loadFromRepository.

private static Map<String, TumorType> loadFromRepository(Version version) throws InvalidOncoTreeDataException {
    List<OncoTreeNode> oncoTreeNodes = oncoTreeRepository.getOncoTree(version);
    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);
        }
    }
    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.setNCI(crosswalks.get("NCI"));
            }
            List<String> umlsIds = new ArrayList<String>();
            if (mskConcept.getConceptIds() != null) {
                for (String mskConceptId : mskConcept.getConceptIds()) {
                    umlsIds.add(mskConceptId.replace("MSK", "C"));
                }
            }
            tumorType.setUMLS(umlsIds);
            tumorType.setHistory(new ArrayList(mskConcept.getHistory()));
        }
        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 : MSKConcept(org.mskcc.oncotree.crosswalk.MSKConcept) OncoTreeNode(org.mskcc.oncotree.topbraid.OncoTreeNode) TumorType(org.mskcc.oncotree.model.TumorType)

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