Skip to content

Commit 0804b7a

Browse files
committed
Merge branch 'dev' of github.com:stemangiola/tidybulk into dev
2 parents d5de0ca + 0e4aa40 commit 0804b7a

File tree

4 files changed

+69
-35
lines changed

4 files changed

+69
-35
lines changed

DESCRIPTION

+1-1
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.9.1
4+
Version: 1.9.2
55
Authors@R: c(person("Stefano", "Mangiola", email = "[email protected]",
66
role = c("aut", "cre")),
77
person("Maria", "Doyle", email = "[email protected]",

R/methods.R

+42-14
Original file line numberDiff line numberDiff line change
@@ -175,28 +175,56 @@ setGeneric("as_SummarizedExperiment", function(.data,
175175
feature_cols = col_direction$vertical_cols
176176
counts_cols = col_direction$counts_cols
177177

178-
colData = .data %>% select(!!.sample, sample_cols) %>% distinct %>% arrange(!!.sample) %>% {
179-
S4Vectors::DataFrame((.) %>% select(-!!.sample),
180-
row.names = (.) %>% pull(!!.sample))
178+
colData =
179+
.data %>%
180+
select(!!.sample, sample_cols) %>%
181+
distinct() %>%
182+
183+
# Unite if multiple sample columns
184+
tidyr::unite(!!sample__$name, !!.sample, remove = FALSE, sep = "___") |>
185+
186+
arrange(!!sample__$symbol) %>% {
187+
S4Vectors::DataFrame(
188+
(.) %>% select(-!!sample__$symbol),
189+
row.names = (.) %>% pull(!!sample__$symbol)
190+
)
181191
}
182192

183-
rowData = .data %>% select(!!.transcript, feature_cols) %>% distinct %>% arrange(!!.transcript) %>% {
184-
S4Vectors::DataFrame((.) %>% select(-!!.transcript),
185-
row.names = (.) %>% pull(!!.transcript))
193+
rowData =
194+
.data %>%
195+
select(!!.transcript, feature_cols) %>%
196+
distinct() %>%
197+
198+
# Unite if multiple sample columns
199+
tidyr::unite(!!feature__$name, !!.transcript, remove = FALSE, sep = "___") |>
200+
201+
arrange(!!feature__$symbol) %>% {
202+
S4Vectors::DataFrame(
203+
(.) %>% select(-!!feature__$symbol),
204+
row.names = (.) %>% pull(!!feature__$symbol)
205+
)
186206
}
187207

188208
my_assays =
189209
.data %>%
190-
select(!!.sample,
191-
!!.transcript,
192-
!!.abundance,
193-
!!.abundance_scaled,
194-
counts_cols) %>%
195-
distinct() %>%
196-
pivot_longer( cols=-c(!!.transcript,!!.sample), names_to="assay", values_to= ".a") %>%
210+
211+
# Unite if multiple sample columns
212+
tidyr::unite(!!sample__$name, !!.sample, remove = FALSE, sep = "___") |>
213+
214+
# Unite if multiple sample columns
215+
tidyr::unite(!!feature__$name, !!.transcript, remove = FALSE, sep = "___") |>
216+
217+
select(!!sample__$symbol,
218+
!!feature__$symbol,
219+
!!.abundance,
220+
!!.abundance_scaled,
221+
counts_cols) %>%
222+
distinct() %>%
223+
224+
pivot_longer( cols=-c(!!feature__$symbol,!!sample__$symbol), names_to="assay", values_to= ".a") %>%
197225
nest(`data` = -`assay`) %>%
198226
mutate(`data` = `data` %>% map(
199-
~ .x %>% spread(!!.sample, .a) %>% as_matrix(rownames = quo_name(.transcript))
227+
~ .x %>% spread(!!sample__$symbol, .a) %>% as_matrix(rownames = feature__$name)
200228
))
201229

202230
# Build the object

R/utilities.R

+14-11
Original file line numberDiff line numberDiff line change
@@ -463,17 +463,17 @@ add_class = function(var, name) {
463463
#' @return A list of column enquo or error
464464
get_sample_transcript_counts = function(.data, .sample, .transcript, .abundance){
465465

466-
if( .sample %>% quo_is_symbol() ) .sample = .sample
466+
if( quo_is_symbolic(.sample) ) .sample = .sample
467467
else if(".sample" %in% (.data %>% get_tt_columns() %>% names))
468468
.sample = get_tt_columns(.data)$.sample
469469
else my_stop()
470470

471-
if( .transcript %>% quo_is_symbol() ) .transcript = .transcript
471+
if( quo_is_symbolic(.transcript) ) .transcript = .transcript
472472
else if(".transcript" %in% (.data %>% get_tt_columns() %>% names))
473473
.transcript = get_tt_columns(.data)$.transcript
474474
else my_stop()
475475

476-
if( .abundance %>% quo_is_symbolic() ) .abundance = .abundance
476+
if( quo_is_symbolic(.abundance) ) .abundance = .abundance
477477
else if(".abundance" %in% (.data %>% get_tt_columns() %>% names))
478478
.abundance = get_tt_columns(.data)$.abundance
479479
else my_stop()
@@ -894,8 +894,8 @@ get_x_y_annotation_columns = function(.data, .horizontal, .vertical, .abundance,
894894
.abundance_scaled = enquo(.abundance_scaled)
895895

896896
# x-annotation df
897-
n_x = .data %>% distinct(!!.horizontal) %>% nrow
898-
n_y = .data %>% distinct(!!.vertical) %>% nrow
897+
n_x = .data %>% select(!!.horizontal) |> distinct() |> nrow()
898+
n_y = .data %>% select(!!.vertical) |> distinct() |> nrow()
899899

900900
# Sample wise columns
901901
horizontal_cols=
@@ -907,8 +907,9 @@ get_x_y_annotation_columns = function(.data, .horizontal, .vertical, .abundance,
907907
.x %>%
908908
when(
909909
.data %>%
910-
distinct(!!.horizontal, !!as.symbol(.x)) %>%
911-
nrow %>%
910+
select(!!.horizontal, !!as.symbol(.x)) %>%
911+
distinct() |>
912+
nrow() %>%
912913
equals(n_x) ~ .x,
913914
~ NULL
914915
)
@@ -928,8 +929,9 @@ get_x_y_annotation_columns = function(.data, .horizontal, .vertical, .abundance,
928929
.x %>%
929930
ifelse_pipe(
930931
.data %>%
931-
distinct(!!.vertical, !!as.symbol(.x)) %>%
932-
nrow %>%
932+
select(!!.vertical, !!as.symbol(.x)) |>
933+
distinct() |>
934+
nrow() %>%
933935
equals(n_y),
934936
~ .x,
935937
~ NULL
@@ -963,8 +965,9 @@ get_x_y_annotation_columns = function(.data, .horizontal, .vertical, .abundance,
963965
.x %>%
964966
ifelse_pipe(
965967
.data %>%
966-
distinct(!!.vertical, !!.horizontal, !!as.symbol(.x)) %>%
967-
nrow %>%
968+
select(!!.vertical, !!.horizontal, !!as.symbol(.x)) %>%
969+
distinct() |>
970+
nrow() %>%
968971
equals(n_x * n_y),
969972
~ .x,
970973
~ NULL

tests/testthat/test-bulk_methods.R

+12-9
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,17 @@ test_that("gene over representation",{
19401940

19411941
})
19421942

1943+
test_that("as_SummarizedExperiment",{
1944+
input_df |>
1945+
as_SummarizedExperiment(
1946+
.sample = c(a, condition),
1947+
.transcript = c(b, entrez),
1948+
.abundance = c
1949+
) |>
1950+
nrow() |>
1951+
expect_equal(527)
1952+
1953+
})
19431954

19441955
# test_that("bibliography",{
19451956
#
@@ -1954,12 +1965,4 @@ test_that("gene over representation",{
19541965
#
19551966
# })
19561967
#
1957-
# test_that("as_SummarizedExperiment",{
1958-
# input_df |>
1959-
# as_SummarizedExperiment(
1960-
# .sample = a,
1961-
# .transcript = b,
1962-
# .abundance = c
1963-
# )
1964-
#
1965-
# })
1968+

0 commit comments

Comments
 (0)