Skip to content

Commit

Permalink
style: make names camelCase for conformance with Bioconductor rules
Browse files Browse the repository at this point in the history
Signed-off-by: Ali Sajid Imami <395482+AliSajid@users.noreply.github.com>
  • Loading branch information
AliSajid committed Apr 22, 2024
1 parent 550f1f6 commit ba9fe1f
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ linters: linters_with_tags(
indentation_linter(indent = 4L, hanging_indent_style = "tidy"),
undesirable_function_linter(modify_defaults(defaults = default_undesirable_functions, library = NULL)),
object_usage_linter = NULL,
object_name_linter(styles = c("snake_case", "camelCase", "PascalCase", "dotted.case")))
object_name_linter(styles = c("camelCase")))
encoding: "UTF-8"
exclusions: list(
"renv/activate.R",
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exclude: '.*\.(csv|tsv|xls)$'
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.4.0
rev: v0.4.2
hooks:
- id: use-tidy-description
- id: codemeta-description-updated
Expand Down Expand Up @@ -44,7 +44,7 @@ repos:
- id: no-debug-statement
- id: deps-in-desc
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
args: ['--maxkb=500']
Expand All @@ -59,7 +59,7 @@ repos:
- --fix=no
- id: trailing-whitespace
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v3.1.0
rev: v3.2.0
hooks:
- args:
- build
Expand All @@ -78,7 +78,7 @@ repos:
stages:
- commit-msg
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
rev: v1.5.5
hooks:
- id: forbid-crlf
- id: remove-crlf
Expand Down
24 changes: 12 additions & 12 deletions R/consensus_concordants.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
#'
#' @examples
#' TRUE
target_rename <- function(input_names) {
if ("treatment" %in% input_names) {
new_cols <- c(
targetRename <- function(inputNames) {
if ("treatment" %in% inputNames) {
newCols <- c(
"TargetSignature", "Target", "TargetCellLine",
"TargetTime", "Similarity", "sig_direction"
)
} else {
new_cols <- c(
newCols <- c(
"TargetSignature", "Target", "TargetCellLine",
"TargetTime", "TargetConcentration", "Similarity", "sig_direction"
)
}

new_cols
newCols
}

#' Generate a Consensus list of Targets
Expand Down Expand Up @@ -48,10 +48,10 @@ target_rename <- function(input_names) {
#'
#' @examples
#' TRUE
consensus_concordants <- function(...,
paired = FALSE,
cutoff = 0.321,
cell_line = NULL) {
consensusConcordants <- function(...,
paired = FALSE,
cutoff = 0.321,
cellLine = NULL) {
if (paired && length(list(...)) != 2L) {
stop("Paired analysis requires two data frames")
} else if (!paired && length(list(...)) != 1L) {
Expand All @@ -60,9 +60,9 @@ consensus_concordants <- function(...,

concordants <- dplyr::bind_rows(list(...))

if (!is.null(cell_line)) {
if (!is.null(cellLine)) {
concordants <- concordants %>%
dplyr::filter(.data[["cellline"]] %in% cell_line)
dplyr::filter(.data[["cellline"]] %in% cellLine)
}

filtered <- concordants %>%
Expand All @@ -80,7 +80,7 @@ consensus_concordants <- function(...,
))
) %>%
dplyr::arrange(dplyr::desc(abs(.data[["similarity"]]))) %>%
dplyr::rename_with(target_rename) %>%
dplyr::rename_with(targetRename) %>%
dplyr::ungroup()

filtered
Expand Down
16 changes: 8 additions & 8 deletions R/filter_signature.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#'
#' @examples
#' TRUE
filter_signature <- function(signature, direction = "any",
threshold = NULL, prop = NULL) {
filterSignature <- function(signature, direction = "any",
threshold = NULL, prop = NULL) {
stopifnot("data.frame" %in% class(signature))

if (!is.null(threshold) && !is.null(prop)) {
Expand All @@ -42,17 +42,17 @@ filter_signature <- function(signature, direction = "any",

if (!is.null(threshold)) {
if (length(threshold) == 2L) {
down_threshold <- threshold[[1L]]
up_threshold <- threshold[[2L]]
downThreshold <- threshold[[1L]]
upThreshold <- threshold[[2L]]
} else if (length(threshold) == 1L) {
down_threshold <- -threshold
up_threshold <- threshold
downThreshold <- -threshold
upThreshold <- threshold
} else {
stop("Threshold must be specified as one or two values")
}
} else if (!is.null(prop)) {
down_threshold <- quantile(signature[["Value_LogDiffExp"]], prop)
up_threshold <- quantile(signature[["Value_LogDiffExp"]], 1.0 - prop)
downThreshold <- quantile(signature[["Value_LogDiffExp"]], prop)
upThreshold <- quantile(signature[["Value_LogDiffExp"]], 1.0 - prop)
}

if (direction == "up") {
Expand Down
16 changes: 8 additions & 8 deletions R/get_concordants.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@
#'
#' @examples
#' TRUE
get_concordants <- function(signature, ilincs_library = "CP",
sig_direction = NULL) {
getConcordants <- function(signature, ilincsLibrary = "CP",
sigDirection = NULL) {
if (!"data.frame" %in% class(signature)) {
stop("signature must be a data frame or data frame like object")
} else {
signature_file <- tempfile(pattern = "ilincs_sig", fileext = ".xls")
signatureFile <- tempfile(pattern = "ilincs_sig", fileext = ".xls")
signature %>%
readr::write_tsv(signature_file)
readr::write_tsv(signatureFile)
}

lib_map <- c(
libMap <- c(
OE = "LIB_11",
KD = "LIB_6",
CP = "LIB_5"
)

if (!ilincs_library %in% c("OE", "KD", "CP")) {
if (!ilincsLibrary %in% c("OE", "KD", "CP")) {
stop("library must be one of 'OE', 'KD' or 'CP'")
}

url <- "http://www.ilincs.org/api/SignatureMeta/uploadAndAnalyze"
query <- list(lib = lib_map[ilincs_library])
query <- list(lib = libMap[ilincsLibrary])
body <- list(file = httr::upload_file(signature_file))

request <- httr::POST(url, query = query, body = body)
Expand All @@ -65,7 +65,7 @@ get_concordants <- function(signature, ilincs_library = "CP",
dplyr::mutate(
similarity = round(.data[["similarity"]], 8L),
pValue = round(.data[["pValue"]], 20L),
sig_direction = sig_direction
sig_direction = sigDirection
)
return(concordants)
} else {
Expand Down
8 changes: 4 additions & 4 deletions R/get_signature.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
#'
#' @examples
#' TRUE
get_signature <- function(sig_id, l1000 = TRUE) {
getSignature <- function(sigId, l1000 = TRUE) {
url <- "http://www.ilincs.org/api/ilincsR/downloadSignature"

if (l1000) {
num_genes <- 978L
numGenes <- 978L
} else {
num_genes <- 25000L
numGenes <- 25000L
}

query <- list(sigID = sig_id, noOfTopGenes = num_genes)
query <- list(sigID = sigId, noOfTopGenes = numGenes)

request <- httr::POST(url, query = query)

Expand Down
110 changes: 55 additions & 55 deletions R/investigate_signature.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,96 +37,96 @@
#'
#' @examples
#' TRUE
investigate_signature <- function(expr,
output_lib,
filter_threshold = NULL,
filter_prop = NULL,
similarity_threshold = 0.2,
paired = TRUE,
output_cell_lines = NULL,
gene_column = "Symbol",
logfc_column = "logFC",
pval_column = "PValue",
source_name = "Input",
source_cell_line = "NA",
source_time = "NA",
source_concentration = "NA") {
investigateSignature <- function(expr,
outputLib,
filterThreshold = NULL,
filterProp = NULL,
similarityThreshold = 0.2,
paired = TRUE,
outputCellLines = NULL,
geneColumn = "Symbol",
logfcColumn = "logFC",
pvalColumn = "PValue",
sourceName = "Input",
sourceCellLine = "NA",
sourceTime = "NA",
sourceConcentration = "NA") {
libs <- c("OE", "KD", "CP")

if (!output_lib %in% libs) {
if (!outputLib %in% libs) {
stop("Output library must be one of 'OE', 'KD', 'CP'")
}

if (missing(output_lib)) {
if (missing(outputLib)) {
stop("Please specify an output library")
}

expr_signature <- expr %>%
prepare_signature(
gene_column = gene_column,
logfc_column = logfc_column,
pval_column = pval_column
exprSignature <- expr %>%
prepareSignature(
gene_column = geneColumn,
logfc_column = logfcColumn,
pval_column = pvalColumn
)

signature_id <- unique(expr_signature[["signatureID"]])
signatureId <- unique(exprSignature[["signatureID"]])

if (paired) {
filtered_up <- expr_signature %>%
filter_signature(
filteredUp <- exprSignature %>%
filterSignature(
direction = "up",
threshold = filter_threshold,
prop = filter_prop
threshold = filterThreshold,
prop = filterProp
)

filtered_down <- expr_signature %>%
filter_signature(
filteredDown <- exprSignature %>%
filterSignature(
direction = "down",
threshold = filter_threshold,
prop = filter_prop
threshold = filterThreshold,
prop = filterProp
)

concordant_up <- filtered_up %>%
get_concordants(ilincs_library = output_lib, sig_direction = "Up")
concordantUp <- filteredUp %>%
getConcordants(ilincs_library = outputLib, sig_direction = "Up")

concordant_down <- filtered_down %>%
get_concordants(ilincs_library = output_lib, sig_direction = "Down")
concordantDown <- filteredDown %>%
getConcordants(ilincs_library = outputLib, sig_direction = "Down")


consensus_targets <-
consensus_concordants(
concordant_up,
concordant_down,
consensusTargets <-
consensusConcordants(
concordantUp,
concordantDown,
paired = paired,
cell_line = output_cell_lines,
cutoff = similarity_threshold
cell_line = outputCellLines,
cutoff = similarityThreshold
)
} else {
filtered <- expr_signature %>%
filter_signature(
filtered <- exprSignature %>%
filterSignature(
direction = "any",
threshold = filter_threshold,
prop = filter_prop
threshold = filterThreshold,
prop = filterProp
)

concordants <- filtered %>%
get_concordants(ilincs_library = output_lib)
getConcordants(ilincs_library = outputLib)

consensus_targets <-
consensus_concordants(
consensusTargets <-
consensusConcordants(
concordants,
paired = paired,
cell_line = output_cell_lines,
cutoff = similarity_threshold
cell_line = outputCellLines,
cutoff = similarityThreshold
)
}

augmented <- consensus_targets %>%
augmented <- consensusTargets %>%
dplyr::mutate(
SourceSignature = signature_id,
Source = source_name,
SourceCellLine = source_cell_line,
SourceTime = source_time,
InputSignatureDirection = sig_direction
SourceSignature = signatureId,
Source = sourceName,
SourceCellLine = sourceCellLine,
SourceTime = sourceTime,
InputSignatureDirection = sigDirection
) %>%
dplyr::select(
dplyr::any_of(c(
Expand Down
Loading

0 comments on commit ba9fe1f

Please sign in to comment.