stemangiola / cellsig

GNU General Public License v3.0
1 stars 1 forks source link

user interface #56

Closed stemangiola closed 1 year ago

stemangiola commented 2 years ago

Hello @Kamran-Khan96,

I have a Bayes quantiles as such

# A tibble: 1,449,323 × 10
   symbol      cell_type .feature_idx variable  lower_quantile  `50%` upper_quantile log_mean log_sd file                                            
   <fct>       <fct>            <int> <chr>              <dbl>  <dbl>          <dbl>    <dbl>  <dbl> <chr>                                           
 1 ABCC1       b_memory             1 Y_gen[1]          1038.   2511          5677.    7.81    0.704 dev/modeling_results//level_1_cell_type_b_memor…
 2 ABCD1P5     b_memory             2 Y_gen[2]             0       0             0     0.0462  0.293 dev/modeling_results//level_1_cell_type_b_memor…
 3 ABI1        b_memory             3 Y_gen[3]          5614.  10174.        17182.    9.22    0.561 dev/modeling_results//level_1_cell_type_b_memor…
 4 ABLIM3      b_memory             4 Y_gen[4]             0       2            28     1.27    1.30  dev/modeling_results//level_1_cell_type_b_memor…
 5 AC004866.3  b_memory             5 Y_gen[5]             0       0             0     0.0237  0.195 dev/modeling_results//level_1_cell_type_b_memor…
 6 AC005537.2  b_memory             6 Y_gen[6]            26.9   134           527.    4.84    1.54  dev/modeling_results//level_1_cell_type_b_memor…
 7 AC005682.5  b_memory             7 Y_gen[7]            71.9   317          1645.    5.76    1.34  dev/modeling_results//level_1_cell_type_b_memor…
 8 AC005703.2  b_memory             8 Y_gen[8]             0       0             0     0.0379  0.194 dev/modeling_results//level_1_cell_type_b_memor…
 9 AC005789.9  b_memory             9 Y_gen[9]             0       0             1     0.216   0.603 dev/modeling_results//level_1_cell_type_b_memor…
10 AC006335.11 b_memory            10 Y_gen[10]            0       4            39.1   1.75    1.48  dev/modeling_results//level_1_cell_type_b_memor…
# … with 1,449,313 more rows

But I get this error

sample not found in .data. quantiles should not be forced to have sample column, could you please solve this in the backend.

This is the code that generated the error

 .level <- "root"

    tibble(level = .level) %>%

      mutate(tt = map(level, ~ .imputed_counts %>%

                        # non-hierarchical methods should only compare leaf cell types
                        filter(!!.cell_type %in% as.phylo(.tree)$tip.label) %>% 

                        # create a root column for pre(.level)
                        mutate(!!as.symbol(.level) := !!.cell_type) %>%
                        mutate(!!as.symbol(pre(.level)) := .level) %>%

                        create_hierarchy_and_calculate_imputation_ratio(.level=.x, .sample=!!.sample, .symbol=!!.symbol))) 

I would like this to work

marker_genes = 

  count %>%

  markers_from_transcription_abundance_quantiles(

    .sample = sample, 
    .symbol = symbol, 
    .count= count,
    .cell_type = cell_type,

    quantile_dataset = bayes_quantiles,
    lower_quantile = "10%",
    upper_quantile = "90%",

    contrast_method = pairwise_contrast,
    selection_method = "silhouette", 
    reduction_method = "PCA", 
    dims=2, 
    discard_number = 10,
    optimisation_method = "penalty",
    is_complete = TRUE
  )
stemangiola commented 2 years ago

I should specify that all backhand functions have been transferred to the functions.R file (so automatically imported by cellsig on loading) rather than the custom file within the dev directory.

So we should fix those functions within the functions.R.

The code in the vignette "bayes" I am trying to run is

# Select only leaves
cell_types = data.tree::as.Node(yaml::read_yaml(here("dev/tree_kamran.yaml")))$leaves %>% purrr::map(~ .x$name) %>% as.character()

# Get data
bayes_quantiles = readRDS(here("dev/modeling_results/counts_bayes.rds")) %>% dplyr::filter(cell_type %in% cell_types) %>% rename(symbol=.feature)
counts = readRDS(here("dev/counts.rds")) %>% dplyr::filter(cell_type %in% cell_types) 
library(tidybulk)
library(tidySummarizedExperiment)
feature_selected = counts %>% 

  # Get markers
  markers_from_transcription_abundance_quantiles(

    .sample = sample, 
    .symbol = symbol, 
    .count= count,
    .cell_type = cell_type,

    quantile_dataset = bayes_quantiles,
    lower_quantile = `10%`,
    upper_quantile = `90%`,

    contrast_method = pairwise_contrast,
    selection_method = "silhouette", 
    reduction_method = "PCA", 
    dims=2, 
    discard_number = 10,
    optimisation_method = "penalty",
    is_complete = TRUE
  )
Kamran-Khan96 commented 2 years ago

Hi @stemangiola,

Sorry for the delayed reply.

It's because the Bayes_quantile file requires a sample column. As the direct output of your bayes run doesn't have that sample column. I run by creating a pseudo-sample column.

bayes_quantiles = readRDS(here("dev/modeling_results/counts_bayes.rds")) %>% 
                                             dplyr::filter(cell_type %in% cell_types) %>% 
                                             rename(symbol=.feature) %>%
                                             mutate(id = "sample", sample = cell_type)  %>%
                                             unite(sample, id, sample, sep = "_")
stemangiola commented 2 years ago

Thanks,

yes I understand. But the user should now have to do this explicitly, but this should be done in the backend.

Kamran-Khan96 commented 2 years ago

Hi @stemangiola ,

Sorry, my bad! I wasn't sure if the bayes quantile output will always miss the sample column.

I've implemented the sample column generation in the backend. Please merge Kamran branch for the updated function.

Now, no need to rename .feature column header and manual addition of sample column is also not needed anymore.

Just load bayes_quantile file as follows-

bayes_quantiles = readRDS(here("dev/jian_R_files/test_count_bayes.rds"))

So, the Bayes_quantile file should have at least four columns- gene symbol/feature, cell_type, lower_quantile and upper_quantile

image

Kamran-Khan96 commented 1 year ago

Obsolete