use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class CacheUtil method resetCache.
public void resetCache() throws FailedCacheRefreshException {
logger.info("resetCache() -- refilling tumor types cache");
Map<Version, Map<String, TumorType>> latestTumorTypesCache = new HashMap<>();
ArrayList<Version> oncoTreeVersions = new ArrayList<Version>();
ArrayList<String> failedVersions = new ArrayList<String>();
// use this to store and look up previous oncoTree codes
HashMap<String, ArrayList<String>> topBraidURIsToOncotreeCodes = new HashMap<String, ArrayList<String>>();
boolean failedOncoTreeVersionsCacheRefresh = false;
boolean failedVersionedOncoTreeNodesCacheRefresh = false;
// update EHCache with newest versions available
try {
oncoTreePersistentCache.updateOncoTreeVersionsInPersistentCache();
} catch (TopBraidException exception) {
logger.error("resetCache() -- failed to pull versions from repository");
failedOncoTreeVersionsCacheRefresh = true;
}
// attmpt to get versions from EHCache -- RuntimeException thrown when ALL options are exhausted (ehcache, topbraid, backup)
try {
oncoTreeVersions = oncoTreePersistentCache.getOncoTreeVersionsFromPersistentCache();
} catch (RuntimeException e) {
throw new FailedCacheRefreshException("No data found in specified backup cache location...");
}
if (!failedOncoTreeVersionsCacheRefresh) {
try {
oncoTreePersistentCache.backupOncoTreeVersionsPersistentCache(oncoTreeVersions);
} catch (Exception e) {
logger.error("Unable to backup versions EHCache");
slackUtil.sendSlackNotification("*OncoTree Error* - OncoTreeVersionsCache backup failed." + e.getMessage());
}
}
// versions are ascending by release date
for (Version version : oncoTreeVersions) {
Map<String, TumorType> latestTumorTypes = new HashMap<String, TumorType>();
ArrayList<OncoTreeNode> oncoTreeNodes = new ArrayList<OncoTreeNode>();
failedVersionedOncoTreeNodesCacheRefresh = false;
if (version != null) {
try {
oncoTreePersistentCache.updateOncoTreeNodesInPersistentCache(version);
} catch (TopBraidException e) {
logger.error("resetCache() -- failed to pull tumor types for version '" + version.getVersion() + "' from repository : " + e.toString());
failedVersionedOncoTreeNodesCacheRefresh = true;
}
// store versions for which nodes cannot be successfully loaded (either due to inaccessible data or invalid data)
try {
oncoTreeNodes = oncoTreePersistentCache.getOncoTreeNodesFromPersistentCache(version);
} catch (RuntimeException e) {
failedVersions.add(version.getVersion());
logger.warn("resetCache() -- failed to retrieve version '" + version.getVersion() + "'");
continue;
}
if (!failedVersionedOncoTreeNodesCacheRefresh) {
try {
oncoTreePersistentCache.backupOncoTreeNodesPersistentCache(oncoTreeNodes, version);
} catch (Exception e) {
logger.error("Unable to backup oncotree nodes EHCache");
slackUtil.sendSlackNotification("*OncoTree Error* - OncoTreeNodesCache backup failed." + e.getMessage());
}
}
try {
latestTumorTypes = tumorTypesUtil.getAllTumorTypesFromOncoTreeNodes(oncoTreeNodes, version, topBraidURIsToOncotreeCodes);
} catch (InvalidOncoTreeDataException exception) {
logger.error("Unable to get tumor types from oncotree nodes");
failedVersions.add(version.getVersion());
logger.warn("resetCache() -- failed to retrieve version : " + version.getVersion() + " : " + exception.toString());
continue;
}
}
latestTumorTypesCache.put(version, latestTumorTypes);
}
// Fail the cache refresh if required oncotree version cannot be constructed or if no versions can be constructed
if (latestTumorTypesCache.keySet().size() == 0) {
logger.error("resetCache() -- failed to pull a single valid OncoTree version");
throw new FailedCacheRefreshException("Failed to refresh cache - no versions constructed");
}
if (failedVersions.contains(requiredOncotreeVersion)) {
logger.error("resetCache() -- failed to pull required oncotree version: " + requiredOncotreeVersion);
throw new FailedCacheRefreshException("Failed to refresh cache - required version not constructed");
}
if (failedVersions.size() > 0) {
slackUtil.sendSlackNotification("OncoTree successfully recached `" + requiredOncotreeVersion + "`, but ran into issues with the following versions: " + String.join(", ", failedVersions));
}
tumorTypesCache = latestTumorTypesCache;
// cache is filled, but indicate to endpoint that we did not successfully pull updated data from TopBraid
if (failedOncoTreeVersionsCacheRefresh || failedVersionedOncoTreeNodesCacheRefresh) {
throw new FailedCacheRefreshException("Failed to refresh cache - composite error");
} else {
dateOfLastCacheRefresh = new Date();
logger.info("resetCache() -- successfully reset cache from repository");
}
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class CacheUtilTest method assertNoPrecursorsInChildren.
private void assertNoPrecursorsInChildren(Map<String, TumorType> tumorTypes) {
for (TumorType tumorType : tumorTypes.values()) {
assertEquals("Node " + tumorType.getCode() + " name: " + tumorType.getName() + " has precursors", 0, tumorType.getPrecursors().size());
assertNoPrecursorsInChildren(tumorType.getChildren());
}
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class OncotreeTestConfig method setupExpectedTumorTypeMap.
private Map<String, TumorType> setupExpectedTumorTypeMap() throws Exception {
String[] rawTestValueSource = getRawTestValueSource();
final int valuesPerCase = 6;
if (rawTestValueSource.length % valuesPerCase != 0) {
throw new Exception("Error : malformed rawTestValueSource");
}
final int caseCount = rawTestValueSource.length / valuesPerCase;
if (caseCount < 1) {
throw new Exception("Error : no test cases defined in rawTestValueSource");
}
Map<String, TumorType> expectedTumorTypeMap = new HashMap<>(caseCount + 1);
for (int pos = 0; pos < rawTestValueSource.length; pos = pos + valuesPerCase) {
TumorType nextType = new TumorType();
String code = rawTestValueSource[pos];
if (code != null && code.trim().length() > 0) {
nextType.setCode(code.trim());
} else {
fail("Error : list of expected oncotree codes contains a node with no code");
}
String name = rawTestValueSource[pos + 1];
if (name != null && name.trim().length() > 0) {
nextType.setName(name.trim());
}
String mainType = rawTestValueSource[pos + 2];
if (mainType != null && mainType.trim().length() > 0) {
nextType.setMainType(mainType.trim());
}
String color = rawTestValueSource[pos + 3];
if (color != null && color.trim().length() > 0) {
nextType.setColor(color.trim());
}
String parentCode = rawTestValueSource[pos + 4];
if (parentCode != null && parentCode.trim().length() > 0) {
nextType.setParent(parentCode.trim());
}
expectedTumorTypeMap.put(code, nextType);
}
return expectedTumorTypeMap;
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class TumorTypesTxtApi method tumorTypesTxtGet.
@Deprecated
@ApiOperation(value = "Tumor Types in plain text format.", notes = "Return all available tumor types.", response = Void.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Tumor types text file."), @ApiResponse(code = 404, message = "Could not find tumor types text file"), @ApiResponse(code = 503, message = "Required data source unavailable") })
@RequestMapping(value = "", produces = { TEXT_PLAIN_VALUE }, method = RequestMethod.GET)
public InputStreamResource tumorTypesTxtGet(@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) {
Map<String, TumorType> tumorTypes = new HashMap<>();
Version v = (version == null) ? versionUtil.getDefaultVersion() : versionUtil.getVersion(version);
tumorTypes = cacheUtil.getTumorTypesByVersion(v);
InputStream inputStream = tumorTypesUtil.getTumorTypeInputStream(tumorTypes);
InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
return inputStreamResource;
}
use of org.mskcc.oncotree.model.TumorType in project oncotree by cBioPortal.
the class TumorTypesUtilTest method testFullOncoTreeCodeListByCode.
@Test
public void testFullOncoTreeCodeListByCode() throws Exception {
int failureCount = 0;
StringBuilder failureReport = new StringBuilder();
Map<String, TumorType> returnedTumorTypeMap = getReturnedFullTumorTypeMap();
for (String oncoTreeCode : expectedTumorTypeMap.keySet()) {
TumorType expectedTumorType = expectedTumorTypeMap.get(oncoTreeCode);
TumorType returnedTumorType = returnedTumorTypeMap.get(oncoTreeCode);
if (expectedTumorType == null || returnedTumorType == null) {
if (expectedTumorType == null) {
failureReport.append(oncoTreeCode + " : no values in expected tumor type hash (internal error)\n");
failureCount = failureCount + 1;
}
if (returnedTumorType == null) {
failureReport.append(oncoTreeCode + " : tumor type expected but not returned from tumorTypesUtil\n");
failureCount = failureCount + 1;
}
} else {
String expectedCode = expectedTumorType.getCode();
String returnedCode = returnedTumorType.getCode();
if (!testValuesMatch(expectedCode, returnedCode)) {
failureReport.append(makeMismatchMessage(oncoTreeCode, "code", returnedCode, expectedCode));
failureCount = failureCount + 1;
}
String expectedName = expectedTumorType.getName();
String returnedName = returnedTumorType.getName();
if (!testValuesMatch(expectedName, returnedName)) {
failureReport.append(makeMismatchMessage(oncoTreeCode, "name", returnedName, expectedName));
failureCount = failureCount + 1;
}
String expectedMainType = expectedTumorType.getMainType();
String returnedMainType = returnedTumorType.getMainType();
if (expectedMainType == null || returnedMainType == null) {
if (expectedMainType == null && returnedMainType != null) {
if (returnedMainType != null && returnedMainType.trim().length() != 0) {
failureReport.append(oncoTreeCode + " : expected MainType is null, and returned MainType is non-null\n");
failureCount = failureCount + 1;
}
}
if (returnedMainType == null && expectedMainType != null) {
if (expectedMainType != null && expectedMainType.trim().length() != 0) {
failureReport.append(oncoTreeCode + " : retunred MainType is null, and expected MainType is non-null\n");
failureCount = failureCount + 1;
}
}
} else {
if (!testValuesMatch(expectedMainType, returnedMainType)) {
failureReport.append(makeMismatchMessage(oncoTreeCode, "mainType", returnedMainType, expectedMainType));
failureCount = failureCount + 1;
}
}
String expectedColor = expectedTumorType.getColor();
String returnedColor = returnedTumorType.getColor();
if (!testValuesMatch(expectedColor, returnedColor)) {
failureReport.append(makeMismatchMessage(oncoTreeCode, "color", returnedColor, expectedColor));
failureCount = failureCount + 1;
}
String expectedParent = expectedTumorType.getParent();
String returnedParent = returnedTumorType.getParent();
if (!testValuesMatch(expectedParent, returnedParent)) {
failureReport.append(makeMismatchMessage(oncoTreeCode, "parent", returnedParent, expectedParent));
failureCount = failureCount + 1;
}
// TODO: add checks for children, level, tissue
}
}
// TODO: scan for differences between sets of TumorTypes
if (failureCount > 0) {
fail(Integer.toString(failureCount) + " failed test conditions. Details follow... " + failureReport.toString());
}
return;
}
Aggregations