02 - InvertR - Assignment 1 - Dispersal - Example in R
Overview
Alex Smith demonstrates an R workflow for estimating dispersal from genetic and geographic data, using South African velvet worms as a terrestrial analogue for the assignment on deep-sea hydrothermal-vent taxa. The workflow moves from GitHub data and GenBank COI sequences through coordinate mapping, sequence alignment, a midpoint-rooted maximum-likelihood phylogeny, and a Mantel test of isolation by distance, producing three figures for students to interpret in a recorded response.
Key takeaways
- The South African velvet-worm example demonstrates a transferable workflow for the hydrothermal-vent assignment because the same genetic and geographic distance analyses apply across habitats.
- GenBank accession numbers connect the site table to mitochondrial COI sequences, while coordinate conversion and mapping connect each sequence to its collection location.
- Sequence alignment must precede phylogenetic analysis so that comparisons use homologous nucleotide regions rather than offset sequence positions.
- A midpoint-rooted maximum-likelihood tree shows genetic relationships, while its horizontal branch lengths represent evolutionary distance and its vertical spacing is only for layout.
- A Mantel test assesses correlation between pairwise genetic and geographic distance matrices; a regression plot can illustrate the pattern but is a distinct analysis.
- The final assignment evidence consists of three figures, a site map, an annotated phylogeny, and an isolation-by-distance plot, discussed in a recorded response rather than submitted only as a PDF.
Chapters
- The assignment uses genetic evidence to estimate larval dispersal and interpret isolation, fragmentation, and vulnerability at deep-sea hydrothermal vents.
- R is free, widely used in science, and supports reproducible research by making analysis code shareable alongside data and conclusions.
- Alex Smith frames the example as practice with transferable R skills, encouraging students to experiment because their local copy can be restored from GitHub.
- Update R by uninstalling the old version and installing the newest release from CRAN before installing RStudio.
- Download the assignment repository from GitHub using Code, then Download ZIP, and unzip its R script and CSV data file.
- Place the unzipped files in the R working directory so the script can read the CSV and save outputs.
- The assignment's target system is deep-sea hydrothermal vents, but the demonstration uses velvet worms, members of Onychophora, collected around Cape Town, South Africa.
- The analysis method is habitat-agnostic: genetic distances and geographic distances can be compared in terrestrial or marine systems.
- Publicly available site coordinates and DNA sequence accessions let students reanalyze the data rather than only read the conclusions of published studies.
- RStudio's source pane displays the R script, the console reports commands and errors, the environment lists loaded objects, and the plots pane displays figures.
- Lines beginning with # are explanatory comments; uncommented code blocks perform the analysis.
- Use get working directory to locate the active folder, and optionally set a custom path; the tutorial is written for Windows and notes that Mac paths can differ.
- Clear the environment before starting to prevent objects with duplicate names from interfering with later commands.
- Install the required packages with BiocManager, then load libraries including ape, Biostrings, vegan, sf, and mapping tools.
- Read the CSV into R; its fields include GenBank accessions, collection site, latitude, longitude, and species name.
- Convert latitude and longitude from degrees, minutes, and seconds to decimal degrees, then turn the coordinates into spatial data.
- Use Natural Earth data, sf, and ggplot2 to plot the sites on a world map and a Cape Town regional map.
- Use the CSV accession identifiers to retrieve mitochondrial cytochrome c oxidase subunit I sequences from GenBank.
- Save the retrieved sequences in FASTA format and inspect them in a browser to check their nucleotide content and alignment.
- Align sequences before phylogenetic analysis because unaligned sequences may compare nonhomologous regions.
- Inserted gaps, shown as dashes, shift shorter sequences into alignment with corresponding regions in longer sequences.
- Use aligned sequences to build a maximum-likelihood phylogeny, then midpoint-root the tree because the example has no outgroup.
- Interpret evolutionary distance from the summed horizontal branch lengths; vertical spacing separates branches but does not represent genetic distance.
- Create a site-by-sample presence-absence matrix, with 1 for a sample found at a site and 0 for absence.
- Color tree tips by species and add collection-site information to show how lineages are distributed across the five South African sites.
- Focus on the purple species and calculate pairwise geographic distances among its collection sites, converting the results to kilometers.
- Compare the geographic distance matrix with pairwise genetic distances using a Mantel test from the vegan package.
- The example's significant positive relationship means samples farther apart geographically are also more genetically different.
- A separate regression plot visualizes genetic distance against geographic distance, but it is not the Mantel test itself.
- Export a PDF containing three outputs: a site map, a phylogeny annotated with species and collection sites, and an isolation-by-distance plot.
- The PDF is a working output, not the assignment submission; students should print the figures and annotate the evidence.
- Record a roughly three-minute response addressing four questions about dispersal, using the maps, phylogeny, and distance relationship as evidence.
- Use the scheduled Friday work period to run the R analysis, resolve problems, and connect the results to the hydrothermal-vent scenario.
Transcript excerpt
0:00 Good morning, good afternoon, good evening, good day and welcome. Here we are in R. Uh, and this is the start of your invertebrate R, your first assignment about dispersal and how that's how we can measure it. uh and how you have tools to measure it and how it would affect the way we think about the isolation, the fragmentation, and the vulnerability of these extremely special deep sea hydrothermal vents that you learned about in our previous time together. So, there's going to be a bit of a um I'm hoping I mean it's intended that there's a bit of a learning curve, but I hope that you're approaching R in a couple of different ways. One of them is if it's been scary in the past, if you've been jump dumped into the deep
0:47 end of the R pool in the past and there be dragons, this is going to be a facilitated and both facilitated and I think high-end um accumulation of skills for you. This is really a um an opportunity to expand on the transferable skills that you take out of your invertebrate zoology course. Uh I have some suggestions. I'm going to run through an example with you here in a second. And if you haven't if you if you're also interested in some other R resources, uh you can scan that QR code or follow the PDF uh to the library links where they talk about some other tools that are available for you here. But what kind of um resources have we arrayed for you here? The first of them
1:35 is that we're going to be let's talk about R I guess in general because R is why are we using R? Why um well it's a really powerful statistical and
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
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.