Last updated: 2022-07-06

Checks: 6 1

Knit directory: 20180328_Atkins_RatFracture/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20220705) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 4a20503. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  analysis/alnQC.Rmd
    Untracked:  analysis/rawQC.Rmd
    Untracked:  analysis/trimQC.Rmd
    Untracked:  data/gmt/
    Untracked:  output/genesGR.rds

Unstaged changes:
    Modified:   20180328_Atkins_RatFracture.Rproj
    Modified:   analysis/_site.yml
    Deleted:    analysis/about.Rmd
    Modified:   analysis/index.Rmd
    Deleted:    analysis/license.Rmd
    Modified:   code/runPipeline.sh
    Modified:   data/targets.csv

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


library(ngsReports)
library(tidyverse)
library(yaml)
library(scales)
library(pander)
library(glue)
library(plotly)
library(edgeR)
library(ggfortify)
library(AnnotationHub)
library(ensembldb)
library(magrittr)
library(BSgenome.Rnorvegicus.UCSC.rn6)
panderOptions("table.split.table", Inf)
panderOptions("big.mark", ",")
theme_set(theme_bw())
suffix <- "_L001"
pattern <- paste0("_CB2YGANXX_.+fastq.gz")
sp <- "Rnorvegicus"
rn6 <- BSgenome.Rnorvegicus.UCSC.rn6
samples <- "data/targets.csv" %>%
  here::here() %>%
  read_csv() %>% 
    mutate(
      Filename = paste0(File, suffix)
    )
group_cols <- hcl.colors(
  n = length(unique(samples$group)), 
  palette = "Zissou 1"
  ) %>%
  setNames(unique(samples$group))

Alignment Statistics

alnFiles <- here::here("data/2_alignedData/log") %>%
  list.files(pattern = "Log.final.out", full.names = TRUE) 
alnStats <- alnFiles %>%
  lapply(function(x){
    importNgsLogs(x, type = "star") %>%
      mutate(Filename = x)
  }) %>%
  bind_rows() %>%
  mutate(
    Filename = basename(Filename) %>% 
      str_remove_all("Log.final.out")
  ) %>%
  left_join(samples, by = "Filename") %>%
  as.data.frame()
  • Across all files the total alignment rate ranged between 85.3% and 94.5%
  • Uniquely aligned reads ranged between 45% and 74%
  • The percentages of mapped reads which aligned to ‘too many’ locations and were discarded was between 3.8% and 7.1%
ggplotly(
  alnStats %>%
    dplyr::select(
      Filename, group, contains("Percent"), -Total_Mapped_Percent
    ) %>%
    mutate(
      Unmapped = Percent_Of_Reads_Unmapped_Too_Many_Mismatches +
        Percent_Of_Reads_Unmapped_Too_Short +
        Percent_Of_Reads_Unmapped_Other
    ) %>%
    dplyr::select(
      Filename, group, contains("Mapped", ignore.case = FALSE), Unmapped
    ) %>%
    pivot_longer(
      cols = contains("mapped"),
      names_to = "Category",
      values_to = "Percent"
    ) %>%
    mutate(
      Category = str_remove_all(Category, "(_Percent|Percent_Of_Reads_)"),
      Category = str_replace_all(Category, "_", " "),
      Category = as.factor(Category),
      Category = relevel(Category, ref = "Uniquely Mapped Reads"),
      Category = fct_rev(Category)
    ) %>%
    ggplot(aes(Filename, Percent, fill = Category)) +
    geom_col(colour = "black", size = 0.1) +
    facet_wrap(~group, scales = "free_x") +
    scale_y_continuous(expand = expansion(c(0, 0.05))) +
    scale_fill_viridis_d(option = "E", direction = -1) +
    theme(
      axis.text.x = element_blank(),
      axis.ticks.x = element_blank()
    )
)

Alignment rates across all libraries

Read Assignment To Genes

Annotation Setup

ah <- AnnotationHub() %>%
  subset(rdataclass == "EnsDb") %>%
  subset(species == "Rattus norvegicus") %>% 
  subset(str_detect(description, "96"))
ensDb <- ah[[1]]
genesGR <- genes(ensDb) %>% 
  keepStandardChromosomes(species = "Rattus_norvegicus", pruning.mode = "coarse") %>% 
  sortSeqlevels() 
transGR <- transcripts(ensDb) %>% 
  keepStandardChromosomes(species = "Rattus_norvegicus", pruning.mode = "coarse") %>% 
  sortSeqlevels() 
exonGR <- exonsBy(ensDb, "tx") %>% 
  reduce() %>% 
  keepStandardChromosomes(species = "Rattus_norvegicus", pruning.mode = "coarse") %>% 
  sortSeqlevels() 
exonGR_UCSC <- exonGR
seqlevels(exonGR_UCSC) <- paste0("chr", seqlevels(exonGR_UCSC)) %>% 
  str_replace("chrMT", "chrM")
genome(exonGR_UCSC) <- genome(rn6)
exonSeq <- getSeq(rn6, exonGR_UCSC) %>% 
  lapply(unlist) %>% 
  as("DNAStringSet")
transGC <- exonSeq %>% 
  letterFrequency("GC", as.prob = TRUE) %>% 
  .[,1] %>% 
  setNames(names(exonSeq))
transGR$gc_content <- transGC[names(transGR)]
mcols(transGR) <- mcols(transGR) %>%
  cbind(
    transcriptLengths(ensDb)[rownames(.), c("nexon", "tx_len")]
  )
mcols(genesGR) <- mcols(genesGR) %>%
  as.data.frame() %>%
  dplyr::select(
    gene_id, gene_name, gene_biotype, entrezid
  ) %>%
  left_join(
    mcols(transGR) %>%
      as.data.frame() %>%
      mutate(
        tx_support_level = case_when(
          is.na(tx_support_level) ~ 1L, 
          TRUE ~ tx_support_level
        )
      ) %>%
      group_by(gene_id) %>%
      summarise(
        n_tx = n(),
        longest_tx = max(tx_len),
        ave_tx_len = mean(tx_len),
        gc_content = sum(tx_len*gc_content) / sum(tx_len)
      ) %>%
      mutate(
        bin_length = cut(
          x = ave_tx_len,
          labels = seq_len(10),
          breaks = quantile(ave_tx_len, probs = seq(0, 1, length.out = 11)),
          include.lowest = TRUE
        ),
        bin_gc = cut(
          x = gc_content,
          labels = seq_len(10),
          breaks = quantile(gc_content, probs = seq(0, 1, length.out = 11)),
          include.lowest = TRUE
        ),
        bin = paste(bin_gc, bin_length, sep = "_")
      ),
    by = "gene_id"
  ) %>%
  set_rownames(.$gene_id) %>%
  as("DataFrame")

Annotation data was loaded as an EnsDb object, using Ensembl release 96. Transcript level gene lengths and GC content was converted to gene level values using:

  • GC Content: The total GC content divided by the total length of transcripts
  • Gene Length: The mean transcript length
write_rds(genesGR, here::here("output/genesGR.rds"), compress = "gz")

Counts

countSummary <- here::here("data/2_alignedData/featureCounts/counts.out.summary") %>%
  importNgsLogs(type = "featureCounts") %>%
  mutate(
    Total = rowSums(
      dplyr::select_if(., is.numeric)
    ),
    Filename = basename(Sample) %>% 
      str_remove_all("Aligned.+")
  ) %>%
  dplyr::select(-Sample) %>%
  left_join(samples)

When assigning reads to genes, featureCounts was run setting the following criteria:

  • Libraries were assumed to be negatively stranded
  • The minimum percentage of a read which needed to overlap an exon before being counted was 100%

Using these settings:

  • The percentages of reads assigned to genes ranged between 5% and 21%
  • Of the total reads:
    • Between 7% and 29% were aligned but didn’t overlap any known genes
    • Between 0.051% and 0.131% were unassigned as they were considered ambiguous
ggplotly(
  countSummary %>%
    pivot_longer(
      cols = contains("assigned"),
      names_to = "Status",
      values_to = "Reads"
    ) %>%
    dplyr::filter(Reads > 0) %>%
    mutate(
      Percent = round(100 * Reads / Total, 2)
    ) %>%
    arrange(Percent) %>%
    mutate(
      Status = str_replace_all(Status, "Unassigned_", "Unassigned: "),
      Status = str_replace_all(Status, "_", " "),
      Status = fct_inorder(Status)) %>%
    ggplot(aes(Rat, Percent, fill = Status)) +
    geom_col() +
    facet_wrap(~group, scales = "free") +
    scale_fill_viridis_d(option = "E", direction = -1) +
    scale_y_continuous(
      labels = ngsReports:::.addPercent,
      expand = expansion(c(0, 0.05))
    ) 
)

Rate of mapped reads being assigned to genes

Total Detected Genes

counts <- here::here("data/2_alignedData/featureCounts/counts.out") %>%
  read_tsv(comment = "#") %>%
  rename_all(str_remove_all, pattern = "_CB2Y.++") %>%
  rename_all(basename) %>%
  dplyr::select(-Chr, -Start, -End, -Strand, -Length) %>%
  column_to_rownames("Geneid") %>%
  as.matrix()
  • Of the 32,623 genes defined in this annotation build, 4,508 genes had no reads assigned in any samples.
  • The numbers of genes with at least one read assigned ranged between 18,043 and 25,566 across all samples.
counts %>%
  as_tibble() %>%
  mutate(
    across(everything(), as.logical)
  ) %>%
  summarise(
    across(everything(), sum)
  ) %>%
  pivot_longer(
    everything(), names_to = "Rat", values_to = "Detected"
  ) %>%
  left_join(samples)%>%
  ggplot(aes(group, Detected, colour = group)) +
  geom_point() +
  geom_segment(
    aes(xend = group, y = 0, yend = Detected),
    data = . %>% 
      group_by(group) %>%
      summarise(Detected = min(Detected)),
    colour = "black", size = 1/4) +
  scale_y_continuous(labels = comma, expand = expansion(c(0, 0.05))) +
  scale_colour_manual(values = group_cols) +
  labs(
    x = "Group", 
    y = "Genes Detected",
    colour = "Group"
  )
*Total numbers of genes detected across all samples and groups.*

Total numbers of genes detected across all samples and groups.

plotly::ggplotly(
  counts %>%
    is_greater_than(0) %>%
    rowSums() %>%
    table() %>%
    enframe(name = "n_samples", value = "n_genes") %>%
    mutate(
      n_samples = as.integer(n_samples),
      n_genes = as.integer(n_genes),
    ) %>%
    arrange(desc(n_samples)) %>%
    mutate(
      Detectable = cumsum(n_genes),
      Undetectable = sum(n_genes) - Detectable
    ) %>%
    pivot_longer(
      cols = ends_with("table"),
      names_to = "Status",
      values_to = "Number of Genes"
    ) %>%
    dplyr::rename(
      `Number of Samples` = n_samples,
    ) %>%
    ggplot(aes(`Number of Samples`, `Number of Genes`, colour = Status)) +
    geom_line() +
    geom_vline(
      aes(xintercept = `Mean Sample Number`),
      data = . %>%
        summarise(`Mean Sample Number` = mean(`Number of Samples`)),
      linetype = 2,
      colour = "grey50"
    ) +
    scale_x_continuous(expand = expansion(c(0.01, 0.01))) +
    scale_y_continuous(labels = comma) +
    scale_colour_manual(values = c(rgb(0.1, 0.7, 0.2), rgb(0.7, 0.1, 0.1))) +
    labs(
      x = "Samples > 0"
    )
)

Total numbers of genes detected shown against the number of samples with at least one read assigned to each gene.

Library Sizes

After assignment to genes, library sizes ranged between 4,868,319 and 14,729,011 reads, with a median library size of 10,432,760 reads.

plotly::ggplotly(
  counts %>%
    colSums() %>%
    enframe(
      name = "Rat", value = "Library Size"
    ) %>%
    left_join(samples) %>%
    ggplot(aes(group, `Library Size`, colour = group, label = Filename)) +
    geom_point() +
    geom_segment(
      aes(x = group, xend = group, y = 0, yend = `Library Size`),
      data = . %>% 
        group_by(group) %>%
        summarise(`Library Size` = min(`Library Size`)),
      colour = "black", size = 1/4,
      inherit.aes = FALSE
    ) +
    scale_y_continuous(labels = comma, expand = expansion(c(0, 0.05))) +
    scale_colour_manual(values = group_cols) +
    labs(
      x = "Group", 
      colour = "Group"
    )
)

Library sizes across all samples and groups. 3 saples fell below 10,000 reads which is the general minimum required for a confident analysis

PCA

Sample Similarity

pca <- counts %>%
  .[rowSums(. == 0) < ncol(.)/2,] %>%
  cpm(log = TRUE) %>%
  t() %>%
  prcomp()

A PCA was performed using logCPM values from the subset of 20,382 genes with at least one read in more than half of the samples.

showLabel <- nrow(samples) <= 20
pca %>%
  autoplot(data = samples, colour = "group", label = showLabel, label.repel = showLabel) +
  labs(colour = "Group") +
  scale_colour_manual(values = group_cols)
*PCA plot of all samples.*

PCA plot of all samples.

GC and Length Biases

mcols(genesGR) %>%
  as.data.frame() %>%
  dplyr::filter(gene_id %in% rownames(pca$rotation)) %>%
  as_tibble() %>%
  mutate(
    bin_length = cut(
      x = ave_tx_len,
      labels = seq_len(10),
      breaks = quantile(ave_tx_len, probs = seq(0, 1, length.out = 11)),
      include.lowest = TRUE
    ),
    bin_gc = cut(
      x = gc_content,
      labels = seq_len(10),
      breaks = quantile(gc_content, probs = seq(0, 1, length.out = 11)),
      include.lowest = TRUE
    ),
    bin = paste(bin_gc, bin_length, sep = "_")
  ) %>%
  dplyr::select(gene_id, contains("bin")) %>%
  mutate(
    PC1 = pca$rotation[gene_id, "PC1"],
    PC2 = pca$rotation[gene_id, "PC2"]
  ) %>%
  pivot_longer(
    cols = c("PC1", "PC2"),
    names_to = "PC",
    values_to = "value"
  ) %>%
  group_by(PC, bin_gc, bin_length, bin) %>%
  summarise(
    Size = n(),
    mean = mean(value),
    sd = sd(value),
    t = t.test(value)$statistic,
    p = t.test(value)$p.value,
    adjP = p.adjust(p, method = "bonf")
  ) %>%
  ggplot(
    aes(bin_length, bin_gc, colour = t, alpha = -log10(adjP), size = Size)
  ) +
  geom_point() +
  facet_wrap(~PC) +
  scale_colour_gradient2() +
  scale_size_continuous(range = c(1, 10)) +
  labs(
    x = "Average Transcript Length",
    y = "GC Content",
    alpha = expression(paste(-log[10], p[adj]))) +
  theme(
    panel.grid = element_blank(),
    legend.position = "bottom"
    ) 
*Contribution of each GC/Length Bin to PC1 and PC2. Fill colours indicate the t-statistic, with tranparency denoting significance as -log10(p), using Bonferroni-adjusted p-values.*

Contribution of each GC/Length Bin to PC1 and PC2. Fill colours indicate the t-statistic, with tranparency denoting significance as -log10(p), using Bonferroni-adjusted p-values.


sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8    
 [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8   
 [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] BSgenome.Rnorvegicus.UCSC.rn6_1.4.1 BSgenome_1.64.0                    
 [3] rtracklayer_1.56.0                  Biostrings_2.64.0                  
 [5] XVector_0.36.0                      magrittr_2.0.3                     
 [7] ensembldb_2.20.1                    AnnotationFilter_1.20.0            
 [9] GenomicFeatures_1.48.0              AnnotationDbi_1.58.0               
[11] Biobase_2.56.0                      GenomicRanges_1.48.0               
[13] GenomeInfoDb_1.32.1                 IRanges_2.30.0                     
[15] S4Vectors_0.34.0                    AnnotationHub_3.4.0                
[17] BiocFileCache_2.4.0                 dbplyr_2.1.1                       
[19] ggfortify_0.4.14                    edgeR_3.38.0                       
[21] limma_3.52.0                        plotly_4.10.0                      
[23] glue_1.6.2                          pander_0.6.5                       
[25] scales_1.2.0                        yaml_2.3.5                         
[27] forcats_0.5.1                       stringr_1.4.0                      
[29] dplyr_1.0.9                         purrr_0.3.4                        
[31] readr_2.1.2                         tidyr_1.2.0                        
[33] tidyverse_1.3.1                     ngsReports_1.13.0                  
[35] tibble_3.1.7                        ggplot2_3.3.6                      
[37] BiocGenerics_0.42.0                 workflowr_1.7.0                    

loaded via a namespace (and not attached):
  [1] readxl_1.4.0                  backports_1.4.1              
  [3] lazyeval_0.2.2                crosstalk_1.2.0              
  [5] BiocParallel_1.30.0           digest_0.6.29                
  [7] htmltools_0.5.2               fansi_1.0.3                  
  [9] memoise_2.0.1                 tzdb_0.3.0                   
 [11] modelr_0.1.8                  matrixStats_0.62.0           
 [13] vroom_1.5.7                   prettyunits_1.1.1            
 [15] colorspace_2.0-3              ggrepel_0.9.1                
 [17] blob_1.2.3                    rvest_1.0.2                  
 [19] rappdirs_0.3.3                haven_2.5.0                  
 [21] xfun_0.30                     callr_3.7.0                  
 [23] crayon_1.5.1                  RCurl_1.98-1.6               
 [25] jsonlite_1.8.0                zoo_1.8-10                   
 [27] gtable_0.3.0                  zlibbioc_1.42.0              
 [29] DelayedArray_0.22.0           DBI_1.1.2                    
 [31] Rcpp_1.0.8.3                  viridisLite_0.4.0            
 [33] xtable_1.8-4                  progress_1.2.2               
 [35] bit_4.0.4                     DT_0.22                      
 [37] htmlwidgets_1.5.4             httr_1.4.3                   
 [39] ellipsis_0.3.2                farver_2.1.0                 
 [41] pkgconfig_2.0.3               XML_3.99-0.9                 
 [43] sass_0.4.1                    here_1.0.1                   
 [45] locfit_1.5-9.5                utf8_1.2.2                   
 [47] labeling_0.4.2                tidyselect_1.1.2             
 [49] rlang_1.0.2                   later_1.3.0                  
 [51] munsell_0.5.0                 BiocVersion_3.15.2           
 [53] cellranger_1.1.0              tools_4.2.0                  
 [55] cachem_1.0.6                  cli_3.3.0                    
 [57] generics_0.1.2                RSQLite_2.2.13               
 [59] broom_0.8.0                   evaluate_0.15                
 [61] fastmap_1.1.0                 ggdendro_0.1.23              
 [63] processx_3.5.3                knitr_1.39                   
 [65] bit64_4.0.5                   fs_1.5.2                     
 [67] KEGGREST_1.36.0               whisker_0.4                  
 [69] mime_0.12                     xml2_1.3.3                   
 [71] biomaRt_2.52.0                compiler_4.2.0               
 [73] rstudioapi_0.13               filelock_1.0.2               
 [75] curl_4.3.2                    png_0.1-7                    
 [77] interactiveDisplayBase_1.34.0 reprex_2.0.1                 
 [79] bslib_0.3.1                   stringi_1.7.6                
 [81] highr_0.9                     ps_1.7.0                     
 [83] lattice_0.20-45               ProtGenerics_1.28.0          
 [85] Matrix_1.4-1                  vctrs_0.4.1                  
 [87] pillar_1.7.0                  lifecycle_1.0.1              
 [89] BiocManager_1.30.17           jquerylib_0.1.4              
 [91] data.table_1.14.2             bitops_1.0-7                 
 [93] httpuv_1.6.5                  R6_2.5.1                     
 [95] BiocIO_1.6.0                  promises_1.2.0.1             
 [97] gridExtra_2.3                 MASS_7.3-57                  
 [99] assertthat_0.2.1              SummarizedExperiment_1.26.1  
[101] rprojroot_2.0.3               rjson_0.2.21                 
[103] withr_2.5.0                   GenomicAlignments_1.32.0     
[105] Rsamtools_2.12.0              GenomeInfoDbData_1.2.8       
[107] parallel_4.2.0                hms_1.1.1                    
[109] grid_4.2.0                    rmarkdown_2.14               
[111] MatrixGenerics_1.8.0          git2r_0.30.1                 
[113] getPass_0.2-2                 shiny_1.7.1                  
[115] lubridate_1.8.0               restfulr_0.0.13