02 - InvertR - Assignment 1 - Dispersal - Example in R
Watch on YouTube →
Overview
Alex Smith uses a South African velvet-worm dataset to demonstrate an R workflow for inferring dispersal from DNA sequences and geographic locations, while explaining how the same methods apply to the assignment’s deep-sea hydrothermal-vent scenario. The workflow downloads GenBank sequences from accessions, aligns them, builds and annotates a maximum-likelihood phylogeny, tests isolation by distance with a Mantel test, and produces maps and plots for a three-minute assignment presentation.
Key takeaways
- The South African velvet-worm workflow is a methodological stand-in for the hydrothermal-vent assignment: the habitat changes, but the sequence, geography, and dispersal analysis steps transfer.
- GenBank accessions connect individual DNA sequences to collection locations, allowing genetic relationships to be interpreted alongside geographic separation.
- Sequence alignment must precede phylogenetic and distance analysis because unaligned sequences may compare nonhomologous positions.
- A Mantel test is appropriate for testing association between pairwise genetic and geographic distance matrices because those pairwise observations are not independent.
- The example combines a significant positive isolation-by-distance relationship with deep within-species tree branches to infer restricted dispersal among sites.
- The assignment’s final deliverable is an annotated, three-minute video presentation—not simply the generated PDF—and it should relate the figures to hydrothermal-vent vulnerability and mining pressure.
Chapters
- R is a free statistical and programming language widely used in science, where publishing code supports reproducibility.
- Alex Smith recommends installing the current R version from CRAN before installing RStudio, which provides the shared coding environment.
- Download the assignment’s GitHub repository as a ZIP and extract its R script and CSV data into an R working directory.
- The assignment uses genetic evidence to estimate larval dispersal among deep-sea hydrothermal vents and consider implications for isolation, fragmentation, and mining pressure.
- The demonstration uses publicly available South African Onychophora data so students can practice methods that transfer across terrestrial and marine habitats.
- Published site coordinates and DNA accessions let students reanalyze data associated with research on velvet-worm diversity around Cape Town.
- The Source pane displays the R script; lines beginning with # are explanatory comments, while uncommented lines execute code.
- The Console shows commands, output, and errors; the Environment tracks imported objects; and the Plots pane displays generated figures.
- Smith recommends running code in sequence, one block at a time, and checking whether warnings actually prevent later steps from running.
- Use get working directory to see where R expects files; change the directory only if the extracted GitHub files are somewhere else.
- Clear the R environment before starting to avoid accidentally reusing objects with names that conflict with the example.
- Install required packages, including through BiocManager, while online; then call library commands to load them for sequence analysis, mapping, and plotting.
- Read the CSV into R; its columns include GenBank accession, site description, latitude, longitude, and species name.
- Convert coordinates from degrees, minutes, and seconds to decimal degrees, then create a site map using sf, Natural Earth data, and ggplot2.
- Make both a world map and a zoomed-in map showing five collection sites along the South African coast.
- Use the CSV’s accession numbers to retrieve DNA records from GenBank; the example sequences are mitochondrial cytochrome c oxidase I (COI).
- Save sequences in FASTA format and align them before analysis so that comparisons involve homologous regions rather than offset sequence positions.
- Build a maximum-likelihood tree, root it at the midpoint because no outgroup is supplied, and interpret genetic distances from horizontal branch lengths.
- Create a site-by-accession presence–absence matrix, using 1 for a sample present at a site and 0 for absent.
- Color tree tips by species and add geographic site information with tree-plotting tools such as ggtree and ggtree spatial functionality.
- The annotated tree shows four named taxa and highlights deep genetic variation among samples assigned to one species across multiple sites.
- Subset the data to the purple focal species and calculate pairwise geographic distances among its collection sites in kilometers.
- Compare geographic and genetic distance matrices with a Mantel test from vegan, which accounts for pairwise observations that are not independent.
- For the example species, genetic distance increases with geographic distance, and the Mantel result is significant; an additional regression plot visualizes the relationship.
- Export a PDF containing the site map, the species- and site-annotated phylogeny, and the isolation-by-distance plot.
- The assignment submission is not the PDF: students should annotate the figures and record a separate three-minute video answering four questions.
- Use the scheduled Friday lab time to troubleshoot R, interpret the geographic, phylogenetic, and isolation-by-distance results, and connect them to hydrothermal-vent dispersal.
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Alex Smith.