Last updated: 2023-10-23

Checks: 5 1

Knit directory: R_workflowr/analysis/

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


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(20230501) 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.

Tracking code development and connecting the code version to the results is critical for reproducibility. To start using Git, open the Terminal and type git init in your project directory.


This project is not being versioned with Git. To obtain the full reproducibility benefits of using workflowr, please see ?wflow_start.


assembly_stats <- read_tsv("../data/assembly_stats/all_assembly_stats.contigs.tsv", col_names = c("genomeName", "stat", "v1", "v2")) %>% 
  mutate(contig = str_detect(genomeName, "contig")) %>% 
  filter(str_detect(genomeName, "M_|mmyo|\\.chr", negate=T)) %>%
  filter(str_detect(genomeName, "mMyo.+1(?!_unmasked)", negate=T)) %>%
  separate(genomeName, c("name", "scaffold"), sep="\\.") %>% 
  arrange(name, contig) %>% 
  select(-scaffold) %>% 
  mutate(name=name %>% str_remove("_unmasked"))
Rows: 27336 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (2): genomeName, stat
dbl (2): v1, v2

ℹ 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.
our_genomes = c(
  "Myotis_auriculus",
  "Myotis_californicus",
  "Myotis_occultus",
  "Myotis_lucifugus",
  "Myotis_yumanensis",
  "Myotis_volans",
  "Myotis_velifer",
  "Myotis_evotis",
  "Myotis_thysanodes"
)
meta <- read_tsv("../data/chiropteraGenomes-20230427.tsv") %>% 
  mutate(`Organism Name` = `Organism Name` %>% str_replace_all(" ", "_"))
Rows: 52 Columns: 33
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (19): Assembly Accession, Assembly Name, Organism Name, Organism Infrasp...
dbl (12): Assembly Stats Total Sequence Length, Assembly Stats Contig N50, A...
lgl  (2): Organism Infraspecific Names Strain, Organism Infraspecific Names ...

ℹ 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.
meta.origin <- meta %>% 
  select(name=`Organism Name`, Origin=Group, Citation) %>% 
  group_by(name) %>% 
  mutate(
    Origin = ifelse(Origin %in% c('Zoonomia', 'Bat1K', 'DNAZoo', 'CCGP'), Origin, 'Other')
  ) %>% 
  bind_rows(assembly_stats %>% filter(str_detect(name, "mMyo")) %>% select(name) %>% distinct %>% mutate(Origin="This Paper", Citation = "This Paper", name = name %>% str_remove("_unmasked")))

assembly_stats.meta <- assembly_stats %>% 
  left_join(meta.origin, by="name") %>% 
  replace_na(list(Origin="Other")) %>% 
  mutate(
    species = name %>% 
      str_replace("mMyoAui.*", "Myotis_auriculus") %>% 
      str_replace("mMyoCai.*", "Myotis_californicus") %>% 
      str_replace("mMyoOcc.*", "Myotis_occultus") %>% 
      str_replace("mMyoLuc.*", "Myotis_lucifugus") %>% 
      str_replace("mMyoYum.*", "Myotis_yumanensis") %>% 
      str_replace("mMyoVol.*", "Myotis_volans") %>% 
      str_replace("mMyoVel.*", "Myotis_velifer") %>% 
      str_replace("mMyoEvo.*", "Myotis_evotis") %>% 
      str_replace("mMyoThy.*", "Myotis_thysanodes") %>% 
      str_replace("_T2T","") %>% 
      str_replace("myoLuc2", "Myotis_lucifugus")
  )

assembly_stats.meta[str_detect(assembly_stats.meta$name, "T2T"),"Origin"] <- "T2T"

Notes about the tree

In order to get TimeTree to play nicely with the phylogeny, a few changes were needed: - Murina aurata feae (replaced with Murina aurata) - Pteropus pselaphon (replaced with Pteropus mariannus) - Miniopterus schreibersii (replace with Miniopterus schreibersii orianae) - Myotis occultus (replaced with Myotis lucifugus lucifugus) - Myotis lucifugus (replaced with Myotis lucifugus carissima) - Hipposideros pendleburyi (replaced with Hipposideros turpis) - TimetreeV5 has split Eptesicus and broken its nomenclature/link to NCBI, so you can’t find “Eptesicus fuscus” anymore. Instead, you have to look for all of Chiroptera or Vespertilliodinae and then look for Eptesicus fuscus hispaniolae.

If you do all these changes, then undo the changes in post, you get this tree. Note that it was very annoying to splice the two trees together by eye so avoid needing to redo this.

tr <- treeio::read.newick("../data/trees/TimeTree.org/genomeSpecies.timetree.nwk")

# setdiff(tr$tip.label, assembly_stats.meta$species)
# setdiff(assembly_stats.meta$species, tr$tip.label)
plot.NGx <- assembly_stats.meta %>% 
  filter(stat == "NGx",
         contig==T
         ) %>% 
  ggplot(aes(x=v1, y=v2, color=Origin, group=name)) + 
  labs(x="NGx", y = "bp", title = "Contig Contiguity") + 
  geom_point() + 
  geom_line() + 
  ylim(1e4,NA) + 
  scale_color_brewer(palette = "Dark2") + 
  # scale_y_log10(limits=c(1e0,NA)) +
  # scale_y_continuous(limits=c(1e0,NA)) +
  theme_pubclean() + 
  labs_pubr() + 
  theme(legend.position = "bottom")
plot.NGx
Warning: Removed 697 rows containing missing values (`geom_point()`).
Warning: Removed 697 rows containing missing values (`geom_line()`).

col.source <- c(
  "This Paper" = "#FFBA08",
  Bat1K = "#B33951",
  T2T = "#d1b1c8",
  Zoonomia = "#4357AD",
  Other = "#6f7c12"
)

plot.NGx.altCol.log <- assembly_stats.meta %>% 
  mutate(Origin = Origin %>% factor(levels=names(col.source))) %>% 
  filter(stat == "NGx",
         contig==T
         ) %>% 
  ggplot(aes(x=v1, y=v2, color=Origin, group=name)) + 
  labs(x="NGx", y = "bp", title = "Contig Contiguity") + 
  # geom_point() + 
  geom_line(linewidth=0.5) + 
  scale_y_log10(lim=c(1e4,NA))+
  scale_color_manual(values=col.source) + 
  theme_pubclean() + 
  labs_pubr() + 
  theme(legend.position = "bottom")
plot.NGx.altCol.log
Warning: Removed 697 rows containing missing values (`geom_line()`).

plot.NGx.altCol <- assembly_stats.meta %>% 
  mutate(Origin = Origin %>% factor(levels=names(col.source))) %>% 
  filter(stat == "NGx",
         contig==T
         ) %>% 
  ggplot(aes(x=v1, y=v2, color=Origin, group=name)) + 
  labs(x="NGx", y = "bp", title = "Contig Contiguity") + 
  # geom_point() + 
  geom_line(linewidth=0.5) + 
  ylim(1e4,NA) +
  scale_color_manual(values=col.source) + 
  theme_pubclean() + 
  labs_pubr() + 
  theme(legend.position = "bottom")
plot.NGx.altCol
Warning: Removed 697 rows containing missing values (`geom_line()`).

plot.NGx.altCol %>% ggsave(plot=., filename = "../output/NGx_curves.pdf", width = 6, height = 3.71, dpi=900, units = "in")
Warning: Removed 697 rows containing missing values (`geom_line()`).
assembly_stats.plotme <- assembly_stats.meta %>% 
  mutate(Origin = Origin %>% factor(levels=names(col.source))) %>% 
  filter(stat == "NGx",
         contig==T
         )
plot.NGx.altCol.t2tzoo <- assembly_stats.plotme %>% 
  ggplot(aes(x=v1, y=v2, color=Origin, group=name)) + 
  labs(x="NGx", y = "bp", title = "Contig Contiguity") + 
  # geom_point() + 
  geom_line(
    data=assembly_stats.plotme %>% filter(Origin %in% c("T2T", "Zoonomia")),
    linewidth=0.5
  ) + 
  ylim(1e4,NA) +
  scale_color_manual(values=col.source) + 
  theme_pubclean() + 
  labs_pubr() + 
  theme(legend.position = "bottom")
plot.NGx.altCol.t2tzoo
Warning: Removed 333 rows containing missing values (`geom_line()`).

plot.NGx.altCol.t2tzoo %>% ggsave(plot=., filename = "../output/NGx_curves_onlyT2TZoonomia.pdf", width = 6, height = 3.71, dpi=900, units = "in")
Warning: Removed 333 rows containing missing values (`geom_line()`).
plot.auNG <- assembly_stats.meta %>% 
  filter(stat == "auNG",
         contig==T
         ) %>% 
  arrange(desc(v2)) %>% 
  mutate(name = factor(name, levels = name %>% unique)) %>% 
  ggplot(aes(x=v2, y=name, color=Origin)) + 
  labs(x="auNG", y = "Assembly", title = "auNG") + 
  geom_point() + 
  scale_color_brewer(palette = "Dark2") + 
  # scale_y_log10(limits=c(1e0,NA)) +
  # scale_y_continuous(limits=c(1e0,NA)) +
  theme_pubclean() + 
  labs_pubr() + 
  theme(legend.position = "bottom")
plot.auNG

auNG <- assembly_stats.meta %>% 
  filter(stat == "auNG",
         contig==T
         ) %>% 
  select(species, Origin, v2, v1) %>% 
  rename(label=species, auNG=v2, genomeSize=v1) %>% 
  filter(!(str_detect(label, "lucifugus") & Origin=="Other"))

color_scale_origin = RColorBrewer::brewer.pal(n=auNG %>% pull(Origin) %>% unique %>% length, name="Dark2") %>% set_names(., auNG %>% pull(Origin) %>% unique)

# tr.auNG <- full_join(tr,auNG)

## Sometimes I hate ggtree
nodes_ourgenomes <- tr %>% 
  as_tibble %>% 
  filter(label %in% our_genomes) %>% 
  select(label, node) %>% 
  deframe()
! # Invaild edge matrix for <phylo>. A <tbl_df> is returned.
p.tr.auNG <- tr %>% 
  ggtree() + 
  geom_tiplab(
    aes(
      subset = (node %in% nodes_ourgenomes)
    ),
    align = T,
    fontface="bold"
    ) +
  geom_tiplab(
    aes(
      subset = !(node %in% nodes_ourgenomes)
    ),
    align = T
    ) +
  xlim_tree(c(NA,250)) +
  geom_facet(
    panel = "auNG (bar)",
    data = auNG,
    geom = geom_col,
    mapping=aes(
      # x = log(1),
      x = log(auNG),
      color=Origin,
      fill=Origin
    ),
    orientation = 'y',
    width = .6
  )+
  geom_facet(
    panel = "auNG (point)", 
    data = auNG, 
    geom = geom_point, 
    mapping=aes(
      # x = log(1),
      x = log(auNG),
      color=Origin,
      fill=Origin
    ), 
    size=2
  )+
  theme_tree2() +
  scale_color_manual("Origin", values = color_scale_origin) +
  scale_fill_manual("Origin", values = color_scale_origin) +
  # geom_facet(panel = "Genome Size", data = auNG %>% select(label, genomeSize, Origin), geom = geom_point, 
  #              mapping=aes(x = genomeSize, color=Origin))+ 
  theme(legend.position = "bottom")
ℹ invalid tbl_tree object. Missing column: parent,node.
ℹ invalid tbl_tree object. Missing column: parent,node.
ℹ invalid tbl_tree object. Missing column: parent,node.
ℹ invalid tbl_tree object. Missing column: parent,node.
p.tr.auNG

auNG.fancy <- auNG %>% 
  mutate(
    label_fancy = sapply(label, . %>% if_else(. %in% our_genomes, str_c("**",.,"**"), .)) %>% 
      str_remove("_mesoamericanus") %>% 
      str_replace_all("_", " ")
  )

angle_rotate <- function(angle){
    # subset1 <- "(angle < 90 | angle > 270)"
    # subset2 <- "(angle >= 90 & angle <=270)"
    if (angle < 90 | angle > 270){
      return(angle)
    } else {
      return(angle+180)
    }
}
h_readjust <- function(angle){
    if (angle < 90 | angle > 270){
      return(0)
    } else {
      return(1)
    }
}

p.tr.auNG.circ <-
  tr %>%
  ggtree(layout = "fan", open.angle=180) +
  xlim_tree(c(NA,100))+ 
  geom_fruit(
    data = auNG.fancy,
    geom = geom_col,
    mapping=aes(
      y= label,
      x = log(auNG),
      color=Origin,
      fill=Origin
    ),
    orientation = 'y',
    width = .6
  ) +
  geom_fruit(
    data = auNG.fancy,
    geom = geom_richtext, 
    mapping = aes(
      y=label,
      label=label_fancy,
      color=Origin,
      angle=sapply(angle,angle_rotate),
      hjust=sapply(angle,h_readjust)
    ),
    fill = NA, 
    label.color = NA, 
    label.padding = grid::unit(rep(0, 4), "pt"),
    
  ) + 
  scale_color_manual("Origin", values = color_scale_origin, guide="none") +
  scale_fill_manual("Origin", values = color_scale_origin,
                    guide = guide_legend(nrow = 2, ncol=6, title.position = "left")) +
  theme(legend.position = c(0.6,0.3), plot.margin = unit(c(4,0,0,0),"cm"))
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
ℹ invalid tbl_tree object. Missing column: parent,node.

ℹ invalid tbl_tree object. Missing column: parent,node.

ℹ invalid tbl_tree object. Missing column: parent,node.

ℹ invalid tbl_tree object. Missing column: parent,node.
p.tr.auNG.circ

species_color = ggsci::pal_d3(palette = "category20")(length(our_genomes)+1) %>% 
  set_names(., c(our_genomes, "Other"))

species_color["Myotis_evotis"] = "#17BECFFF"
species_color["Other"] = "#7F7F7FFF"

auNG.fancy.color <- auNG.fancy %>% 
  mutate(color_me = sapply(label, . %>% ifelse(. %in% our_genomes, ., "Other")))

p.tr.auNG.circ.altcolor <-
  tr %>%
  ggtree(layout = "fan", open.angle=180) +
  xlim_tree(c(NA,100))+ 
  # geom_fruit_list(
    geom_fruit(
      data = auNG.fancy.color,
      geom = geom_col,
      mapping=aes(
        y= label,
        x = log(auNG),
        color=color_me,
        fill=color_me
      ),
      orientation = 'y',
      width = .6
    ) + 
    geom_fruit(
      data = auNG.fancy.color,
      geom = geom_richtext, 
      mapping = aes(
        y=label,
        label=label_fancy,
        color=color_me,
        angle=sapply(angle,angle_rotate),
        hjust=sapply(angle,h_readjust)
      ),
      fill = NA, 
      label.color = NA, 
      # offset=0.2,
      label.padding = grid::unit(rep(0,4), "pt"),
    ) + 
  # ) +
  scale_color_manual("Origin", values = species_color, guide="none") +
  scale_fill_manual("Origin", values = species_color, guide="none") +
  theme(plot.margin = unit(c(4,0,0,0),"cm"))
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
ℹ invalid tbl_tree object. Missing column: parent,node.

ℹ invalid tbl_tree object. Missing column: parent,node.

ℹ invalid tbl_tree object. Missing column: parent,node.

ℹ invalid tbl_tree object. Missing column: parent,node.
p.tr.auNG.circ.altcolor

t2t.base = p.tr.auNG.circ.altcolor$data %>% filter(label == 'Homo_sapiens') %>% pull(x)
! # Invaild edge matrix for <phylo>. A <tbl_df> is returned.
! # Invaild edge matrix for <phylo>. A <tbl_df> is returned.
t2t.bartop = p.tr.auNG.circ.altcolor$layers[[4]]$data %>% filter(label == 'Homo_sapiens') %>% pull(new_xtmp) +
  p.tr.auNG.circ.altcolor$layers[[4]]$data %>% filter(label == 'Homo_sapiens') %>% pull(x)
t2t.start = min(p.tr.auNG.circ.altcolor$data$y)
t2t.end = max(p.tr.auNG.circ.altcolor$data$y)

p.tr.auNG.circ.altcolor.withLine <- p.tr.auNG.circ.altcolor + 
  geom_segment(
    aes(
      x = t2t.base + t2t.bartop,
      xend = t2t.base + t2t.bartop,
      y = t2t.start, 
      yend = t2t.end
    )
  )

sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

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

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
 [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
[10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

time zone: America/Los_Angeles
tzcode source: system (glibc)

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

other attached packages:
 [1] ggsci_3.0.0       ggtext_0.1.2      ggtreeExtra_1.8.1 ggtree_3.6.2     
 [5] patchwork_1.1.3   ggpubr_0.6.0      magrittr_2.0.3    lubridate_1.9.2  
 [9] forcats_1.0.0     stringr_1.5.0     dplyr_1.1.3       purrr_1.0.2      
[13] readr_2.1.4       tidyr_1.3.0       tibble_3.2.1      ggplot2_3.4.3    
[17] tidyverse_2.0.0  

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.0   farver_2.1.1       fastmap_1.1.1      lazyeval_0.2.2    
 [5] promises_1.2.1     digest_0.6.33      timechange_0.2.0   lifecycle_1.0.3   
 [9] tidytree_0.4.5     compiler_4.3.1     rlang_1.1.1        sass_0.4.7        
[13] tools_4.3.1        utf8_1.2.3         yaml_2.3.7         knitr_1.44        
[17] ggsignif_0.6.4     labeling_0.4.3     bit_4.0.5          xml2_1.3.5        
[21] RColorBrewer_1.1-3 aplot_0.2.1        abind_1.4-5        workflowr_1.7.1   
[25] withr_2.5.0        grid_4.3.1         fansi_1.0.5        git2r_0.32.0      
[29] colorspace_2.1-0   scales_1.2.1       cli_3.6.1          rmarkdown_2.25    
[33] crayon_1.5.2       ragg_1.2.5         treeio_1.25.4      generics_0.1.3    
[37] rstudioapi_0.15.0  tzdb_0.4.0         commonmark_1.9.0   ape_5.7-1         
[41] cachem_1.0.8       parallel_4.3.1     ggplotify_0.1.2    vctrs_0.6.3       
[45] yulab.utils_0.1.0  jsonlite_1.8.7     carData_3.0-5      car_3.1-2         
[49] gridGraphics_0.5-1 hms_1.1.3          bit64_4.0.5        rstatix_0.7.2     
[53] systemfonts_1.0.4  magick_2.7.5       ggnewscale_0.4.9   jquerylib_0.1.4   
[57] glue_1.6.2         stringi_1.7.12     gtable_0.3.4       later_1.3.1       
[61] munsell_0.5.0      pillar_1.9.0       htmltools_0.5.6    R6_2.5.1          
[65] textshaping_0.3.6  rprojroot_2.0.3    vroom_1.6.3        evaluate_0.21     
[69] lattice_0.21-8     markdown_1.8       backports_1.4.1    gridtext_0.1.5    
[73] memoise_2.0.1      broom_1.0.5        httpuv_1.6.11      ggfun_0.1.3       
[77] bslib_0.5.1        Rcpp_1.0.11        nlme_3.1-163       xfun_0.40         
[81] fs_1.6.3           pkgconfig_2.0.3