Skip to content

Commit

Permalink
rename feature_symbol to feature_name
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa104 committed Oct 24, 2024
1 parent 0acca60 commit e3b354d
Show file tree
Hide file tree
Showing 20 changed files with 62 additions and 62 deletions.
14 changes: 7 additions & 7 deletions R/OmicSigFromDifexp.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
OmicSigFromDifexp <- function(difexp, metadata, criteria = NULL) {
## define the following to pass R check since they are viewed as variables in dplyr functions
probe_id <- NULL
feature_symbol <- NULL
feature_name <- NULL
score <- NULL
direction <- NULL

Expand Down Expand Up @@ -53,25 +53,25 @@ OmicSigFromDifexp <- function(difexp, metadata, criteria = NULL) {
if ("score" %in% colnames(difexp)) {
if (signatureType %in% c("bi-directional", "categorical")) {
signatures <- signatures %>%
dplyr::select(probe_id, feature_symbol, score, direction) %>%
dplyr::select(probe_id, feature_name, score, direction) %>%
dplyr::arrange(dplyr::desc(abs(score)))
} else {
signatures <- signatures %>%
dplyr::select(probe_id, feature_symbol, score)
dplyr::select(probe_id, feature_name, score)
}
} else {
if (signatureType %in% c("bi-directional", "categorical")) {
signatures <- signatures %>%
dplyr::select(probe_id, feature_symbol, direction)
dplyr::select(probe_id, feature_name, direction)
} else {
signatures <- signatures %>%
dplyr::select(probe_id, feature_symbol)
dplyr::select(probe_id, feature_name)
}
}

signatures <- signatures %>%
dplyr::distinct(feature_symbol, .keep_all = TRUE) %>%
filter(feature_symbol != "", complete.cases(.))
dplyr::distinct(feature_name, .keep_all = TRUE) %>%
filter(feature_name != "", complete.cases(.))

OmicSig <- OmicSignature$new(
metadata = metadata,
Expand Down
36 changes: 18 additions & 18 deletions R/OmicSignature.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ OmicSignature <-
#' @description
#' Create a new OmicSignature object
#' @param metadata required. a list. See `createMetadata` for more information
#' @param signature required. a vector, or a dataframe including columns: "probe_id", "feature_symbol" and "direction", and an optional column "score"
#' @param signature required. a vector, or a dataframe including columns: "probe_id", "feature_name" and "direction", and an optional column "score"
#' @param difexp optional
#' @param print_message use TRUE if want to see all messages printed
#' @export
Expand All @@ -31,10 +31,10 @@ OmicSignature <-
paste(head(setdiff(signature$probe_id, difexp$probe_id)), collapse = " ")
))
}
if (!all(signature$feature_symbol %in% difexp$feature_symbol)) {
if (!all(signature$feature_name %in% difexp$feature_name)) {
stop(paste(
"Some features in signature$feature_symbol are not included in difexp$feature_symbol. Examples:",
paste(head(setdiff(signature$feature_symbol, difexp$feature_symbol)), collapse = " ")
"Some features in signature$feature_name are not included in difexp$feature_name. Examples:",
paste(head(setdiff(signature$feature_name, difexp$feature_name)), collapse = " ")
))
}
}
Expand Down Expand Up @@ -89,35 +89,35 @@ OmicSignature <-
if ("score" %in% colnames(difexp)) {
if (direction_type == "uni-directional") {
res <- res %>%
dplyr::select(probe_id, feature_symbol, score) %>%
dplyr::select(probe_id, feature_name, score) %>%
dplyr::filter(score != "") %>%
dplyr::arrange(desc(abs(score)))
} else if (direction_type == "bi-directional") {
res <- res %>%
dplyr::select(probe_id, feature_symbol, score) %>%
dplyr::select(probe_id, feature_name, score) %>%
dplyr::filter(score != "") %>%
dplyr::mutate(direction = ifelse(score < 0, "-", "+")) %>%
dplyr::arrange(desc(abs(score)))
} else if (direction_type == "categorical") {
res <- res %>%
dplyr::select(probe_id, feature_symbol, score, direction) %>%
dplyr::select(probe_id, feature_name, score, direction) %>%
dplyr::filter(score != "", ) %>%
dplyr::arrange(desc(abs(score)))
}
} else {
if (direction_type == "uni-directional") {
res <- res %>%
dplyr::select(probe_id, feature_symbol)
dplyr::select(probe_id, feature_name)
} else {
res <- res %>%
dplyr::filter(!!!v) %>%
dplyr::select(probe_id, feature_symbol, direction)
dplyr::select(probe_id, feature_name, direction)
}
}

res <- res %>%
dplyr::filter(feature_symbol != "", complete.cases(.)) %>%
dplyr::distinct(feature_symbol, .keep_all = TRUE) %>%
dplyr::filter(feature_name != "", complete.cases(.)) %>%
dplyr::distinct(feature_name, .keep_all = TRUE) %>%
dplyr::mutate(direction = as.character(direction))

return(res)
Expand All @@ -134,7 +134,7 @@ OmicSignature <-
private$.metadata <- private$checkMetadata(value, print_message)
}
},
#' @field signature a dataframe contains probe_id, feature_symbol, score (optional) and direction (optional)
#' @field signature a dataframe contains probe_id, feature_name, score (optional) and direction (optional)
signature = function(value, print_message = FALSE) {
if (missing(value)) {
private$.signature
Expand Down Expand Up @@ -186,7 +186,7 @@ OmicSignature <-
## require any of p_value, q_value, or adj_p
exist_p_columns <- intersect(colnames(difexp), c("p_value", "q_value", "adj_p"))
if (length(exist_p_columns) > 0) {
difexpColRequired <- c("probe_id", "feature_symbol", exist_p_columns)
difexpColRequired <- c("probe_id", "feature_name", exist_p_columns)
} else {
stop("difexp requires at least one of the following columns: p_value, q_value, adj_p.")
}
Expand All @@ -208,10 +208,10 @@ OmicSignature <-
}
}
}
## "feature_symbol" should be character
if ("feature_symbol" %in% colnames(difexp)) {
if (!is(difexp$feature_symbol, "character")) {
stop("difexp: feature_symbol is not character.")
## "feature_name" should be character
if ("feature_name" %in% colnames(difexp)) {
if (!is(difexp$feature_name, "character")) {
stop("difexp: feature_name is not character.")
}
}
private$verbose(v, " [Success] difexp is valid. \n")
Expand Down Expand Up @@ -320,7 +320,7 @@ OmicSignature <-
signature <- standardizeSigDF(signature)

## check column names
signatureColRequired <- c("probe_id", "feature_symbol")
signatureColRequired <- c("probe_id", "feature_name")
if (signatureType != "uni-directional") {
signatureColRequired <- c(signatureColRequired, "direction")
}
Expand Down
2 changes: 1 addition & 1 deletion R/readwriteJson.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ readJson <- function(filename) {
}

#### sig df ####
readSignature <- data.frame("probe_id" = readJson$sig_probe_id, "feature_symbol" = readJson$sig_feature_symbol)
readSignature <- data.frame("probe_id" = readJson$sig_probe_id, "feature_name" = readJson$sig_feature_name)
if (!is.null(readJson$sig_score)) {
readSignature$score <- readJson$sig_score
}
Expand Down
2 changes: 1 addition & 1 deletion R/replaceDifexpCol.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ replaceDifexpCol <- function(colname) {
"adj.p.val" = "adj_p", "adj.p.value" = "adj_p", "adj.p" = "adj_p", "fdr" = "adj_p",
"q.value" = "q_value", "qval" = "q_value"
)
colnameMissing <- setdiff(c("id", "symbol", "score"), colname)
colnameMissing <- setdiff(c("probe_id", "feature_name", "score"), colname)
if (length(colnameMissing) > 0) {
warning(
"Required column for OmicSignature object difexp: ", paste(colnameMissing, collapse = ", "),
Expand Down
8 changes: 4 additions & 4 deletions R/signatureVecToDF.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' @title change a signature vector into a dataframe to be saved into OmicSignature object
#' updated 10/2024
#' @param input a character vector of the symbol of the signature, or a numeric vector which names are signature symbols and values are scores.
#' @param input a character vector of the significant feature names, or a numeric vector which names are feature names and values are scores.
#' @param bi_directional logical.
#' @return signature dataframe with columns "feature_symbol", along with "score" and "direction" if applicable
#' @return signature dataframe with columns "feature_name", along with "score" and "direction" if applicable
#' @examples
#' signatures <- c("gene1", "gene2", "gene3")
#' signatureVecToDF(signatures)
Expand All @@ -16,7 +16,7 @@ signatureVecToDF <- function(input, bi_directional = FALSE) {
if (is.numeric(input) & !is.null(names(input))) {
DF <- data.frame(
"probe_id" = seq(length(input)),
"feature_symbol" = names(input),
"feature_name" = names(input),
"score" = input
)
if (bi_directional) {
Expand All @@ -28,7 +28,7 @@ signatureVecToDF <- function(input, bi_directional = FALSE) {
} else if (is.character(input) | is.factor(input)) {
DF <- data.frame(
"probe_id" = seq(length(input)),
"feature_symbol" = as.character(input)
"feature_name" = as.character(input)
)
} else {
stop("input signature vector is not valid. See `signatureVecToDF()`. ")
Expand Down
4 changes: 2 additions & 2 deletions R/standardizeSigDF.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#' @export
standardizeSigDF <- function(sigdf) {
sigdf <- sigdf %>%
dplyr::filter(feature_symbol != "") %>%
dplyr::filter(feature_name != "") %>%
dplyr::mutate(
probe_id = as.character(probe_id),
feature_symbol = as.character(feature_symbol)
feature_name = as.character(feature_name)
)
if ("score" %in% colnames(sigdf)) {
sigdf <- sigdf %>%
Expand Down
6 changes: 3 additions & 3 deletions inst/extdata/Myc_reduce_mice_liver_24m_obj.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions inst/extdata/OmS_example_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"signature_name": ["Experiment in liver"],
"metadata_length": [10],
"sig_probe_id": [2, 46, 13, 48, 6, 47, 30, 9, 45, 17, 38, 42, 1, 21, 43, 35, 26, 19],
"sig_feature_symbol": ["gene2", "gene46", "gene13", "gene48", "gene6", "gene47", "gene30", "gene9", "gene45", "gene17", "gene38", "gene42", "gene1", "gene21", "gene43", "gene35", "gene26", "gene19"],
"sig_feature_name": ["gene2", "gene46", "gene13", "gene48", "gene6", "gene47", "gene30", "gene9", "gene45", "gene17", "gene38", "gene42", "gene1", "gene21", "gene43", "gene35", "gene26", "gene19"],
"sig_score": [4.99, -4.71, 4.68, -4.67, 4.35, -4.13, 4.09, 3.98, 3.96, -3.94, 3.74, 3.73, 3.69, 3.54, 3.51, 3.37, 3.28, -3.08],
"sig_direction": ["+", "-", "+", "-", "+", "-", "+", "+", "+", "-", "+", "+", "+", "+", "+", "+", "+", "-"],
"difexp_colnames": ["difexp_probe_id", "difexp_feature_symbol", "difexp_score", "difexp_p_value"],
"difexp_colnames": ["difexp_probe_id", "difexp_feature_name", "difexp_score", "difexp_p_value"],
"difexp_probe_id": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50],
"difexp_feature_symbol": ["gene1", "gene2", "gene3", "gene4", "gene5", "gene6", "gene7", "gene8", "gene9", "gene10", "gene11", "gene12", "gene13", "gene14", "gene15", "gene16", "gene17", "gene18", "gene19", "gene20", "gene21", "gene22", "gene23", "gene24", "gene25", "gene26", "gene27", "gene28", "gene29", "gene30", "gene31", "gene32", "gene33", "gene34", "gene35", "gene36", "gene37", "gene38", "gene39", "gene40", "gene41", "gene42", "gene43", "gene44", "gene45", "gene46", "gene47", "gene48", "gene49", "gene50"],
"difexp_feature_name": ["gene1", "gene2", "gene3", "gene4", "gene5", "gene6", "gene7", "gene8", "gene9", "gene10", "gene11", "gene12", "gene13", "gene14", "gene15", "gene16", "gene17", "gene18", "gene19", "gene20", "gene21", "gene22", "gene23", "gene24", "gene25", "gene26", "gene27", "gene28", "gene29", "gene30", "gene31", "gene32", "gene33", "gene34", "gene35", "gene36", "gene37", "gene38", "gene39", "gene40", "gene41", "gene42", "gene43", "gene44", "gene45", "gene46", "gene47", "gene48", "gene49", "gene50"],
"difexp_score": [3.69, 4.99, -1.36, -0.31, -2.13, 4.35, -2.63, 2.22, 3.98, -1.6, 1.38, 2.57, 4.68, 2.44, -1.03, 1.28, -3.94, 1.09, -3.08, -0.4, 3.54, 0.02, 1.41, 1.75, 1.34, 3.28, 0.31, 0.07, -0.22, 4.09, -1.92, 0.7, -0.49, 1.13, 3.37, -0.24, 1.05, 3.74, -0.98, -2.64, 2.98, 3.73, 3.51, -2.17, 3.96, -4.71, -4.13, -4.67, 0.72, -2.4],
"difexp_p_value": [0.001, 0.029, 0.001, 0.002, 0.002, 0.001, 0.002, 0.009, 0.003, 0.026, 0.001, 0.002, 0.001, 0.001, 0.003, 0.003, 0.001, 0.004, 0.001, 0.004, 0.002, 0.003, 0.001, 0.018, 0.02, 0.011, 0.007, 0.001, 0.001, 0.012, 0.003, 0.001, 0.008, 0.001, 0.004, 0.001, 0.003, 0.002, 0.004, 0.002, 0.007, 0.002, 0.005, 0.001, 0.003, 0.002, 0.001, 0.002, 0.001, 0.001]
}
6 changes: 3 additions & 3 deletions inst/extdata/OmS_example_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"signature_name": ["Experiment in brain"],
"metadata_length": [10],
"sig_probe_id": [14, 9, 15, 25, 16, 2, 50, 27, 41, 33, 20, 43, 49, 1, 17, 48, 8, 7, 22, 31, 34, 30],
"sig_feature_symbol": ["gene14", "gene9", "gene15", "gene25", "gene16", "gene2", "gene50", "gene27", "gene41", "gene33", "gene20", "gene43", "gene49", "gene1", "gene17", "gene48", "gene8", "gene7", "gene22", "gene31", "gene34", "gene30"],
"sig_feature_name": ["gene14", "gene9", "gene15", "gene25", "gene16", "gene2", "gene50", "gene27", "gene41", "gene33", "gene20", "gene43", "gene49", "gene1", "gene17", "gene48", "gene8", "gene7", "gene22", "gene31", "gene34", "gene30"],
"sig_score": [-4.99, -4.86, -4.77, -4.62, -4.59, 4.48, -4.44, -4.17, 4.13, -4.11, -4, 3.78, 3.49, 3.45, -3.42, -3.3, -3.28, -3.27, -3.2, -3.05, -3.04, -3.03],
"sig_direction": ["-", "-", "-", "-", "-", "+", "-", "-", "+", "-", "-", "+", "+", "+", "-", "-", "-", "-", "-", "-", "-", "-"],
"difexp_colnames": ["difexp_probe_id", "difexp_feature_symbol", "difexp_score", "difexp_p_value"],
"difexp_colnames": ["difexp_probe_id", "difexp_feature_name", "difexp_score", "difexp_p_value"],
"difexp_probe_id": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50],
"difexp_feature_symbol": ["gene1", "gene2", "gene3", "gene4", "gene5", "gene6", "gene7", "gene8", "gene9", "gene10", "gene11", "gene12", "gene13", "gene14", "gene15", "gene16", "gene17", "gene18", "gene19", "gene20", "gene21", "gene22", "gene23", "gene24", "gene25", "gene26", "gene27", "gene28", "gene29", "gene30", "gene31", "gene32", "gene33", "gene34", "gene35", "gene36", "gene37", "gene38", "gene39", "gene40", "gene41", "gene42", "gene43", "gene44", "gene45", "gene46", "gene47", "gene48", "gene49", "gene50"],
"difexp_feature_name": ["gene1", "gene2", "gene3", "gene4", "gene5", "gene6", "gene7", "gene8", "gene9", "gene10", "gene11", "gene12", "gene13", "gene14", "gene15", "gene16", "gene17", "gene18", "gene19", "gene20", "gene21", "gene22", "gene23", "gene24", "gene25", "gene26", "gene27", "gene28", "gene29", "gene30", "gene31", "gene32", "gene33", "gene34", "gene35", "gene36", "gene37", "gene38", "gene39", "gene40", "gene41", "gene42", "gene43", "gene44", "gene45", "gene46", "gene47", "gene48", "gene49", "gene50"],
"difexp_score": [3.45, 4.48, -1.95, -2.49, -0.64, 1.47, -3.27, -3.28, -4.86, -0.65, -0.04, -0.49, -0.21, -4.99, -4.77, -4.59, -3.42, 2.47, 2.84, -4, 1.28, -3.2, 2.35, 0.5, -4.62, -0.03, -4.17, 0.17, -1.45, -3.03, -3.05, -2.37, -4.11, -3.04, -2.03, 1.67, 0.36, 1.78, -2.76, -2.58, 4.13, 1.86, 3.78, -1.92, 2.65, 2.85, 1.37, -3.3, 3.49, -4.44],
"difexp_p_value": [0.004, 0.001, 0.002, 0.003, 0.005, 0.001, 0.001, 0.002, 0.003, 0.01, 0.002, 0.002, 0.001, 0.002, 0.003, 0.005, 0.002, 0.001, 0.001, 0.001, 0.004, 0.001, 0.067, 0.005, 0.001, 0.001, 0.003, 0.001, 0.001, 0.001, 0.001, 0.011, 0.001, 0.003, 0.002, 0.016, 0.002, 0.001, 0.001, 0.05, 0.002, 0.002, 0.002, 0.01, 0.001, 0.001, 0.002, 0.004, 0.002, 0.002]
}
6 changes: 3 additions & 3 deletions inst/extdata/OmS_example_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"signature_name": ["Experiment in heart"],
"metadata_length": [10],
"sig_probe_id": [28, 32, 25, 49, 6, 38, 43, 27, 46, 39, 11, 29, 15, 2, 14, 4, 9, 45, 24, 33, 47, 16, 10, 7],
"sig_feature_symbol": ["gene28", "gene32", "gene25", "gene49", "gene6", "gene38", "gene43", "gene27", "gene46", "gene39", "gene11", "gene29", "gene15", "gene2", "gene14", "gene4", "gene9", "gene45", "gene24", "gene33", "gene47", "gene16", "gene10", "gene7"],
"sig_feature_name": ["gene28", "gene32", "gene25", "gene49", "gene6", "gene38", "gene43", "gene27", "gene46", "gene39", "gene11", "gene29", "gene15", "gene2", "gene14", "gene4", "gene9", "gene45", "gene24", "gene33", "gene47", "gene16", "gene10", "gene7"],
"sig_score": [4.99, -4.9, 4.71, -4.7, -4.54, -4.44, 4.4, -4.1, 4.09, -4.04, 3.92, 3.88, -3.84, 3.79, 3.72, 3.65, -3.61, -3.42, 3.4, -3.28, -3.16, -3.15, -3.1, -3.03],
"sig_direction": ["+", "-", "+", "-", "-", "-", "+", "-", "+", "-", "+", "+", "-", "+", "+", "+", "-", "-", "+", "-", "-", "-", "-", "-"],
"difexp_colnames": ["difexp_probe_id", "difexp_feature_symbol", "difexp_score", "difexp_p_value"],
"difexp_colnames": ["difexp_probe_id", "difexp_feature_name", "difexp_score", "difexp_p_value"],
"difexp_probe_id": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50],
"difexp_feature_symbol": ["gene1", "gene2", "gene3", "gene4", "gene5", "gene6", "gene7", "gene8", "gene9", "gene10", "gene11", "gene12", "gene13", "gene14", "gene15", "gene16", "gene17", "gene18", "gene19", "gene20", "gene21", "gene22", "gene23", "gene24", "gene25", "gene26", "gene27", "gene28", "gene29", "gene30", "gene31", "gene32", "gene33", "gene34", "gene35", "gene36", "gene37", "gene38", "gene39", "gene40", "gene41", "gene42", "gene43", "gene44", "gene45", "gene46", "gene47", "gene48", "gene49", "gene50"],
"difexp_feature_name": ["gene1", "gene2", "gene3", "gene4", "gene5", "gene6", "gene7", "gene8", "gene9", "gene10", "gene11", "gene12", "gene13", "gene14", "gene15", "gene16", "gene17", "gene18", "gene19", "gene20", "gene21", "gene22", "gene23", "gene24", "gene25", "gene26", "gene27", "gene28", "gene29", "gene30", "gene31", "gene32", "gene33", "gene34", "gene35", "gene36", "gene37", "gene38", "gene39", "gene40", "gene41", "gene42", "gene43", "gene44", "gene45", "gene46", "gene47", "gene48", "gene49", "gene50"],
"difexp_score": [1.96, 3.79, 2.9, 3.65, 2.1, -4.54, -3.03, -0.22, -3.61, -3.1, 3.92, -0.55, -2.98, 3.72, -3.84, -3.15, 0.21, -0.17, -0.91, 0.57, 0.6, 0.94, 2.12, 3.4, 4.71, 1.99, -4.1, 4.99, 3.88, 2.05, 2.38, -4.9, -3.28, -2.21, -2.22, -2.99, 1.92, -4.44, -4.04, 0.15, -2.97, 0.53, 4.4, -1.82, -3.42, 4.09, -3.16, -2.63, -4.7, 1],
"difexp_p_value": [0.001, 0.003, 0.002, 0.002, 0.001, 0.001, 0.026, 0.002, 0.002, 0.006, 0.005, 0.001, 0.005, 0.001, 0.001, 0.001, 0.006, 0.003, 0.002, 0.002, 0.001, 0.25, 0.003, 0.001, 0.001, 0.001, 0.004, 0.007, 0.002, 0.004, 0.091, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.002, 0.002, 0.003, 0.012, 0.02, 0.002, 0.002, 0.002, 0.006, 0.002, 0.002, 0.002]
}
Binary file modified inst/extdata/difmatrix_Myc_mice_liver_24m.rds
Binary file not shown.
Binary file added inst/extdata/feature_dictionary/human_gene.rds
Binary file not shown.
Binary file not shown.
Binary file added inst/extdata/feature_dictionary/mouse_gene.rds
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions man/OmicSignature.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e3b354d

Please sign in to comment.