-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from transmart/sascha-developments
code refactoring and bugfixing
- Loading branch information
Showing
19 changed files
with
2,642 additions
and
2,697 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
'use strict'; | ||
|
||
describe('smartRUtils', function() { | ||
'use strict'; | ||
|
||
var smartRUtils; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,45 @@ | ||
|
||
main <- function( excludedPatientIDs = integer() ) { | ||
datapoints <- parse.input(sourceLabel="datapoints", loaded_variables=loaded_variables, type="numerical") | ||
datapoints <- na.omit(datapoints) | ||
colnames(datapoints)[2] <- 'value' | ||
|
||
subsets <- parse.input(sourceLabel="subsets", loaded_variables=loaded_variables, type="categorical") | ||
|
||
if (nrow(subsets) > 0) { | ||
df <- merge(datapoints, subsets, by="patientID") | ||
levels(df$category) <- c(levels(df$category), "no subset") | ||
df$category[df$category == ""] <- "no subset" | ||
} else { | ||
df <- datapoints | ||
df$category <- "no subset" | ||
} | ||
|
||
df$jitter <- runif(nrow(df), -0.5, 0.5) | ||
|
||
if (! is.null(excludedPatientIDs)) { | ||
df <- df[! df$patientID %in% excludedPatientIDs, ] | ||
} | ||
patientIDs <- df$patientID | ||
main <- function(excludedPatientIDs = integer()) { | ||
|
||
output <- list() | ||
output$concept <- fetch_params$ontologyTerms$datapoints_n0$fullName | ||
output$globalMin <- min(df[,2]) | ||
output$globalMax <- max(df[,2]) | ||
output$categories <- unique(df$category) | ||
output$excludedPatientIDs <- excludedPatientIDs | ||
|
||
for (cat in unique(df$category)) { | ||
subset <- df[df$category == cat,] | ||
bxp <- boxplot(subset[,2], plot=FALSE) | ||
output[[cat]] <- list() | ||
output[[cat]]$lowerWhisker <- bxp$stats[1] | ||
output[[cat]]$lowerHinge <- bxp$stats[2] | ||
output[[cat]]$median <- bxp$stats[3] | ||
output[[cat]]$upperHinge <- bxp$stats[4] | ||
output[[cat]]$upperWhisker <- bxp$stats[5] | ||
outlier <- subset[,2] > output[[cat]]$upperWhisker | subset[,2] < output[[cat]]$lowerWhisker | ||
subset$outlier <- outlier | ||
output[[cat]]$points <- subset | ||
df1 <- loaded_variables$datapoints_n0_s1 | ||
df1 <- prepareData(df1, excludedPatientIDs) | ||
output <- addBoxplotStats(output, "Subset 1", df1) | ||
output$globalMin <- min(df1$value) | ||
output$globalMax <- max(df1$value) | ||
|
||
if(!is.null(loaded_variables$datapoints_n0_s2)) { | ||
df2 <- loaded_variables$datapoints_n0_s2 | ||
df2 <- prepareData(df2, excludedPatientIDs) | ||
output <- addBoxplotStats(output, "Subset 2", df2) | ||
output$globalMin <- min(df1$value, df2$value) | ||
output$globalMax <- max(df1$value, df2$value) | ||
} | ||
|
||
toJSON(output) | ||
} | ||
|
||
prepareData <- function(df, excludedPatientIDs) { | ||
df <- na.omit(df) | ||
df$jitter <- runif(nrow(df), -0.5, 0.5) | ||
colnames(df) <- c("patientID", "value", "jitter") | ||
df <- df[!df$patientID %in% excludedPatientIDs, ] | ||
df | ||
} | ||
|
||
addBoxplotStats <- function(output, subset, df) { | ||
bxp <- boxplot(df$value, plot=FALSE) | ||
output[[subset]] <- list() | ||
output[[subset]]$lowerWhisker <- bxp$stats[1] | ||
output[[subset]]$lowerHinge <- bxp$stats[2] | ||
output[[subset]]$median <- bxp$stats[3] | ||
output[[subset]]$upperHinge <- bxp$stats[4] | ||
output[[subset]]$upperWhisker <- bxp$stats[5] | ||
outlier <- df$value > output[[subset]]$upperWhisker | df$value < output[[subset]]$lowerWhisker | ||
df$outlier <- outlier | ||
output[[subset]]$rawData <- df | ||
output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 58 additions & 76 deletions
134
web-app/js/smartR/_angular/directives/preprocessButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,60 @@ | ||
//# sourceURL=preprocessButton.js | ||
|
||
window.smartRApp.directive('preprocessButton', ['rServeService', | ||
function(rServeService) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
running: '=', | ||
params: '=', | ||
showSummaryStats: '=', | ||
summaryData: '=' | ||
}, | ||
template: | ||
'<input type="button" value="Preprocess" class="heim-action-button">' + | ||
'<span style="padding-left: 10px;"></span>', | ||
link: function(scope, element) { | ||
var template_btn = element.children()[0]; | ||
var template_msg = element.children()[1]; | ||
|
||
scope.$watch('summaryData', function (newSummaryData) { | ||
if (newSummaryData.hasOwnProperty('allSamples')) { | ||
// when everything is retrieved | ||
scope.disabled = false; | ||
} | ||
}, true); | ||
|
||
template_btn.onclick = function() { | ||
|
||
var _init = function () { | ||
template_btn.disabled = true; | ||
scope.summaryData = {}; // reset | ||
scope.disabled = true; | ||
scope.running = true; | ||
template_msg.innerHTML = 'Preprocessing, please wait <span class="blink_me">_</span>'; | ||
}, | ||
|
||
_args = {aggregate:scope.params.aggregateProbes}, | ||
|
||
_preprocessData = function (_args) { | ||
return rServeService.preprocess(_args).then(function (msg){ | ||
return msg; | ||
}); | ||
}, | ||
|
||
_finishedPreprocessed = function (msg) { | ||
template_msg.innerHTML = 'Success: ' + msg; | ||
scope.disabled = false; | ||
scope.running = false; | ||
}, | ||
|
||
_afterDataPreprocessed = function (msg) { | ||
template_btn.disabled = false; | ||
|
||
if (!scope.showSummaryStats) { | ||
return _finishedPreprocessed(msg); | ||
} | ||
template_msg.innerHTML = 'Execute summary statistics, please wait <span class="blink_me">_</span>'; | ||
|
||
return rServeService.executeSummaryStats('preprocess') | ||
.then (function (data) { | ||
scope.summaryData = data.result; | ||
template_msg.innerHTML = 'Success: ' + data.msg; | ||
scope.running = false; | ||
}, function(msg) { | ||
template_msg.innerHTML = 'Failure: ' + msg; | ||
scope.running = false; | ||
}) | ||
}; | ||
|
||
_init(); | ||
|
||
_preprocessData(_args) | ||
.then(_afterDataPreprocessed, _afterDataPreprocessed); | ||
|
||
}; | ||
} | ||
}; | ||
}]); | ||
'use strict'; | ||
|
||
window.smartRApp.directive('preprocessButton', [ | ||
'rServeService', | ||
'$rootScope', | ||
function(rServeService, $rootScope) { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
running: '=?', | ||
params: '=?', | ||
showSummaryStats: '=', | ||
summaryData: '=' | ||
}, | ||
templateUrl: $rootScope.smartRPath + '/js/smartR/_angular/templates/preprocessButton.html', | ||
link: function(scope, element) { | ||
|
||
var template_btn = element.children()[0]; | ||
var template_msg = element.children()[1]; | ||
|
||
var _onSuccess = function() { | ||
template_msg.innerHTML = 'Task complete!'; | ||
template_btn.disabled = false; | ||
scope.running = false; | ||
}; | ||
|
||
var _onFail = function(msg) { | ||
template_msg.innerHTML = 'Error: ' + msg; | ||
template_btn.disabled = false; | ||
scope.running = false; | ||
}; | ||
|
||
var _showSummaryStats = function() { | ||
template_msg.innerHTML = 'Execute summary statistics, please wait <span class="blink_me">_</span>'; | ||
rServeService.executeSummaryStats('preprocess').then( | ||
function (data) { | ||
scope.summaryData = data.result; | ||
_onSuccess(); | ||
}, | ||
_onFail | ||
); | ||
}; | ||
|
||
template_btn.onclick = function() { | ||
scope.summaryData = {}; | ||
scope.disabled = true; | ||
scope.running = true; | ||
template_msg.innerHTML = 'Preprocessing, please wait <span class="blink_me">_</span>'; | ||
|
||
var params = scope.params ? scope.params : {}; | ||
rServeService.preprocess(params).then( | ||
scope.showSummaryStats ? _showSummaryStats : _onSuccess, | ||
_onFail | ||
); | ||
}; | ||
} | ||
}; | ||
}]); |
Oops, something went wrong.