use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class TumorTypesUtil method validateOncoTreeOrThrowException.
private void validateOncoTreeOrThrowException(Set<String> rootNodeCodeSet, Set<String> duplicateCodeSet, Map<String, TumorType> allNodes) throws InvalidOncoTreeDataException {
StringBuilder errorMessageBuilder = new StringBuilder();
// check for one root node
if (rootNodeCodeSet.size() == 0) {
errorMessageBuilder.append("\toncotree has no root node (a node where parent is empty)\n");
} else if (rootNodeCodeSet.size() > 1) {
errorMessageBuilder.append("\toncotree has more than one root node (nodes where parent is empty):\n");
for (String code : rootNodeCodeSet) {
errorMessageBuilder.append("\t\t" + code + "\n");
}
}
// check for no duplicated OncoTree codes
if (duplicateCodeSet.size() > 0) {
errorMessageBuilder.append("\tduplication : OncoTree has more than one node containing each of the following OncoTree codes:\n");
for (String code : duplicateCodeSet) {
errorMessageBuilder.append("\t\t" + code + "\n");
}
}
// check that non-root nodes have a parent in the set of all nodes
Set<String> allCodeSet = allNodes.keySet();
for (TumorType tumorType : allNodes.values()) {
String thisNodeCode = tumorType.getCode();
String parentCode = tumorType.getParent();
if (rootNodeCodeSet.contains(thisNodeCode)) {
// by definition, root nodes have no parent
continue;
} else {
if (!allCodeSet.contains(parentCode)) {
errorMessageBuilder.append("\tnode " + thisNodeCode + " has parent code '" + parentCode + "', which is not a code for any node in the tree\n");
}
}
}
if (errorMessageBuilder.length() > 0) {
throw new InvalidOncoTreeDataException("Invalid OncoTree received:\n" + errorMessageBuilder.toString());
}
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class TumorTypesUtil method flattenTumorTypes.
public Set<TumorType> flattenTumorTypes(Map<String, TumorType> nestedTumorTypes, String parent) {
Set<TumorType> tumorTypes = new HashSet<>();
Iterator<Map.Entry<String, TumorType>> it = nestedTumorTypes.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, TumorType> pair = it.next();
TumorType tumorType = pair.getValue();
if (tumorType.getChildren() != null && tumorType.getChildren().size() > 0) {
tumorTypes.addAll(flattenTumorTypes(tumorType.getChildren(), pair.getKey()));
}
tumorType.setParent(parent);
tumorType.setChildren(null);
tumorTypes.add(tumorType);
}
return tumorTypes;
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class CacheUtilTest method assertRevocationsInChildren.
private Boolean assertRevocationsInChildren(Map<String, TumorType> tumorTypes, Boolean foundRevocations) {
for (TumorType tumorType : tumorTypes.values()) {
if ("URMM".equals(tumorType.getCode())) {
assertEquals("URMM revocations size", 1, tumorType.getRevocations().size());
assertEquals("GMUCM", tumorType.getRevocations().get(0));
foundRevocations = Boolean.TRUE;
// do not return because we want to check no other revocations
} else {
assertEquals(0, tumorType.getRevocations().size());
}
foundRevocations = assertRevocationsInChildren(tumorType.getChildren(), foundRevocations);
}
return foundRevocations;
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class CacheUtilTest method assertPrecursorsInChildren.
private Boolean assertPrecursorsInChildren(Map<String, TumorType> tumorTypes, Boolean foundPrecursors) {
for (TumorType tumorType : tumorTypes.values()) {
if ("CLLSLL".equals(tumorType.getCode())) {
assertEquals("'CLLSLL' precursors size", 2, tumorType.getPrecursors().size());
assertTrue("Expected 'CLL' to be precursor to 'CLLSLL'", tumorType.getPrecursors().contains("CLL"));
assertTrue("Expected 'SLL' to be precursor to 'CLLSLL'", tumorType.getPrecursors().contains("SLL"));
foundPrecursors = Boolean.TRUE;
// do not return because we want to check no other precursors
} else {
assertEquals(0, tumorType.getPrecursors().size());
}
foundPrecursors = assertPrecursorsInChildren(tumorType.getChildren(), foundPrecursors);
}
return foundPrecursors;
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class CacheUtilTest method assertHistoryInChildren.
private Boolean assertHistoryInChildren(Map<String, TumorType> tumorTypes, Boolean foundHistory) {
for (TumorType tumorType : tumorTypes.values()) {
if ("SS".equals(tumorType.getCode())) {
assertEquals(1, tumorType.getHistory().size());
assertEquals("SEZS", tumorType.getHistory().get(0));
foundHistory = Boolean.TRUE;
// do not return because we want to check no other history
} else {
assertEquals(0, tumorType.getHistory().size());
}
foundHistory = assertHistoryInChildren(tumorType.getChildren(), foundHistory);
}
return foundHistory;
}
Aggregations