Skip to content

Commit 9d98380

Browse files
authored
Merge pull request #242 from stemangiola/dev
Dev
2 parents 7830bc2 + 74c026f commit 9d98380

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1686
-1199
lines changed

DESCRIPTION

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: tidybulk
33
Title: Brings transcriptomics to the tidyverse
4-
Version: 1.7.3
4+
Version: 1.7.4
55
Authors@R: c(person("Stefano", "Mangiola", email = "[email protected]",
66
role = c("aut", "cre")),
77
person("Maria", "Doyle", email = "[email protected]",
@@ -32,7 +32,9 @@ Imports:
3232
scales,
3333
SummarizedExperiment,
3434
GenomicRanges,
35-
methods
35+
methods,
36+
S4Vectors,
37+
crayon
3638
Suggests:
3739
BiocStyle,
3840
testthat,
@@ -53,7 +55,6 @@ Suggests:
5355
Seurat,
5456
KernSmooth,
5557
Rtsne,
56-
S4Vectors,
5758
ggplot2,
5859
widyr,
5960
clusterProfiler,
@@ -82,7 +83,7 @@ Biarch: true
8283
biocViews: AssayDomain, Infrastructure, RNASeq, DifferentialExpression, GeneExpression, Normalization, Clustering, QualityControl, Sequencing, Transcription, Transcriptomics
8384
Encoding: UTF-8
8485
LazyData: true
85-
RoxygenNote: 7.1.2
86+
RoxygenNote: 7.2.0
8687
LazyDataCompression: xz
8788
URL: https://github.com/stemangiola/tidybulk
8889
BugReports: https://github.com/stemangiola/tidybulk/issues

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ import(readr)
8181
import(tibble)
8282
import(tidyr)
8383
importFrom(GenomicRanges,makeGRangesListFromDataFrame)
84+
importFrom(S4Vectors,metadata)
8485
importFrom(SummarizedExperiment,SummarizedExperiment)
8586
importFrom(SummarizedExperiment,assays)
8687
importFrom(SummarizedExperiment,colData)
8788
importFrom(SummarizedExperiment,rowData)
8889
importFrom(SummarizedExperiment,rowRanges)
90+
importFrom(dplyr,across)
8991
importFrom(dplyr,arrange)
9092
importFrom(dplyr,bind_rows)
9193
importFrom(dplyr,distinct)

R/cibersort.R

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Public code https://rdrr.io/github/IOBR/IOBR/src/R/CIBERSORT.R
2+
13
# CIBERSORT R script v1.03 (last updated 07-10-2015)
24
# Note: Signature matrix construction is not currently available; use java version for full functionality.
35
# Author: Aaron M. Newman, Stanford University ([email protected])
@@ -172,6 +174,34 @@ doPerm <- function(perm, X, Y, cores = 3){
172174
newList <- list("dist" = dist)
173175
}
174176

177+
# MADE BY STEFANO TO ALLOW PARALLELISM
178+
call_core = function(itor, Y, X, P, pval, CoreAlg){
179+
##################################
180+
## Analyze the first mixed sample
181+
##################################
182+
183+
y <- Y[,itor]
184+
185+
#standardize mixture
186+
y <- (y - mean(y)) / sd(y)
187+
188+
#run SVR core algorithm
189+
result <- CoreAlg(X, y, cores = 1)
190+
191+
#get results
192+
w <- result$w
193+
mix_r <- result$mix_r
194+
mix_rmse <- result$mix_rmse
195+
196+
#calculate p-value
197+
if(P > 0) {pval <- 1 - (which.min(abs(nulldist - mix_r)) / length(nulldist))}
198+
199+
#print output
200+
c(colnames(Y)[itor],w,pval,mix_r,mix_rmse)
201+
202+
}
203+
204+
175205
#' @importFrom stats sd
176206
#' @importFrom utils install.packages
177207
#'
@@ -189,9 +219,9 @@ my_CIBERSORT <- function(Y, X, perm=0, QN=TRUE, cores = 3, exp_transform = FALSE
189219
###################################
190220
## This is needed to make the two tables consistent in gene
191221
###################################
192-
193-
X <- X[order(rownames(X)),,drop=FALSE]
194-
Y <- Y[order(rownames(Y)),,drop=FALSE]
222+
common_genes = intersect(rownames(X), rownames(Y))
223+
X <- X[common_genes,,drop=FALSE]
224+
Y <- Y[common_genes,,drop=FALSE]
195225

196226
P <- perm #number of permutations
197227

@@ -248,45 +278,37 @@ my_CIBERSORT <- function(Y, X, perm=0, QN=TRUE, cores = 3, exp_transform = FALSE
248278
#empirical null distribution of correlation coefficients
249279
if(P > 0) {nulldist <- sort(doPerm(P, X, Y, cores = cores)$dist)}
250280

251-
#print(nulldist)
252281

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

256284
output <- matrix()
257285
itor <- 1
258286
mix <- dim(Y)[2]
259287
pval <- 9999
260288

261-
#iterate through mix
262-
while(itor <= mix){
289+
# If not Windows
290+
if(Sys.info()['sysname'] == 'Windows')
291+
{
292+
while(itor <= mix){
263293

264-
##################################
265-
## Analyze the first mixed sample
266-
##################################
294+
##################################
295+
## Analyze the first mixed sample
296+
##################################
267297

268-
y <- Y[,itor]
269298

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

273-
#run SVR core algorithm
274-
result <- CoreAlg(X, y, cores = cores)
304+
}
275305

276-
#get results
277-
w <- result$w
278-
mix_r <- result$mix_r
279-
mix_rmse <- result$mix_rmse
280-
281-
#calculate p-value
282-
if(P > 0) {pval <- 1 - (which.min(abs(nulldist - mix_r)) / length(nulldist))}
283-
284-
#print output
285-
out <- c(colnames(Y)[itor],w,pval,mix_r,mix_rmse)
286-
if(itor == 1) {output <- out}
287-
else {output <- rbind(output, out)}
306+
}
288307

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

291313
}
292314

R/data.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@
5757
#'
5858
#'
5959
"counts_SE"
60+
61+
#' Needed for tests tximeta_summarizeToGene_object, It is SummarizedExperiment from tximeta
62+
#'
63+
#'
64+
"tximeta_summarizeToGene_object"

R/dplyr_methods.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ rowwise.tidybulk <- function(data, ...)
723723
#'
724724
#' @examples
725725
#'`%>%` = magrittr::`%>%`
726-
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(sample) %>% mutate(source = "AU")
726+
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(.sample) %>% mutate(source = "AU")
727727
#' tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% left_join(annotation)
728728
#'
729729
#' @rdname dplyr-methods
@@ -763,7 +763,7 @@ left_join.tidybulk <- function (x, y, by = NULL, copy = FALSE, suffix = c(".x",
763763
#'
764764
#' @examples
765765
#'`%>%` = magrittr::`%>%`
766-
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(sample) %>% mutate(source = "AU")
766+
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(.sample) %>% mutate(source = "AU")
767767
#' tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% inner_join(annotation)
768768
#'
769769
#' @rdname join-methods
@@ -802,7 +802,7 @@ inner_join.tidybulk <- function (x, y, by = NULL, copy = FALSE, suffix = c(".x",
802802
#'
803803
#' @examples
804804
#'`%>%` = magrittr::`%>%`
805-
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(sample) %>% mutate(source = "AU")
805+
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(.sample) %>% mutate(source = "AU")
806806
#' tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% right_join(annotation)
807807
#'
808808
#' @rdname join-methods
@@ -843,7 +843,7 @@ right_join.tidybulk <- function (x, y, by = NULL, copy = FALSE, suffix = c(".x",
843843
#'
844844
#' @examples
845845
#'`%>%` = magrittr::`%>%`
846-
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(sample) %>% mutate(source = "AU")
846+
#' annotation = tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% distinct(.sample) %>% mutate(source = "AU")
847847
#' tidybulk::counts_SE %>% tidybulk() %>% as_tibble() %>% full_join(annotation)
848848
#'
849849
#' @rdname join-methods

0 commit comments

Comments
 (0)