Skip to content

Commit

Permalink
Added CohortDiagnostics output for Breast Cancer work
Browse files Browse the repository at this point in the history
  • Loading branch information
gowthamrao committed Oct 8, 2020
1 parent 0101a17 commit 0767a96
Show file tree
Hide file tree
Showing 24 changed files with 4,496 additions and 0 deletions.
13 changes: 13 additions & 0 deletions CohortDiagnosticsBreastCancer/DiagnosticsExplorer.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
73 changes: 73 additions & 0 deletions CohortDiagnosticsBreastCancer/R/DisplayFunctions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
camelCaseToSnakeCase <- function(string) {
string <- gsub("([A-Z])", "_\\1", string)
string <- tolower(string)
string <- gsub("([a-z])([0-9])", "\\1_\\2", string)
return(string)
}


camelCaseToTitleCase <- function(string) {
string <- gsub("([A-Z])", " \\1", string)
string <- gsub("([a-z])([0-9])", "\\1 \\2", string)
substr(string, 1, 1) <- toupper(substr(string, 1, 1))
return(string)
}


truncateStringDef <- function(columns, maxChars) {
list(
targets = columns,
render = DT::JS(sprintf("function(data, type, row, meta) {\n
return type === 'display' && data != null && data.length > %s ?\n
'<span title=\"' + data + '\">' + data.substr(0, %s) + '...</span>' : data;\n
}", maxChars, maxChars))
)
}

minCellCountDef <- function(columns) {
list(
targets = columns,
render = DT::JS("function(data, type) {
if (type !== 'display' || isNaN(parseFloat(data))) return data;
if (data >= 0) return data.toString().replace(/(\\d)(?=(\\d{3})+(?!\\d))/g, '$1,');
return '<' + Math.abs(data).toString().replace(/(\\d)(?=(\\d{3})+(?!\\d))/g, '$1,');
}")
)
}

minCellPercentDef <- function(columns) {
list(
targets = columns,
render = DT::JS("function(data, type) {
if (type !== 'display' || isNaN(parseFloat(data))) return data;
if (data >= 0) return (100 * data).toFixed(1).replace(/(\\d)(?=(\\d{3})+(?!\\d))/g, '$1,') + '%';
return '<' + Math.abs(100 * data).toFixed(1).replace(/(\\d)(?=(\\d{3})+(?!\\d))/g, '$1,') + '%';
}")
)
}

minCellRealDef <- function(columns, digits = 1) {
list(
targets = columns,
render = DT::JS(sprintf("function(data, type) {
if (type !== 'display' || isNaN(parseFloat(data))) return data;
if (data >= 0) return data.toFixed(%s).replace(/(\\d)(?=(\\d{3})+(?!\\d))/g, '$1,');
return '<' + Math.abs(data).toFixed(%s).replace(/(\\d)(?=(\\d{3})+(?!\\d))/g, '$1,');
}", digits, digits))
)
}

styleAbsColorBar <- function(maxValue, colorPositive, colorNegative, angle = 90) {
DT::JS(sprintf("isNaN(parseFloat(value))? '' : 'linear-gradient(%fdeg, transparent ' + (%f - Math.abs(value))/%f * 100 + '%%, ' + (value > 0 ? '%s ' : '%s ') + (%f - Math.abs(value))/%f * 100 + '%%)'",
angle, maxValue, maxValue, colorPositive, colorNegative, maxValue, maxValue))
}

sumCounts <- function(counts) {
result <- sum(abs(counts))
if (any(counts < 0)) {
return(-result)
} else {
return(result)
}

}
Loading

0 comments on commit 0767a96

Please sign in to comment.