use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class TumorTypesUtil method setDepthAndTissue.
private void setDepthAndTissue(TumorType tumorType, int depth, String tissue) {
if (tumorType != null) {
tumorType.setLevel(new Integer(depth));
if (depth == 1) {
tissue = tumorType.getName();
}
tumorType.setTissue(tissue);
for (TumorType childTumorType : tumorType.getChildren().values()) {
setDepthAndTissue(childTumorType, depth + 1, tissue);
}
}
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class TumorTypesUtil method findTumorType.
private List<TumorType> findTumorType(TumorType allTumorTypes, TumorType currentTumorType, List<TumorType> matchedTumorTypes, String key, String keyword, Boolean exactMatch, Boolean includeParent) throws InvalidQueryException {
Map<String, TumorType> childrenTumorTypes = currentTumorType.getChildren();
Boolean match = false;
Map<String, List<String>> externalReferences = currentTumorType.getExternalReferences();
if (includeParent == null) {
includeParent = false;
}
if (exactMatch == null) {
exactMatch = true;
}
switch(key) {
case "code":
if (exactMatch) {
match = currentTumorType.getCode() == null ? false : currentTumorType.getCode().equalsIgnoreCase(keyword);
} else {
match = currentTumorType.getCode() == null ? false : StringUtils.containsIgnoreCase(currentTumorType.getCode(), keyword);
}
break;
case "color":
if (exactMatch) {
match = currentTumorType.getColor() == null ? false : currentTumorType.getColor().equalsIgnoreCase(keyword);
} else {
match = currentTumorType.getColor() == null ? false : StringUtils.containsIgnoreCase(currentTumorType.getColor(), keyword);
}
break;
case "name":
if (exactMatch) {
match = currentTumorType.getName() == null ? false : currentTumorType.getName().equalsIgnoreCase(keyword);
} else {
match = currentTumorType.getName() == null ? false : StringUtils.containsIgnoreCase(currentTumorType.getName(), keyword);
}
break;
case "nci":
if (exactMatch) {
match = externalReferences.containsKey("NCI") ? ListUtil.hasMatchingElementIgnoreCase(externalReferences.get("NCI"), keyword) : false;
} else {
match = externalReferences.containsKey("NCI") ? ListUtil.hasElementWhichContainsStringIgnoreCase(externalReferences.get("NCI"), keyword) : false;
}
break;
case "umls":
if (exactMatch) {
match = externalReferences.containsKey("UMLS") ? ListUtil.hasMatchingElementIgnoreCase(externalReferences.get("UMLS"), keyword) : false;
} else {
match = externalReferences.containsKey("UMLS") ? ListUtil.hasElementWhichContainsStringIgnoreCase(externalReferences.get("UMLS"), keyword) : false;
}
break;
case "maintype":
if (exactMatch) {
match = currentTumorType == null ? false : (currentTumorType.getMainType() == null ? false : currentTumorType.getMainType().equals(keyword));
} else {
match = currentTumorType == null ? false : (currentTumorType.getMainType() == null ? false : StringUtils.containsIgnoreCase(currentTumorType.getMainType(), keyword));
}
break;
case "level":
try {
Integer keywordAsInteger = Integer.parseInt(keyword);
match = currentTumorType == null ? false : (currentTumorType.getLevel() == null ? false : (currentTumorType.getLevel() == null ? false : currentTumorType.getLevel().equals(keywordAsInteger)));
} catch (NumberFormatException e) {
throw new InvalidQueryException("'" + keyword + "' is not a valid level. Level must be an integer.");
}
break;
default:
// we should never get here because we have already checked if this is a valid key
throw new InvalidQueryException(buildInvalidQueryTypeError(key));
}
if (match) {
TumorType tumorType = new TumorType();
tumorType.setCode(currentTumorType.getCode());
tumorType.setColor(currentTumorType.getColor());
tumorType.setName(currentTumorType.getName());
tumorType.setMainType(currentTumorType.getMainType());
tumorType.setExternalReferences(currentTumorType.getExternalReferences());
tumorType.setTissue(currentTumorType.getTissue());
// the results of search operations are flat lists of TumorTypes .. no nested children so do not setChildren()
tumorType.setParent(currentTumorType.getParent());
tumorType.setHistory(currentTumorType.getHistory());
tumorType.setRevocations(currentTumorType.getRevocations());
tumorType.setPrecursors(currentTumorType.getPrecursors());
tumorType.setLevel(currentTumorType.getLevel());
matchedTumorTypes.add(tumorType);
if (includeParent) {
String code = currentTumorType.getParent();
List<TumorType> parentTumorTypes = findTumorType(allTumorTypes, allTumorTypes, new ArrayList<TumorType>(), "code", code, true, true);
if (parentTumorTypes != null && parentTumorTypes.size() > 0) {
TumorType parentNode = parentTumorTypes.get(0);
matchedTumorTypes.add(parentNode);
if (parentNode.getParent() != null) {
matchedTumorTypes = findTumorType(allTumorTypes, allTumorTypes, matchedTumorTypes, "code", parentNode.getParent(), true, true);
}
}
}
}
if (childrenTumorTypes.size() > 0) {
Iterator it = childrenTumorTypes.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
matchedTumorTypes = findTumorType(allTumorTypes, (TumorType) pair.getValue(), matchedTumorTypes, key, keyword, exactMatch, includeParent);
}
}
return new ArrayList<>(new LinkedHashSet<>(matchedTumorTypes));
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class TumorTypesUtil method initTumorType.
private TumorType initTumorType(OncoTreeNode oncoTreeNode, Version version) throws InvalidOncoTreeDataException {
// we do not have level or tissue
TumorType tumorType = new TumorType();
tumorType.setMainType(oncoTreeNode.getMainType());
tumorType.setCode(oncoTreeNode.getCode());
tumorType.setName(oncoTreeNode.getName());
tumorType.setColor(oncoTreeNode.getColor());
tumorType.setParent(oncoTreeNode.getParentCode());
// do not copy history, revocations, or precursors
return tumorType;
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class CacheUtilTest method assertNoRevocationsInChildren.
private void assertNoRevocationsInChildren(Map<String, TumorType> tumorTypes) {
for (TumorType tumorType : tumorTypes.values()) {
assertEquals("Node " + tumorType.getCode() + " name: " + tumorType.getName() + " has revocations", 0, tumorType.getRevocations().size());
assertNoRevocationsInChildren(tumorType.getChildren());
}
}
use of org.mskcc.oncotree.model.TumorType 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;
}
Aggregations