Last updated: 2022-11-15

Checks: 6 1

Knit directory: R_workflowr/

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(20221115) 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 5c92bd2. 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:    R_workflowr/.Rproj.user/
    Ignored:    data/USGS_SpeciesRanges/
    Ignored:    data/tree/

Untracked files:
    Untracked:  R_workflowr/analysis/ng_curves.Rmd
    Untracked:  R_workflowr/analysis/sample_map.Rmd
    Untracked:  R_workflowr/ng_curves.html
    Untracked:  R_workflowr/renv.lock
    Untracked:  R_workflowr/renv/

Unstaged changes:
    Modified:   .gitignore
    Modified:   R_workflowr/README.md
    Modified:   R_workflowr/_workflowr.yml
    Deleted:    R_workflowr/code/README.md
    Modified:   data/README.md

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.


assembly_stats <- read_tsv("~/projects/MyotisGenomeAssembly/data/chiroptera.contig.assembly_stats.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)
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/chiroptera_genomes_20220627.tsv") %>% 
  filter(!is.na(`Assembly BioProject Lineage Parent Accessions`)) %>% 
  mutate(`Organism Name` = `Organism Name` %>% str_replace_all(" ", "_"))
Rows: 129 Columns: 29
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr  (15): Assembly Name, Assembly Accession, Organism Name, Organism Infras...
dbl  (10): Annotation BUSCO Complete, Annotation BUSCO Duplicated, Annotatio...
lgl   (3): Organism Infraspecific Names Strain, Organism Infraspecific Names...
date  (1): Assembly Submission Date

ℹ 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 %>% 
  filter(str_detect(`Assembly BioProject Lineage Title`, "[Aa]ssembl", negate = T)) %>%
  filter(str_detect(`Assembly BioProject Lineage Title`, "Myotis myotis", negate = T)) %>% 
  filter(str_detect(`Assembly BioProject Lineage Title`, "Pipistrellus", negate = T)) %>% 
  select(name=`Organism Name`, `Assembly BioProject Lineage Title`) %>% 
  group_by(name) %>% 
  summarize(Origin = `Assembly BioProject Lineage Title` %>% unique %>% sort %>%  paste(collapse=",")) %>% 
  mutate(Origin = Origin %>% 
           str_replace("The European Reference Genome Atlas,Vertebrate Genomes Project", "Vertebrate Genomes Project") %>% 
           str_replace("Bat1K Project,Vertebrate Genomes Project", "Bat1K Project") %>% 
           str_replace("Genome sequencing for Pteropus vampyrus", "Other") %>% 
           str_replace("Eptesicus fuscus Genome Sequencing", "Other")
         ) %>% 
  bind_rows(assembly_stats %>% filter(str_detect(name, "mMyo")) %>% select(name) %>% distinct %>% mutate(Origin="This Paper"))

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"
assembly_stats.meta[str_detect(assembly_stats.meta$name, "Yum"),"Origin"] <- "CCGP"
tr <- treeio::read.newick("~/projects/MyotisGenomeAssembly/data/tree/species_timetree2.nwk") %>% 
  ape::drop.tip("Rhinolophus_sinicus")

setdiff(tr$tip.label, assembly_stats.meta$species)
character(0)
setdiff(assembly_stats.meta$species, tr$tip.label)
character(0)
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()`).

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


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")

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.
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_point,
      mapping=aes(
        y= label,
        x = log(17.7),
        angle=angle
      ),
      color="black",
      shape = "-",
      size=2,
      vjust = 1,
      hjust = 1
    ),
    geom_fruit(
      data = auNG.fancy.color,
      geom = geom_point,
      mapping=aes(
        y= label,
        x = log(max(auNG)),
        angle=angle
      ),
      color="blue",
      shape = "-",
      size=2,
      vjust = 1,
      hjust = 1
    )
  ) +
  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, 
    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.
Warning in (function (mapping = NULL, data = NULL, stat = "identity", position =
"identity", : Ignoring unknown parameters: `vjust` and `hjust`
Warning in (function (mapping = NULL, data = NULL, stat = "identity", position =
"identity", : Ignoring unknown aesthetics: angle
Warning in (function (mapping = NULL, data = NULL, stat = "identity", position =
"identity", : Ignoring unknown parameters: `vjust` and `hjust`
Warning in (function (mapping = NULL, data = NULL, stat = "identity", position =
"identity", : Ignoring unknown aesthetics: angle
p.tr.auNG.circ.altcolor


sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 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_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] ggsci_2.9         ggtext_0.1.2      ggtreeExtra_1.8.0 ggtree_3.7.1     
 [5] patchwork_1.1.2   ggpubr_0.4.0      magrittr_2.0.3    forcats_0.5.2    
 [9] stringr_1.4.1     dplyr_1.0.10      purrr_0.3.5       readr_2.1.3      
[13] tidyr_1.2.1       tibble_3.1.8      ggplot2_3.4.0     tidyverse_1.3.2  

loaded via a namespace (and not attached):
 [1] googledrive_2.0.0   ggnewscale_0.4.8    colorspace_2.0-3   
 [4] ggsignif_0.6.4      ellipsis_0.3.2      rprojroot_2.0.3    
 [7] markdown_1.3        fs_1.5.2            aplot_0.1.8        
[10] gridtext_0.1.5      rstudioapi_0.14     farver_2.1.1       
[13] bit64_4.0.5         fansi_1.0.3         lubridate_1.9.0    
[16] xml2_1.3.3          cachem_1.0.6        knitr_1.40         
[19] jsonlite_1.8.3      workflowr_1.7.0     broom_1.0.1        
[22] dbplyr_2.2.1        compiler_4.2.2      httr_1.4.4         
[25] backports_1.4.1     assertthat_0.2.1    fastmap_1.1.0      
[28] lazyeval_0.2.2      gargle_1.2.1        cli_3.4.1          
[31] later_1.3.0         htmltools_0.5.3     tools_4.2.2        
[34] gtable_0.3.1        glue_1.6.2          Rcpp_1.0.9         
[37] carData_3.0-5       cellranger_1.1.0    jquerylib_0.1.4    
[40] vctrs_0.5.0         ape_5.6-2           nlme_3.1-160       
[43] xfun_0.34           rvest_1.0.3         timechange_0.1.1   
[46] lifecycle_1.0.3     renv_0.16.0         rstatix_0.7.0      
[49] googlesheets4_1.0.1 scales_1.2.1        vroom_1.6.0        
[52] hms_1.1.2           promises_1.2.0.1    parallel_4.2.2     
[55] RColorBrewer_1.1-3  yaml_2.3.6          ggfun_0.0.8        
[58] yulab.utils_0.0.5   sass_0.4.2          stringi_1.7.8      
[61] highr_0.9           tidytree_0.4.1      rlang_1.0.6        
[64] pkgconfig_2.0.3     commonmark_1.8.1    evaluate_0.18      
[67] lattice_0.20-45     treeio_1.23.0       labeling_0.4.2     
[70] bit_4.0.4           tidyselect_1.2.0    R6_2.5.1           
[73] magick_2.7.3        generics_0.1.3      DBI_1.1.3          
[76] pillar_1.8.1        haven_2.5.1         withr_2.5.0        
[79] abind_1.4-5         modelr_0.1.9        crayon_1.5.2       
[82] car_3.1-1           utf8_1.2.2          tzdb_0.3.0         
[85] rmarkdown_2.17      grid_4.2.2          readxl_1.4.1       
[88] git2r_0.30.1        reprex_2.0.2        digest_0.6.30      
[91] httpuv_1.6.6        gridGraphics_0.5-1  munsell_0.5.0      
[94] ggplotify_0.1.0     bslib_0.4.1