Skip to content

Commit

Permalink
Merge pull request #16 from transmart/sascha-developments
Browse files Browse the repository at this point in the history
code refactoring and bugfixing
  • Loading branch information
rnugraha committed Apr 21, 2016
2 parents 3d30a2f + b378807 commit 88e5cc8
Show file tree
Hide file tree
Showing 19 changed files with 2,642 additions and 2,697 deletions.
6 changes: 4 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
"funcscope" : false, // true: Tolerate defining variables inside control statements

"globalstrict" : true, // true: Allow global "use strict" (also enables 'strict')
"iterator" : false, // true: Tolerate using the `__iterator__` property
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
Expand Down Expand Up @@ -89,6 +89,8 @@
"angular": true,
"module": true,
"inject": true,
"pageInfo": true
"pageInfo": true,
"d3": true,
"Ext": true
} // additional predefined global variables
}
1 change: 1 addition & 0 deletions grails-app/conf/SmartRResources.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ modules = {
resource url: [plugin: 'smart-r', dir: 'js/smartR/_angular/services', file: 'rServeService.js']
resource url: [plugin: 'smart-r', dir: 'js/smartR/_angular/services', file: 'smartRUtils.js']
resource url: [plugin: 'smart-r', dir: 'js/smartR/_angular/services', file: 'commonWorkflowService.js']
resource url: [plugin: 'smart-r', dir: 'js/smartR/_angular/services', file: 'controlElements.js']
}

smartR_all {
Expand Down
18 changes: 10 additions & 8 deletions grails-app/views/layouts/_boxplot.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
label="Numerical Variable"
tooltip="Select a single numerical variable that you would like to have displayed.">
</concept-box>
<concept-box style="display: inline-block;"
concept-group="conceptBoxes.subsets"
type="LD-categorical"
min="0"
max="-1"
label="(optional) Categorical Variables"
tooltip="Select an arbitrary amount of categorical variables to split the numerical variable into subsets.">
</concept-box>
%{--Nice idea but somehow lost it's initial purpose because cross-study support is gone.
Maybe implement later--}%
%{--<concept-box style="display: inline-block;"--}%
%{--concept-group="conceptBoxes.subsets"--}%
%{--type="LD-categorical"--}%
%{--min="0"--}%
%{--max="-1"--}%
%{--label="(optional) Categorical Variables"--}%
%{--tooltip="Select an arbitrary amount of categorical variables to split the numerical variable into subsets.">--}%
%{--</concept-box>--}%
<br/>
<br/>
<fetch-button concept-map="conceptBoxes" show-summary-stats="false" disabled="false"></fetch-button>
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/layouts/_heatmap.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<workflow-tab tab-name="Preprocess" disabled="preprocess.disabled">
%{--Aggregate Probes--}%
<div class="heim-input-field">
<input type="checkbox" ng-model="preprocess.params.aggregateProbes">
<input type="checkbox" ng-model="preprocess.params.aggregate">
<span>Aggregate probes</span>
</div>

Expand Down
3 changes: 2 additions & 1 deletion test/unit/javascript/smartRUtilsServiceTests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

describe('smartRUtils', function() {
'use strict';

var smartRUtils;

Expand Down
72 changes: 35 additions & 37 deletions web-app/HeimScripts/boxplot/run.R
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
}
12 changes: 8 additions & 4 deletions web-app/js/smartR/_angular/controllers/boxplot.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@

window.smartRApp.controller('BoxplotController',
['$scope', 'smartRUtils', 'commonWorkflowService', function($scope, smartRUtils, commonWorkflowService) {
'use strict';

window.smartRApp.controller('BoxplotController', [
'$scope',
'smartRUtils',
'commonWorkflowService',
function($scope, smartRUtils, commonWorkflowService) {

commonWorkflowService.initializeWorkflow('boxplot', $scope);

// model
$scope.conceptBoxes = {
datapoints: [],
subsets: []
datapoints: []
};
$scope.scriptResults = {};
$scope.params = {};
Expand Down
2 changes: 1 addition & 1 deletion web-app/js/smartR/_angular/controllers/heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ window.smartRApp.controller('HeatmapController',
disabled: true,
running: false,
params: {
aggregateProbes: false
aggregate: false
},
scriptResults: {}
};
Expand Down
26 changes: 11 additions & 15 deletions web-app/js/smartR/_angular/directives/fetchButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ window.smartRApp.directive('fetchButton', [
},
templateUrl: $rootScope.smartRPath + '/js/smartR/_angular/templates/fetchButton.html',
link: function(scope, element) {

var template_btn = element.children()[0],
template_msg = element.children()[1];

Expand Down Expand Up @@ -66,19 +65,13 @@ window.smartRApp.directive('fetchButton', [
}
};

var _afterDataFetched = function() {
if (!scope.showSummaryStats) {
_onSuccess();
} else {
template_msg.innerHTML =
'Execute summary statistics, please wait <span class="blink_me">_</span>';

rServeService.executeSummaryStats('fetch')
.then(
function(data) { scope.summaryData = data.result; }, // this will trigger $watch
_onFailure
);
}
var _showSummaryStats = function() {
template_msg.innerHTML = 'Execute summary statistics, please wait <span class="blink_me">_</span>';
rServeService.executeSummaryStats('fetch')
.then(
function(data) { scope.summaryData = data.result; }, // this will trigger $watch
_onFailure
);
};

template_btn.onclick = function() {
Expand All @@ -105,7 +98,10 @@ window.smartRApp.directive('fetchButton', [
var dataConstraints = _getDataConstraints(scope.biomarkers);

rServeService.loadDataIntoSession(conceptKeys, dataConstraints)
.then(_afterDataFetched, _onFailure);
.then(
scope.showSummaryStats ? _showSummaryStats : _onSuccess,
_onFailure
);
};
}
};
Expand Down
134 changes: 58 additions & 76 deletions web-app/js/smartR/_angular/directives/preprocessButton.js
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
);
};
}
};
}]);
Loading

0 comments on commit 88e5cc8

Please sign in to comment.