use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class MainTypesApi method mainTypesGet.
@ApiOperation(value = "Return all available main tumor types.", notes = "")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Nested tumor types object"), @ApiResponse(code = 404, message = "Could not find maintypes"), @ApiResponse(code = 503, message = "Required data source unavailable") })
@RequestMapping(value = "", produces = { "application/json" }, method = RequestMethod.GET)
public Iterable<String> mainTypesGet(@ApiParam(value = "The version of tumor types. For example, " + VersionUtil.DEFAULT_VERSION + ". Please see the versions api documentation for released versions.") @RequestParam(value = "version", required = false) String version) {
Version v = (version == null) ? versionUtil.getDefaultVersion() : versionUtil.getVersion(version);
Map<String, TumorType> tumorTypes = cacheUtil.getTumorTypesByVersion(v);
Set<TumorType> tumorTypesSet = tumorTypesUtil.flattenTumorTypes(tumorTypes, version);
return mainTypesUtil.getMainTypesByTumorTypes(tumorTypesSet);
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class TumorTypesUtilTest method getReturnedFullTumorTypeMap.
private Map<String, TumorType> getReturnedFullTumorTypeMap() throws Exception {
Set<TumorType> tumorTypesAsPreparedForTumorTypesEndpoint = simulateFullTumorTypeApiResponse();
HashMap<String, TumorType> returnedTumorTypeMap = new HashMap<>(tumorTypesAsPreparedForTumorTypesEndpoint.size());
for (TumorType tumorType : tumorTypesAsPreparedForTumorTypesEndpoint) {
returnedTumorTypeMap.put(tumorType.getCode(), tumorType);
}
return returnedTumorTypeMap;
}
use of org.mskcc.oncotree.model.TumorType 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;
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class TumorTypesUtil method addTumorTypeToRows.
private void addTumorTypeToRows(TumorType tumorType, List<String> rows, List<String> parents) {
List<String> row = new ArrayList<>();
String oncotreeCode = StringUtils.defaultString(tumorType.getCode()).trim();
// only 7 levels of headers. Abort the attemp to render the spreadsheet and throw an exception.
if (parents.size() > 7) {
throw new RuntimeException("OncoTree depth for code " + oncotreeCode + " exceeds max representation. Depth cannot be > 7");
}
String displayName = StringUtils.defaultString(tumorType.getName()).trim() + " (" + oncotreeCode + ")";
row.addAll(parents);
row.add(displayName);
// Need to pad for the primary - quinternary columns if all parents are not present
for (int i = 6; i > parents.size(); i--) {
row.add("");
}
row.add(StringUtils.defaultString(tumorType.getMainType()));
row.add(StringUtils.defaultString(tumorType.getColor()));
// TODO enum or something
if (tumorType.getExternalReferences().containsKey("NCI")) {
row.add(StringUtils.defaultString(StringUtils.join(tumorType.getExternalReferences().get("NCI"), ",")));
} else {
row.add("");
}
// TODO enum or something
if (tumorType.getExternalReferences().containsKey("UMLS")) {
row.add(StringUtils.defaultString(StringUtils.join(tumorType.getExternalReferences().get("UMLS"), ",")));
} else {
row.add("");
}
// add revocations and precursors to history column
List<String> combinedHistory = new ArrayList<String>();
combinedHistory.addAll(tumorType.getHistory());
combinedHistory.addAll(tumorType.getRevocations());
combinedHistory.addAll(tumorType.getPrecursors());
// do not display a code in its own history (e.g. PTCL)
combinedHistory.removeAll(Collections.singletonList(tumorType.getCode()));
row.add(StringUtils.defaultString(StringUtils.join(combinedHistory, ",")));
rows.add(StringUtils.join(row, "\t"));
// Prepare for next recursive call
Map<String, TumorType> children = tumorType.getChildren();
if (children.size() > 0) {
parents.add(displayName);
for (String code : children.keySet()) {
TumorType child = children.get(code);
addTumorTypeToRows(child, rows, parents);
}
parents.remove(parents.size() - 1);
}
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class TumorTypesUtil method getTsvFromTumorTypes.
private String getTsvFromTumorTypes(Map<String, TumorType> tumorTypes) {
List<String> rows = new ArrayList<>();
for (String code : tumorTypes.keySet()) {
TumorType tumorType = tumorTypes.get(code);
// skip the root node, "TISSUE". Just add it's children
Map<String, TumorType> children = tumorType.getChildren();
for (String childCode : children.keySet()) {
addTumorTypeToRows(children.get(childCode), rows, new ArrayList<String>());
}
}
Collections.sort(rows);
rows.add(0, TSV_HEADER);
return StringUtils.join(rows, "\n") + "\n";
}
Aggregations