Skip to contents

This function returns a dataframe having first column gene names and subsequent columns are fold change values for the comparisons passed through sample_comparisons.

Usage

get_fold_change_matrix(x, sample_comparisons, genes)

Arguments

x

an abject of class "parcutils". This is an output of the function run_deseq_analysis().

sample_comparisons

a character vector denoting sample comparisons for which fold change values to be derived.

genes

a character vector denoting gene names for which fold change values to be derived.

Value

a dataframe.

Examples

count_file <- system.file("extdata","toy_counts.txt" , package = "parcutils")
count_data <- readr::read_delim(count_file, delim = "\t")
#> Rows: 5000 Columns: 10
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: "\t"
#> chr (1): gene_id
#> dbl (9): control_rep1, control_rep2, control_rep3, treat1_rep1, treat1_rep2,...
#> 
#>  Use `spec()` to retrieve the full column specification for this data.
#>  Specify the column types or set `show_col_types = FALSE` to quiet this message.

sample_info <- count_data %>% colnames() %>% .[-1]  %>%
 tibble::tibble(samples = . , groups = rep(c("control" ,"treatment1" , "treatment2"), each = 3) )


res <- run_deseq_analysis(counts = count_data ,
                         sample_info = sample_info,
                         column_geneid = "gene_id" ,
                         group_numerator = c("treatment1", "treatment2") ,
                         group_denominator = c("control"))
#>  Running DESeq2 ...
#> converting counts to integer mode
#> Warning: some variables in design formula are characters, converting to factors
#> estimating size factors
#> estimating dispersions
#> gene-wise dispersion estimates
#> mean-dispersion relationship
#> final dispersion estimates
#> fitting model and testing
#>  Done.
#>  Summarizing DEG ...
#>  Done.

genes = parcutils::get_genes_by_regulation(x = res, sample_comparison = "treatment2_VS_control") %>% names()

fc_df <- get_fold_change_matrix(x = res, sample_comparison = c("treatment2_VS_control" , "treatment1_VS_control"), genes = genes)

print(fc_df)
#> # A tibble: 835 × 3
#>    gene_id                 treatment1_VS_control treatment2_VS_control
#>    <chr>                                   <dbl>                 <dbl>
#>  1 ENSG00000139263:LRIG3                 -0.138                  -1.18
#>  2 ENSG00000072135:PTPN18                -0.589                  -1.93
#>  3 ENSG00000204531:POU5F1                -0.155                  -1.06
#>  4 ENSG00000144840:RABL3                 -0.157                  -1.76
#>  5 ENSG00000178597:PSAPL1                -0.191                  -1.68
#>  6 ENSG00000186472:PCLO                  -0.687                  -2.17
#>  7 ENSG00000155918:RAET1L                 0.467                   2.63
#>  8 ENSG00000151458:ANKRD50               -0.0441                  1.91
#>  9 ENSG00000151623:NR3C2                 -0.298                  -2.83
#> 10 ENSG00000172725:CORO1B                -0.400                  -2.10
#> # … with 825 more rows