In spatial genetic correlative analyses, as soon as pairwise aggregates are associated with more than one distance measure, that is when computing inter-individual genetic distances with more than one sampled genotype per aggregate (*n* > 1) rather than interpopulation genetic distances based of allelic frequencies, Mantel tests are to be performed with restricted permutations, as pseudo-replication issues may arise when clumped genotypes are considered independent ([3] *Prunier et al. 2013*): in this case, permuted objects are the *p* blocks of *n* individuals, rather than the *n* individuals.

The following Matlab script can be used to perform simple and partial Mantel tests with standard or restricted permutations, depending on input data :

*This is the version 2.0 of the script. You now have to specify whether you intend to perform a Mantel test with classical ('c') or with restricted ('r') permutations. It prevents issues due to the spatial alignment of sampling points when using classical permutations. You can also choose to perform one-tailed or two-tailed Mantel tests.*

*Please, contact me by email for any trouble, remarks or suggestions !*

This is the R-version of *Tool #1*, now allowing MRDM (Multiple Regression on Distance Matrices) rather than (partial) Mantel test only :

*Please, contact me by email for any trouble, remarks or suggestions !*

Non-directional Mantel autocorrelograms may provide an insightful description of spatial patterns of genetic similarity among aggregates, especially when many aggregates are sampled across the study area ([3] *Prunier et al. 2013*). With only a few sampled individuals per aggregate (but many prospected aggregates), Mantel correlograms are to be performed with restricted permutations.

The following Matlab script can be used to perform spatial autocorrelation analyses through non-directional Mantel correlograms with standard or restricted permutations (depending on input data) :

*This is the version 2.0 of the script. You now have to specify whether you intend to perform a Mantel test with classical ('c') or with restricted ('r') permutations. It prevents issues due to the spatial alignment of sampling points when using classical permutations. *

*Please, contact me by email for any trouble, remarks or suggestions ! Many thanks to Dr J. Galarza for feedback on this script !*

The following figure shows an example of plots you may get when using this script (here, spatial autocorrelation analysis in 40 aggregates of 5 individuals each). Genetic data were simulated in CDPOP (Landguth & Cushman 2010)

Non-directional Mantel autocorrelograms with restricted permutations and boostrap resampling. Error bars bound the 95% confidence interval about r (y-axis) as determined by bootstrap resampling. Upper and lower confidence limits (dotted line) bound the 95% confidence interval about r under the null hypothesis of no spatial structure. Black circles indicate a significant Mantel correlation value at alpha=5%.

CDpop (Landguth & Cushman 2010) is a well-known spatially explicit, individual-based population genetics tool that simulates birth, death, mating and dispersal of individuals in complex landscape as probabilistic functions of movement costs among sampling locations.

Depending on input parameters, a thorough understanding of simulated processes and resulting gene flow is of crude importance for an accurate use of CDpop.

The following R and Matlab scripts are based on provided individual ID in CDpop format output grids. It computes the mean number of interpopulation individual exchanges per generation and provides a summary matrix in .txt format.

The matrix allows a quick and informative overview of effective connectivity among populations for each CDpop run. Diagonal elements stand for internal recruitment, e.g. the mean number of non-immigrant individuals per generation.

Matlab script : CDpopinterpopExchange.m. *This is the version 3.0 of the script, compatible with CDPOP v.1.2.18, and easily implemented in a loop.*

R script : CDpopinterpopExchange.R

*Please, contact me by email for any trouble, remarks or suggestions !*

An output matrix providing the mean number of individual exchanges among 15 populations (N=30) per generation. Diagonal elements (in orange) correspond to the mean internal recruitment per population and per generation.

Commonality analysis (CA) is a detailed variance-partitioning procedure that can be used to deal with
nonindependence among spatial predictors. By decomposing model ﬁt indices into unique and common (or shared) variance components, CA allows identifying the location and magnitude of multicollinearity, revealing spurious correlations and thus thoroughly improving the interpretation of multivariate regressions (*Prunier et al. 2015*)

The following R and Rstudio scripts can be used to perform CA in both Multivariate Regression on Distance Matrices (MRDM) and Logistic Regressions on Distance Matrices (LRDM). These scripts allow visually investigating the normality of the dependent variable, choosing between MRDM and LRDM accordingly, performing adequate bootstrapping (taking into account the non-independence of pairwise data), and getting insightful numerical and graphical outputs. Note that both scripts are identical except for the preparation of graphs, the procedure being slightly different depending on the platform you use.

* CAonDM* stands for

You will find below some graphical outputs you can get with these scripts (Here, using dataset 1 from *Prunier et al. 2015*).

This new version (v0.4) of scripts provides additional graphical and numerical outputs (notably, structures coefficients and normality tests of residuals) ! Furthermore, input data can be either an R-list of pairwise matrices or a dataframe of linearized matrices !

*Please, contact me by email for any trouble, remarks or suggestions !*

a) Distribution of the dependent variable, histogram and normal Q–Q plot of studentized residuals resulting from MRDM on quantitative datas.

b) Plot of β weights with 95% confidence intervals computed on the basis of 1000 replicates with a random removal of 10% of all 64 considered populations.

c) Plot of commonalities with 95% confidence intervals computed on the basis of 1000 replicates with a random removal of 10% of all 64 considered populations.

The following R and Rstudio scripts can be used to perform classical CA in both Linear and Logistic regressions, that is, using point data in a R-dataframe (in which each column stands for a specific vector), rather than pairwise matrices in a R-list (see Tools #5). They provide exactly the same outputs as Tools #5.

* CAonV* stands for

This new version (v0.5) of scripts provides additional graphical and numerical outputs (notably, structures coefficients and normality tests of residuals) !

*Please, contact me by email for any trouble, remarks or suggestions !*

The following R functions allow the application of the permutation-based d-sep test, clustering-based path analysis, permutation-based path analysis and a parametric bootstrap procedure dedicated to the handling of pairwise matrices in path analysis, as described in *Fourtune et al. 2018* .

* PAonDM* stands for

*Please, contact me or Lisa Fourtune by email for any trouble, remarks or suggestions !*

Macdonald et al. (Ecol. Lett., 21, 2018, 207–216; doi: 10.1111/ele.12883) proposed an analytical framework for identifying evolutionary processes underlying trait-environment relationships (TER) observed in natural populations. It is based on the visual inspection of the graphical distribution of two summary statistics (β-weights *Benv* and *Bint*; see Figure 1 in Macdonald et al. 2018) that are also used to compute another summary statistic (*L*) described as an index of local adaptation. We proposed an expanded and refined framework based on simulations and bootstrap-based approaches.To make the interpretation of *L*, *Benv* and *Bint* more objective, we designed a bootstrap procedure to estimate 95% conﬁdence intervals (CIs), and hence to take into account the uncertainty associated with each statistic. This refined approach, described in *Prunier and Blanchet (2018)*, allows directly inferring processes underlying each TER independently, even when a single trait and single environmental variable are considered.

The R script *BenvBintBootstrap.R* can be used to implement the expanded Macdonald's framework. It may be used to compute *Benv* and *Bint* β weights, RSint structure coefficients, as well 95% CI about *Benv* and *Bint* as obtained from bootstrap.

The R script *BenvBintBootstrapPlot.R* can be used to plot outputs from the *BenvBintBoostrap.R* function as in *Prunier and Blanchet (2018)*.

The R script *InteractionPlot.R* can be used to get both a fan-representation and a surface-representation of any first-order interaction.

You will find below some graphical outputs you can get with these scripts, here using the Macdonald’s empirical dataset revisited.

*Please, contact me by email for any trouble, remarks or suggestions !*

Scatterplot showing the results of 99 linear nested mixed effect models run to assess the putative driver of each TER in Macdonald et al. Symbols indicate whether a TER was found to be null (circles), driven by plasticity (squares) or driven by local adaptation (triangles) while taking uncertainty in the model estimates into account. Situations where

Scatterplot showing the distortion in

Panels a and b represent the

The following Rstudio script can be used to compute the *Cindex*, a standardized index of genetic connectivity allowing an absolute and independent assessment of the individual impacts of obstacles on functional connectivity. Briefly, the *Cindex* is computed as the standardized ratio (expressed as a percentage) between the observed genetic differentiation between pairs of populations located on either side of an aquatic or a terrestrial obstacle and the genetic differentiation expected if this obstacle completely prevented gene flow. The expected genetic differentiation is predicted from a RandomForest algorithm trained on numerous simulations taking into account both the age of the barrier and the effective size of the targeted populations. See the bioRxiv preprint *Prunier et al. (2019)* for a complete description.

The computation of the *Cindex* is automated in a user-friendly **CINDEX()** R-function (see R-walkthrough). The function is embedded within the CINDEX_data.rda file. This *.rda* file also contains all RandomForest predictions required to compute the *Cindex*. Users are invited to download this .rda file within their working directory, and to load/install required R-libraries (*adegenet*, *randomForest*, *mmod*, *lme4* and *reshape2*) before running the **CINDEX()** R-function.

Illustration files are provided in the form of a compressed zip-file containing a *parameter file* (*Prunier2018_illustration.txt*) as well as four genepop files from Prunier et al. 2018 (*Phoxinus_from_Cele.gen*, *Phoxinus_from_Viaur.gen*, *Gobio_from_Cele.gen* and *Gobio_from_Viaur.gen*) that can be used to test the **CINDEX()** R-function.

Illustration files from Prunier et al. 2018

You will find below the flowchart explaining how the *Cindex* is computed, as well as a graphical output you can get with the **CINDEX()** R-function using illustration files from Prunier et al. 2018.

*Please, contact me by email for any trouble, remarks or suggestions !*

Flowchart illustrating the major steps in calculating the index of genetic connectivity for two independent obstacles. After the sampling of populations located at the immediate upstream and downstream vicinity of each obstacle, users only have to provide a file of genotypes in the genepop format and a file of parameters indicating, for each obstacle, the names of the sampled populations and the number

For each monitored species (Gobio: