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

Dev #242

Merged
merged 51 commits into from
Jun 28, 2022
Merged

Dev #242

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1c68731
implementation parallel cibersort
stemangiola Jun 7, 2022
11e05b3
replace if_else once
stemangiola Jun 12, 2022
29efe9c
make non standard columns not a problem
stemangiola Jun 13, 2022
758e08b
polish and make more robust also for SE
stemangiola Jun 13, 2022
442249f
fix bug
stemangiola Jun 13, 2022
948256a
fix bug
stemangiola Jun 13, 2022
558cf13
simplified aggregate for se and add test
stemangiola Jun 13, 2022
32f915f
implement new vocabulary
stemangiola Jun 24, 2022
f4f5822
replace if_else once
stemangiola Jun 12, 2022
f8d38ba
Merge branch 'dev' of github.com:stemangiola/tidybulk into dev
stemangiola Jun 24, 2022
60f4260
allow other feature column for SE
stemangiola Jun 24, 2022
fedd878
fix typo
stemangiola Jun 24, 2022
f93a90a
fix tidybulk()
stemangiola Jun 24, 2022
601aa4a
avoid human annotation
stemangiola Jun 24, 2022
5ddf54a
update docs
stemangiola Jun 24, 2022
1a1a758
fixed pivot_
stemangiola Jun 24, 2022
a284fc6
deprecate .contrasts and update tests
stemangiola Jun 25, 2022
78c6838
temporary save to work on other branch
stemangiola Jun 25, 2022
0f31e39
get as_tibble from tidySE for tidybulk()
stemangiola Jun 25, 2022
7b4b310
fix tests
stemangiola Jun 25, 2022
4a867ff
fix dependencies
stemangiola Jun 25, 2022
a76efa9
fix examples
stemangiola Jun 25, 2022
d470795
fix tests
stemangiola Jun 25, 2022
9f08092
fix tests
stemangiola Jun 25, 2022
6def641
fix back deconvolution
stemangiola Jun 25, 2022
b31ffe0
Merge pull request #237 from stemangiola/SE_to_tidybulk_new_vocabulary
stemangiola Jun 25, 2022
c0f2962
merge dev
stemangiola Jun 26, 2022
0bc0619
fix aggregation
stemangiola Jun 26, 2022
2b729ef
Merge branch 'dev' into deprecate_dot_contrasts
stemangiola Jun 26, 2022
18f4cf0
Merge pull request #239 from stemangiola/deprecate_dot_contrasts
stemangiola Jun 26, 2022
86d3107
Merge pull request #238 from stemangiola/allow-mapping-to-other-genomes
stemangiola Jun 26, 2022
73175cd
Merge pull request #236 from stemangiola/robustify_deconvolution_SE
stemangiola Jun 26, 2022
b97eec0
deprecation untested
stemangiola Jun 26, 2022
2197096
deprecation untested
stemangiola Jun 26, 2022
38fcfc0
Merge branch 'deprecate_log_transform_for_function' of github.com:ste…
stemangiola Jun 26, 2022
4e3b77c
fix CHECK
stemangiola Jun 26, 2022
a439f77
add docs
stemangiola Jun 26, 2022
a1719ee
fix CHECKs
stemangiola Jun 26, 2022
6898f8d
Merge pull request #235 from stemangiola/polish_aggregation_tibble
stemangiola Jun 26, 2022
1b48d42
Merge pull request #244 from stemangiola/parallel-cibersort
stemangiola Jun 26, 2022
ffc0680
add news and version UP
stemangiola Jun 28, 2022
c3e317c
use |> for tests
stemangiola Jun 28, 2022
527ca24
make tests more detailed
stemangiola Jun 28, 2022
b399314
deprecation untested
stemangiola Jun 26, 2022
0690a9f
fix CHECKs
stemangiola Jun 26, 2022
0c25324
Merge branch 'deprecate_log_transform_for_function' of github.com:ste…
stemangiola Jun 28, 2022
38d0688
drop tsne test
stemangiola Jun 28, 2022
c00ae27
deprecation untested
stemangiola Jun 26, 2022
f47d148
fix CHECKs
stemangiola Jun 26, 2022
9c8ef7a
Merge branch 'deprecate_log_transform_for_function' of github.com:ste…
stemangiola Jun 28, 2022
74c026f
Merge pull request #241 from stemangiola/deprecate_log_transform_for_…
stemangiola Jun 28, 2022
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
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: tidybulk
Title: Brings transcriptomics to the tidyverse
Version: 1.7.3
Version: 1.7.4
Authors@R: c(person("Stefano", "Mangiola", email = "[email protected]",
role = c("aut", "cre")),
person("Maria", "Doyle", email = "[email protected]",
Expand Down Expand Up @@ -32,7 +32,9 @@ Imports:
scales,
SummarizedExperiment,
GenomicRanges,
methods
methods,
S4Vectors,
crayon
Suggests:
BiocStyle,
testthat,
Expand All @@ -53,7 +55,6 @@ Suggests:
Seurat,
KernSmooth,
Rtsne,
S4Vectors,
ggplot2,
widyr,
clusterProfiler,
Expand Down Expand Up @@ -82,7 +83,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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ import(readr)
import(tibble)
import(tidyr)
importFrom(GenomicRanges,makeGRangesListFromDataFrame)
importFrom(S4Vectors,metadata)
importFrom(SummarizedExperiment,SummarizedExperiment)
importFrom(SummarizedExperiment,assays)
importFrom(SummarizedExperiment,colData)
importFrom(SummarizedExperiment,rowData)
importFrom(SummarizedExperiment,rowRanges)
importFrom(dplyr,across)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_rows)
importFrom(dplyr,distinct)
Expand Down
78 changes: 50 additions & 28 deletions R/cibersort.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Public code https://rdrr.io/github/IOBR/IOBR/src/R/CIBERSORT.R

# CIBERSORT R script v1.03 (last updated 07-10-2015)
# Note: Signature matrix construction is not currently available; use java version for full functionality.
# Author: Aaron M. Newman, Stanford University ([email protected])
Expand Down Expand Up @@ -172,6 +174,34 @@ doPerm <- function(perm, X, Y, cores = 3){
newList <- list("dist" = dist)
}

# MADE BY STEFANO TO ALLOW PARALLELISM
call_core = function(itor, Y, X, P, pval, CoreAlg){
##################################
## Analyze the first mixed sample
##################################

y <- Y[,itor]

#standardize mixture
y <- (y - mean(y)) / sd(y)

#run SVR core algorithm
result <- CoreAlg(X, y, cores = 1)

#get results
w <- result$w
mix_r <- result$mix_r
mix_rmse <- result$mix_rmse

#calculate p-value
if(P > 0) {pval <- 1 - (which.min(abs(nulldist - mix_r)) / length(nulldist))}

#print output
c(colnames(Y)[itor],w,pval,mix_r,mix_rmse)

}


#' @importFrom stats sd
#' @importFrom utils install.packages
#'
Expand All @@ -189,9 +219,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 Expand Up @@ -248,45 +278,37 @@ my_CIBERSORT <- function(Y, X, perm=0, QN=TRUE, cores = 3, exp_transform = FALSE
#empirical null distribution of correlation coefficients
if(P > 0) {nulldist <- sort(doPerm(P, X, Y, cores = cores)$dist)}

#print(nulldist)

header <- c('Mixture',colnames(X),"P-value","Correlation","RMSE")
#print(header)

output <- matrix()
itor <- 1
mix <- dim(Y)[2]
pval <- 9999

#iterate through mix
while(itor <= mix){
# If not Windows
if(Sys.info()['sysname'] == 'Windows')
{
while(itor <= mix){

##################################
## Analyze the first mixed sample
##################################
##################################
## Analyze the first mixed sample
##################################

y <- Y[,itor]

#standardize mixture
y <- (y - mean(y)) / sd(y)
out <- call_core(itor, Y, X, P, pval, CoreAlg)
if(itor == 1) {output <- out}
else {output <- rbind(output, out)}
itor <- itor + 1

#run SVR core algorithm
result <- CoreAlg(X, y, cores = cores)
}

#get results
w <- result$w
mix_r <- result$mix_r
mix_rmse <- result$mix_rmse

#calculate p-value
if(P > 0) {pval <- 1 - (which.min(abs(nulldist - mix_r)) / length(nulldist))}

#print output
out <- c(colnames(Y)[itor],w,pval,mix_r,mix_rmse)
if(itor == 1) {output <- out}
else {output <- rbind(output, out)}
}

itor <- itor + 1
# If Linux of Mac
else {
output <- parallel::mclapply(1:mix, call_core, Y, X, P, pval, CoreAlg, mc.cores=cores)
output= matrix(unlist(output), nrow=length(output), byrow=TRUE)

}

Expand Down
5 changes: 5 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@
#'
#'
"counts_SE"

#' Needed for tests tximeta_summarizeToGene_object, It is SummarizedExperiment from tximeta
#'
#'
"tximeta_summarizeToGene_object"
8 changes: 4 additions & 4 deletions R/dplyr_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ rowwise.tidybulk <- function(data, ...)
#'
#' @examples
#'`%>%` = magrittr::`%>%`
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(sample) %>% mutate(source = "AU")
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(.sample) %>% mutate(source = "AU")
#' tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% left_join(annotation)
#'
#' @rdname dplyr-methods
Expand Down Expand Up @@ -763,7 +763,7 @@ left_join.tidybulk <- function (x, y, by = NULL, copy = FALSE, suffix = c(".x",
#'
#' @examples
#'`%>%` = magrittr::`%>%`
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(sample) %>% mutate(source = "AU")
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(.sample) %>% mutate(source = "AU")
#' tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% inner_join(annotation)
#'
#' @rdname join-methods
Expand Down Expand Up @@ -802,7 +802,7 @@ inner_join.tidybulk <- function (x, y, by = NULL, copy = FALSE, suffix = c(".x",
#'
#' @examples
#'`%>%` = magrittr::`%>%`
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(sample) %>% mutate(source = "AU")
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(.sample) %>% mutate(source = "AU")
#' tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% right_join(annotation)
#'
#' @rdname join-methods
Expand Down Expand Up @@ -843,7 +843,7 @@ right_join.tidybulk <- function (x, y, by = NULL, copy = FALSE, suffix = c(".x",
#'
#' @examples
#'`%>%` = magrittr::`%>%`
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(sample) %>% mutate(source = "AU")
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(.sample) %>% mutate(source = "AU")
#' tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% full_join(annotation)
#'
#' @rdname join-methods
Expand Down
Loading