Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow other feature column for SE #236

Merged
merged 2 commits into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Biarch: true
biocViews: AssayDomain, Infrastructure, RNASeq, DifferentialExpression, GeneExpression, Normalization, Clustering, QualityControl, Sequencing, Transcription, Transcriptomics
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2
RoxygenNote: 7.2.0
LazyDataCompression: xz
URL: https://github.com/stemangiola/tidybulk
BugReports: https://github.com/stemangiola/tidybulk/issues
6 changes: 3 additions & 3 deletions R/cibersort.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ my_CIBERSORT <- function(Y, X, perm=0, QN=TRUE, cores = 3, exp_transform = FALSE
###################################
## This is needed to make the two tables consistent in gene
###################################

X <- X[order(rownames(X)),,drop=FALSE]
Y <- Y[order(rownames(Y)),,drop=FALSE]
common_genes = intersect(rownames(X), rownames(Y))
X <- X[common_genes,,drop=FALSE]
Y <- Y[common_genes,,drop=FALSE]

P <- perm #number of permutations

Expand Down
19 changes: 15 additions & 4 deletions R/methods_SE.R
Original file line number Diff line number Diff line change
Expand Up @@ -901,19 +901,30 @@ setMethod("aggregate_duplicates",




#' @importFrom rlang quo_is_symbol
.deconvolve_cellularity_se = function(.data,
reference = X_cibersort,
method = "cibersort",
prefix = "",
...) {

.transcript = enquo(.transcript)

my_assay =
.data %>%

assays() %>%
as.list() %>%
.[[get_assay_scaled_if_exists_SE(.data)]]
.[[get_assay_scaled_if_exists_SE(.data)]] %>%

# Change row names
when(quo_is_symbol(.transcript) ~ {
.x = (.)
rownames(.x) = .data %>% pivot_transcript() %>% pull(!!.transcript)
.x
},
~ (.)
)

# Get the dots arguments
dots_args = rlang::dots_list(...)
Expand Down Expand Up @@ -952,7 +963,7 @@ setMethod("aggregate_duplicates",
reference = reference %>% when(is.null(.) ~ X_cibersort, ~ .)

# Validate reference
validate_signature_SE(.data, reference, !!.transcript)
validate_signature_SE(., reference)

do.call(my_CIBERSORT, list(Y = ., X = reference, QN=FALSE) %>% c(dots_args)) %$%
proportions %>%
Expand All @@ -967,7 +978,7 @@ setMethod("aggregate_duplicates",
reference = reference %>% when(is.null(.) ~ X_cibersort, ~ .)

# Validate reference
validate_signature_SE(.data, reference, !!.transcript)
validate_signature_SE(., reference)

(.) %>%
run_llsr(reference, ...) %>%
Expand Down
43 changes: 24 additions & 19 deletions R/validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -307,33 +307,38 @@ validate_signature = function(.data, reference, .transcript){

.transcript = enquo(.transcript)

if ((.data %>%
pull(!!.transcript) %in% (reference %>% rownames)) %>%
which %>%
length %>%
st(50))
warning(
"tidybulk says: You have less than 50 genes in common between the query data and the reference data. Please check again your input dataframes"
)
overlapping_genes = .data %>% pull(!!.transcript) %in% rownames(reference) %>% which

if(length(overlapping_genes) == 0 )
stop(sprintf(
"\ntidybulk says: You have NO genes in common between the query data and the reference data. Please check again your input dataframes\nthe genes in the reference look like this %s", paste(rownames(reference)[1:10], collapse = ", ")
))

if ( length(overlapping_genes) %>% st(50) )
warning(sprintf(
"\ntidybulk says: You have less than 50 genes in common between the query data and the reference data. Please check again your input dataframes\nthe genes in the reference look like this %s", paste(rownames(reference)[1:10], collapse = ", ")
))

# Check if rownames exist
if (reference %>% sapply(class) %in% c("numeric", "double", "integer") %>% not() %>% any)
stop("tidybulk says: your reference has non-numeric/integer columns.")
stop("tidybulk says: your reference has non-numeric/integer columns.")


}

validate_signature_SE = function(.data, reference, .transcript){
validate_signature_SE = function(assay, reference){

.transcript = enquo(.transcript)
overlapping_genes = (rownames(assay) %in% rownames(reference)) %>% which

if ((.data %>%
rownames %in% (reference %>% rownames)) %>%
which %>%
length %>%
st(50))
warning(
"tidybulk says: You have less than 50 genes in common between the query data and the reference data. Please check again your input dataframes"
)
if(length(overlapping_genes) == 0 )
stop(sprintf(
"\ntidybulk says: You have NO genes in common between the query data and the reference data. Please check again your input dataframes\nthe genes in the reference look like this %s", paste(rownames(reference)[1:10], collapse = ", ")
))

if ( length(overlapping_genes) %>% st(50) )
warning(sprintf(
"\ntidybulk says: You have less than 50 genes in common between the query data and the reference data. Please check again your input dataframes\nthe genes in the reference look like this %s", paste(rownames(reference)[1:10], collapse = ", ")
))

# Check if rownames exist
if (reference %>% sapply(class) %in% c("numeric", "double", "integer") %>% not() %>% any)
Expand Down