Data and code from: Evolutionary rescue by adaptive specialization in rapidly changing environments
Data files
May 08, 2026 version files 4.48 GB
-
calculate_ecological_fitness_benefits.R
3.46 KB
-
calculate_rescue_results.R
3 KB
-
fig_02.R
4.78 KB
-
fig_03.R
3.58 KB
-
fig_04.R
2.12 KB
-
fig_05.R
4.62 KB
-
fig_06.R
4.41 KB
-
fig_07.R
2.42 KB
-
fig_S01.R
2.26 KB
-
fig_S02.R
2.08 KB
-
fig_S03.R
3.19 KB
-
fig_S04.R
2.88 KB
-
fig_S05.R
3.96 KB
-
fig_S06.R
979 B
-
identify_replay_targets.R
1.89 KB
-
main_code_asymmetric_environments.r
10.34 KB
-
main_code_evolvability_measure.R
10.25 KB
-
main_code_full_linkage.R
10.20 KB
-
main_code_limited_linkage.R
10.61 KB
-
main_code_no_linkage.R
10.48 KB
-
main_code_tall_poppies.R
10.62 KB
-
outputs.zip
4.48 GB
-
README.md
6.91 KB
-
replay_code_main.R
8.85 KB
-
replay_code_tall_poppies.r
8.85 KB
Abstract
Theory suggests that a population with a narrower niche can adapt more rapidly to environmental change, all else being equal. However, a narrow niche may be correlated with other factors that compromise evolvability, such as a smaller population size, and it is unclear if specialist mutants can succeed by virtue of greater evolvability when impeded by the ecological costs of a narrower niche. Here we use simulation models to show that specialist mutants can invade during periods of rapid environmental change, in some cases preventing extinction. Focusing on asexual populations, we show that successful specialist mutants typically enjoy two types of advantages over generalists: an immediate benefit of ignoring a habitat in which they are particularly unfit, and a longer-term benefit of greater evolvability. By understanding the mechanisms that yield these benefits, we are also able to show that evolutionary rescue by specialization can be largely prevented by manipulating the schedule of environment change. Our results demonstrate how a population may change fundamentally under strong pressure to adapt rapidly, with implications for both beneficial (e.g., conservation) and harmful (e.g., antibiotic resistance) examples of evolutionary rescue.
Dataset DOI: 10.5061/dryad.cjsxksnm4
Description of the data and file structure
Overview
Code is organized by scripts associated with analyzing data for figures and code used to run simulations. The former are generally identified by a corresponding figure number and the latter by the word “main,” of which there are several versions for particular tasks.
Raw simulation outputs are in the archive “outputs”. Generally, to summarize these for figures pertaining to evolution rescue (e.g., Figure 2), the file “calculate_rescue_results.R” is used.
The bulk of the paper was generated from “main_code_full_linkage.R”, and all the other “main” files are forked from this version as used for special tasks. For example, “main_code_asymmetric_environments.R” was used for the results in Supplementary Figure 4. The code labeled “tall_poppies” was used for Figure 7 and related results. The code “identify_replay_targets.R” was used to create files to guide “replay” experiments, which have their own corresponding main code files.
Some results in the paper do not have an associated figure, in particular, calculations of the ecological benefits of niche contraction. These are calculated using the code in “calculate_ecological_fitness_benefits.R.”
Required packages
The R packages doParallel, flock, and fastmatch are used. The former two are only used for parallel processing,g and it is easy to change the code to run sequentially if desired.
Typical usage
To help understand the code, we can examine the process to create Figure 2. Several batches of results were run using main_code_full_linkage.R. In particular, note that one type of result--specialists only--is available only by commenting in a block of code within that file. Each batch of results is identified with a unique experiment name. The file "calculate_rescue_results.R" is then run on each batch, generating summary files that are then combined in the plotting code for "fig_02.R."
Guide to data files
Experiments were run in batches identified by a capital letter or a short phrase. Each replicate of a batch then writes a “fits” and a “types” file to the folder “outputs.” The “fits” files record the mean fitness in each niche every twenty generations, while the “types” file records the niche phenotypes of the most common types.
The major experiments used are:
- A and K: Main results with default parameters (e.g., demes = 4, c = 0.01) used in Fig. 2 and elsewhere. Other experiments use these default parameter values unless noted below.
- B: Generated by “main_code_tall_poppies” for figure 7.
- C: Specialists only, no niche evolution.
The following experiments vary the number of demes (and, where necessary, the population size to allow the sites to be evenly divided) and are used to make Fig. S2.
- E: demes = 5
- S: N = 20001, demes = 3
The following experiments vary the cost parameter, and their outputs are used to generate Fig. S3.
- G: c = 0.03
- H: c = 0.05
- I: c = 0.07
- J: c = 0.1
- P: c = 0.13
- Q c = 0.16
M: Experiment with asymmetries in the number of patches of each environment (Fig. S4).
R, W, Z: Extra batches of replicates of pref=TRUE treatment for a few values of prob. of env. change; same parameters as A and K. Used to provide a more detailed description of rare outcomes in Figs. 5 and 6.
limited_sex: Recombination between blocks of loci.
full_sex: Free recombination between all loci (no linkage).
general_evolvability, special_evolvability: Experiments for tracking the rate of evolution; used in Fig. S1
The archive "outputs" contains other file types used in various simulations and analyses. These include:
"eco_extended_A.txt" and "eco_extended_B.txt", which are generated by "calculate_ecological_fitness_benefits.R"
Files with prefixes "env", "trials", "pop", and "vacant", which are used to store data for replay experiments; e.g., "replay_code_tall_poppies.R".
Files with "niche_results" are used in fig_05.R.
Files and variables
- File: fig_S06.R
Description: Generates figure S06 from files in outputs.
- File: fig_02.R
Description: Generates Figure 2 from files in outputs.
- File: main_code_tall_poppies.R
Description: Performs simulations in which the best-adapted environment is chosen to change.
- File: replay_code_main.R
Description: Performs replay simulations based on files generated by "identify_replay_targets.R."
- File: replay_code_tall_poppies.r
Description: Performs replay simulations based on files generated by "identify_replay_targets.R."
- File: identify_replay_targets.R
Description: Creates files for replay experiments based on data files in outputs.
- File: main_code_asymmetric_environments.r
Description: Performs main simulations with variance in the number of sites per environment.
- File: calculate_ecological_fitness_benefits.R
Description: Uses files in outputs and generated by "identify_replay_targets.R" to determine ecological benefits of target genotypes.
- File: calculate_rescue_results.R
Description: Used to create summary results from files in outputs.
- File: fig_S05.R
Description: Generates figure S05 from files in outputs
- File: main_code_full_linkage.R
Description: Main simulation code with purely asexual reproduction; saves data to outputs.
- File: fig_05.R
Description: Generates figure % from files in outputs.
- File: main_code_evolvability_measure.R
Description: Version of the main simulation code specialized to measure evolutionary change over short intervals.
- File: main_code_limited_linkage.R
Description: Version of the main simulation code with recombination between blocks.
- File: main_code_no_linkage.R
Description: Version of the main simulation code with free recombination among loci.
- File: fig_S01.R
Description: Generates figure S01 from files in outputs.
- File: fig_S04.R
Description: Generates figure S04 from files in outputs.
- File: fig_07.R
Description: Generates Figure 7 from files in outputs.
- File: fig_S02.R
Description: Generates figure S02 from files in outputs.
- File: fig_S03.R
Description: Generates figure S03 from files in outputs.
- File: fig_06.R
Description: Generates figure 6 from files in outputs.
- File: fig_03.R
Description: Generates Figure 3 from files in outputs.
File: fig_04.R
- Description: Generates figure $ from files in outputs.
File: outputs.zip
Description: Compressed archive of all raw simulation outputs.
Code/software
R 4.5.0 was used for all results. Additional libraries used are doParallel, flock, and fastmatch.
