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;
}
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);
}
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();
}
}
}
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;
}
Aggregations