Search in sources :

Example 16 with TumorType

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());
    }
}
Also used : TumorType(org.mskcc.oncotree.model.TumorType) InvalidOncoTreeDataException(org.mskcc.oncotree.error.InvalidOncoTreeDataException)

Example 17 with TumorType

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;
}
Also used : TumorType(org.mskcc.oncotree.model.TumorType)

Example 18 with TumorType

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;
}
Also used : TumorType(org.mskcc.oncotree.model.TumorType)

Example 19 with TumorType

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;
}
Also used : TumorType(org.mskcc.oncotree.model.TumorType)

Example 20 with TumorType

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;
}
Also used : TumorType(org.mskcc.oncotree.model.TumorType)

Aggregations

TumorType (org.mskcc.oncotree.model.TumorType)22 InvalidOncoTreeDataException (org.mskcc.oncotree.error.InvalidOncoTreeDataException)3 Version (org.mskcc.oncotree.model.Version)3 OncoTreeNode (org.mskcc.oncotree.topbraid.OncoTreeNode)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Test (org.junit.Test)2 MSKConcept (org.mskcc.oncotree.crosswalk.MSKConcept)2 TopBraidException (org.mskcc.oncotree.topbraid.TopBraidException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 InputStream (java.io.InputStream)1 Deprecated (java.lang.Deprecated)1 HashMap (java.util.HashMap)1 InvalidQueryException (org.mskcc.oncotree.error.InvalidQueryException)1 InvalidVersionException (org.mskcc.oncotree.error.InvalidVersionException)1 InputStreamResource (org.springframework.core.io.InputStreamResource)1