| Type: | Package |
| Title: | Build Graphs for Landscape Genetics Analysis |
| Version: | 1.8.0 |
| Maintainer: | Paul Savary <psavary@protonmail.com> |
| Description: | Build graphs for landscape genetics analysis. This set of functions can be used to import and convert spatial and genetic data initially in different formats, import landscape graphs created with 'GRAPHAB' software (Foltete et al., 2012) <doi:10.1016/j.envsoft.2012.07.002>, make diagnosis plots of isolation by distance relationships in order to choose how to build genetic graphs, create graphs with a large range of pruning methods, weight their links with several genetic distances, plot and analyse graphs,compare them with other graphs. It uses functions from other packages such as 'adegenet' (Jombart, 2008) <doi:10.1093/bioinformatics/btn129> and 'igraph' (Csardiet Nepusz, 2006)https://igraph.org/. It also implements methods commonly used in landscape genetics to create graphs, described by Dyer et Nason (2004) <doi:10.1111/j.1365-294X.2004.02177.x> and Greenbaum et Fefferman (2017) <doi:10.1111/mec.14059>, and to analyse distance data (van Strien et al., 2015) <doi:10.1038/hdy.2014.62>. |
| Depends: | R(≥ 3.1.0) |
| License: | GPL-2 |
| Encoding: | UTF-8 |
| LazyData: | true |
| Imports: | adegenet, ggplot2, stringr, igraph, stats, spatstat.geom,spatstat.linnet, Matrix, vegan, utils, methods, pegas, MASS,tidyr, sp, sf, hierfstat, rappdirs, gdistance, raster, foreign,ecodist, Rdpack |
| Suggests: | knitr, rmarkdown |
| RdMacros: | Rdpack |
| RoxygenNote: | 7.2.1 |
| VignetteBuilder: | knitr, rmarkdown |
| NeedsCompilation: | no |
| Packaged: | 2023-01-30 00:23:37 UTC; paul |
| Author: | Paul Savary |
| Repository: | CRAN |
| Date/Publication: | 2023-01-30 14:00:05 UTC |
Add attributes to the nodes of a graph
Description
The function adds attributes to the nodes of a graph fromeither an object of classdata.frame or from a shapefile layer.The node IDs in the input objects must be the same as in the graph object.
Usage
add_nodes_attr( graph, input = "df", data, dir_path = NULL, layer = NULL, index = "Id", include = "all")Arguments
graph | A graph object of class |
input | A character string indicating the nature of theinput data from which come the attributes to add to the nodes.
In both cases, input attribute table or dataframe must have a column withthe exact same values as the node IDs. |
data | (only if 'input = "df"') The name of the object ofclass |
dir_path | (only if 'input = "shp"') The path (character string) to thedirectory containing the shapefile layer of type point whose attributetable contains the attributes to add to the nodes. |
layer | (only if 'input = "shp"') The name (character string) of theshapefile layer of type point (without extension, ex.: "nodes" refersto "nodes.shp" layer) whose attribute table contains the attributesto add to the nodes. |
index | The name (character string) of the column with the nodes namesin the input data (column of the attribute table or of the dataframe). |
include | A character string (vector) indicating which columns of theinput data will be added as nodes' attributes.By default, 'include = "all"', i.e. every column of the input data is added.Alternatively, 'include' can be a vector with the names of the columns to add(ex.: "c('x', 'y', 'pop_name')"). |
Details
The graph can be created with the functiongraphab_to_igraph by importing output from Graphab projects.Values of the metrics computed at the node level with Graphab can then beadded to such a graph with this function.
Value
A graph object of classigraph
Author(s)
P. Savary
Examples
data("data_tuto")graph <- data_tuto[[3]]df_nodes <- data.frame(Id = igraph::V(graph)$name, Area = runif(50, min = 10, max = 60))graph <- add_nodes_attr(graph, data = df_nodes, input = "df", index = "Id", include = "Area")Check whether the option 'nomerge' was used when building the landscapegraph with Graphab
Description
The function checks whether the option 'nomerge' was used whenbuilding the landscape graph with Graphab
Usage
check_merge(proj_end_path)Arguments
proj_end_path | The path to the project .xml file. |
Value
The function returns a logical indicating whether 'nomerge' was used.If nomerge=TRUE, then it returns FALSE. If nomerge=FALSE, it returns TRUE.
Author(s)
P. Savary
Examples
## Not run: proj_name <- "grphb_ex"check_merge(proj_name = proj_name)## End(Not run)Compare two correlation coefficients obtained from different sample sizes
Description
The function compares two correlation coefficients obtained fromdifferent sample sizes using Z-Fisher transformation.
Usage
compar_r_fisher(data)Arguments
data | An object of class
|
Details
The Z-Fisher method consists in computing z scores from thecorrelation coefficients and to compare these z scores.z scores are computed as follows :Let n1 and r1 be the sample size and the correlation coefficient,z1 = (1/2)*log( (1+r1) / (1-r1) )Then, a test's statistic is computed from z1 and z2 :Z = (z1-z2) / sqrt( (1/(n1-3)) + (1/(n2-3)))If Z is above the limit given by the alpha value, then the difference betweenr1 and r2 is significant
Value
An object of classdata.frame with the same columns as 'data'and 4 columns more : z1, z2 (respective z-scores), Z (test's statistic) andp (p-value) of the test.
Author(s)
P. Savary
Examples
df <- data.frame(n1 = rpois(n = 40, lambda = 85), n2 = rpois(n = 40, lambda = 60), r1 = runif(n = 40, min = 0.6, max = 0.85), r2 = runif(n = 40, min = 0.55, max = 0.75))data <- compar_r_fisher(df)Compute modules from a graph by maximising modularity
Description
The function computes modules from a graph by maximisingmodularity.
Usage
compute_graph_modul( graph, algo = "fast_greedy", node_inter = NULL, nb_modul = NULL)Arguments
graph | An object of class |
algo | A character string indicating the algorithm used to createthe modules withigraph.
|
node_inter | (optional, default = NULL) A character string indicatingwhether the links of the graph are weighted by distances or by similarityindices. It is only used to compute the modularity index. It can be:
|
nb_modul | (optional , default = NULL) A numeric or integer valueindicating the number of modules in the graph. When this number is notspecified, the optimal value is retained. |
Value
Adata.frame with the node names and the correspondingmodule ID.
Author(s)
P. Savary
Examples
data("data_tuto")mat_gen <- data_tuto[[1]]graph <- gen_graph_thr(mat_w = mat_gen, mat_thr = mat_gen, thr = 0.8)res_mod <- compute_graph_modul(graph = graph, algo = "fast_greedy", node_inter = "distance")Compute graph-theoretic metrics from a graph at the node level
Description
The function computes graph-theoretic metric values at thenode level.
Usage
compute_node_metric( graph, metrics = c("deg", "close", "btw", "str", "siw", "miw"), weight = TRUE)Arguments
graph | An object of class |
metrics | Character vector specifying the graph-theoreticmetrics computed at the node-level in the graphsGraph-theoretic metrics can be:
By default, the vector |
weight | Logical which indicates whether the links are weighted duringthe calculation of the centrality indices betweenness and closeness.(default: |
Value
Adata.frame with the node names and the metrics computed.
Author(s)
P. Savary
Examples
data(data_ex_genind)mat_gen <- mat_gen_dist(x = data_ex_genind, dist = "DPS")graph <- gen_graph_thr(mat_w = mat_gen, mat_thr = mat_gen, thr = 0.8)res_met <- compute_node_metric(graph)Fit a model to convert cost-distances into Euclidean distances
Description
The function fits a model to convert cost-distances intoEuclidean distances as implemented in Graphab software.
Usage
convert_cd( mat_euc, mat_ld, to_convert, method = "log-log", fig = TRUE, line_col = "black", pts_col = "#999999")Arguments
mat_euc | A symmetric |
mat_ld | A symmetric |
to_convert | A numeric value or numeric vector with Euclidean distancesto convert into cost-distances. |
method | A character string indicating the method used to fit the model.
|
fig | Logical (default = TRUE) indicating whether a figure is plotted |
line_col | (if 'fig = TRUE') Character string indicating the colorused to plot the line (default: "blue"). It must be a hexadecimal colorcode or a color used by default in R. |
pts_col | (if 'fig = TRUE') Character string indicating the colorused to plot the points (default: "#999999"). It must be a hexadecimal colorcode or a color used by default in R. |
Details
IDs in 'mat_euc' and 'mat_ld' must be the same and refer to the samesampling site or populations, and both matrices must be orderedin the same way.Matrix of Euclidean distance 'mat_euc' can be computed using the functionmat_geo_dist.Matrix of landscape distance 'mat_ld' can be computed using the functionmat_cost_dist.Before the log calculation, 0 distance values are converted into 1,so that they are 0 after this calculation.
Value
A list of output (converted values, estimated parameters, R2)and optionally a ggplot2 object to plot
Author(s)
P. Savary
References
Foltête J, Clauzel C, Vuidel G (2012).“A software tool dedicated to the modelling of landscape networks.”Environmental Modelling & Software,38, 316–327.
Examples
data("data_tuto")mat_ld <- data_tuto[[2]][1:10, 1:10] * 1000mat_euc <- data_tuto[[1]][1:10, 1:10] * 50000to_convert <- c(30000, 40000)res <- convert_cd(mat_euc = mat_euc, mat_ld = mat_ld, to_convert = to_convert, fig = FALSE)data_ex_genind genetic dataset
Description
Genetic dataset from genetic simulation on CDPOP200 individuals, 10 populations20 microsatellite loci (3 digits coding)100 generations simulated
Usage
data_ex_genindFormat
An object of type 'genind'
Details
The simulation was made with CDPOP during 100 generations.Dispersal was possible between the 10 populations. Its probability dependedon the cost distance between populations, calculated on a simulatedresistance surface (raster). Mutations were not possible. Therewere initially 600 alleles in total (many disappeared because of drift).Population stayed constantwith a sex-ratio of 1. Generations did not overlap.This simulation includes a part of stochasticity and these data resultfrom only 1 simulation run.
References
Landguth EL, Cushman SA (2010).“CDPOP: a spatially explicit cost distance population genetics program.”Molecular Ecology Resources,10(1), 156–161.
Examples
data("data_ex_genind")length(unique(data_ex_genind@pop))data_ex_gstud genetic dataset
Description
Genetic dataset from genetic simulation on CDPOP200 individuals, 10 populations20 microsatellite loci (3 digits coding)100 generations simulated
Usage
data_ex_gstudFormat
A 'data.frame' with columns:
- ID
Individual ID
- POP
Population name
- LOCI-1 to LOCI-20
20 loci columns with microsatellite data with3 digits coding, alleles separated by ":", and blank missing data(class 'locus' fromgstudio)
Examples
data("data_ex_gstud")str(data_ex_gstud)length(unique(data_ex_gstud$POP))data_ex_loci genetic dataset
Description
Genetic dataset from genetic simulation on CDPOP200 individuals, 10 populations20 microsatellite loci (3 digits coding)100 generations simulated
Usage
data_ex_lociFormat
An object of class 'loci' and 'data.frame' with the columns :
- population
Population name
- Other columns
20 loci columns with microsatellite data with3 digits coding, alleles separated by "/", and missing data noted "NA/NA"
Row names correspond to individuals' ID
Examples
data("data_ex_loci")length(unique(data_ex_loci$population))data_simul_genind genetic dataset
Description
Genetic dataset from genetic simulation on CDPOP1500 individuals, 50 populations20 microsatellite loci (3 digits coding)50 generations simulated
Usage
data_simul_genindFormat
An object of type 'genind'
Details
The simulation was made with CDPOP during 50 generations.Dispersal was possible between the 50 populations. Its probability dependedon the cost distance between populations, calculated on a simulatedresistance surface (raster). Mutations were not possible. Therewere initially 600 alleles in total (many disappeared because of drift).Population stayed constantwith a sex-ratio of 1. Generations did not overlap.This simulation includes a part of stochasticity and these data resultfrom only 1 simulation run.
References
Landguth EL, Cushman SA (2010).“CDPOP: a spatially explicit cost distance population genetics program.”Molecular Ecology Resources,10(1), 156–161.
Examples
data("data_simul_genind")length(unique(data_simul_genind@pop))data_tuto : data used to generate the vignette
Description
Data used to generate the vignette
Data used to generate the vignette
Usage
data_tutodata_tutoFormat
Several outputs or inputs to show how the package works in a list
- mat_dps
Genetic distance matrix example
- mat_pg
Second genetic distance matrix example
- graph_ci
Genetic independence graph example
- dmc
Output of the function 'dist_max_corr'
- land_graph
Landscape graph example
- mat_ld
Landscape distance matrix example
Several outputs or inputs to show how the package works in a list
- dmc
Output of the function 'dist_max_corr'
- graph_ci
Genetic independence graph example
- mat_dps
Genetic distance matrix example
- mat_pg
Second genetic distance matrix example
Examples
data("data_tuto")mat_dps <- data_tuto[[1]]str(mat_dps)data("data_tuto")mat_dps <- data_tuto[[1]]str(mat_dps)Convert degrees to radians
Description
The function converts degree to radians
Usage
deg2rad(deg)Arguments
deg | A coordinate in degrees |
Value
The coordinate in radians
Author(s)
P. Savary
Examples
deg2rad(40.75170)Convert an edge-list data.frame into a pairwise matrix
Description
The function converts an edge-list data.frameinto a symmetric pairwise matrix
Usage
df_to_pw_mat(data, from, to, value)Arguments
data | An object of class |
from | A character string indicating the name of the column with the IDof the origins |
to | A character string indicating the name of the column with the IDof the arrivals |
value | A character string indicating the name of the column with thevalues corresponding to each pair |
Details
The matrix is a symmetric matrix. Be careful, you shall not providea data.frame with different values corresponding to the pair 1-2 and 2-1 asan example. Ideally, for a complete matrix, data should have n(n-1)/2 rowsif values are computed between n objects.
Value
A pairwise matrix
Author(s)
P. Savary
Examples
data(pts_pop_simul)suppressWarnings(mat_geo <- mat_geo_dist(pts_pop_simul, ID = "ID", x = "x", y = "y"))g <- gen_graph_topo(mat_w = mat_geo, mat_topo = mat_geo, topo = "comp")df <- data.frame(igraph::as_edgelist(g))df$w <- igraph::E(g)$weightdf_to_pw_mat(df, from = "X1", to = "X2", value = "w")Calculate the Great-Circle distance between two points using theHarversine formula (hvs)
Description
The function calculates the Great-Circle distance between twopoints specified by radian latitude/longitude using theHarversine formula (hvs)
Usage
dist_gc_hvs(long1, lat1, long2, lat2)Arguments
long1 | Point 1 longitude in radians |
lat1 | Point 1 latitude in radians |
long2 | Point 2 longitude in radians |
lat2 | Point 2 latitude in radians |
Value
The distance between points 1 and 2 in meters
Author(s)
P. Savary
Examples
dist_gc_hvs(long1 = -73.99420, lat1 = 40.75170, long2 = -87.63940, lat2 = 41.87440)Calculate the Great-Circle distance between two points using theSpherical Law of Cosines (slc)
Description
The function calculates the Great-Circle distance between twopoints specified by radian latitude/longitude using the Spherical Lawof Cosines (slc)
Usage
dist_gc_slc(long1, lat1, long2, lat2)Arguments
long1 | Point 1 longitude in radians |
lat1 | Point 1 latitude in radians |
long2 | Point 2 longitude in radians |
lat2 | Point 2 latitude in radians |
Value
The distance between points 1 and 2 in meters
Author(s)
P. Savary
Examples
dist_gc_slc(long1 = -73.99420, lat1 = 40.75170, long2 = -87.63940, lat2 = 41.87440)Calculate the Great-Circle distance between two points using theVincenty inverse formula for ellipsoids (vicenty)
Description
The function calculates the Great-Circle distance between twopoints specified by radian latitude/longitude using theVincenty inverse formula for ellipsoids (vicenty)
Usage
dist_gc_vicenty(long1, lat1, long2, lat2)Arguments
long1 | Point 1 longitude in radians |
lat1 | Point 1 latitude in radians |
long2 | Point 2 longitude in radians |
lat2 | Point 2 latitude in radians |
Value
The distance between points 1 and 2 in meters
Author(s)
P. Savary
Examples
dist_gc_vicenty(long1 = -73.99420, lat1 = 40.75170, long2 = -87.63940, lat2 = 41.87440)Compute the Great Circle distance between two points
Description
The function computes the Great Circle distance between twotwo points defined by their longitudes and latitudes.
Usage
dist_great_circle(long1, long2, lat1, lat2, method = "vicenty")Arguments
long1 | project name, project dir in which proj_name.xml is found |
long2 | raster.tif INT2S path or present in wd, |
lat1 | habitat code in the raster file |
lat2 | default 0, minimum habitat size in ha |
method | default NULL nodata code in the raster file |
Author(s)
P. Savary
Examples
dist_great_circle(long1 = -73.99420, lat1 = 40.75170, long2 = -87.63940, lat2 = 41.87440, method = "vicenty")Compute the distance at which the correlation between genetic distanceand landscape distance is maximal
Description
The function enables to compute the distance at which thecorrelation between genetic distance and landscape distance is maximal,using a method similar to that employed by van Strien et al. (2015).Iteratively, distance threshold values are tested. For each value, all thepopulation pairs separated by a landscape distance larger than the thresholdare removed before the Mantel correlation coefficient between geneticdistance and landscape distance is computed.The distance threshold at which the correlation is the strongest is thenidentified. A figure showing the evolution of the correlation coefficientswhen landscape distance threshold increases is plotted.
Usage
dist_max_corr( mat_gd, mat_ld, interv, from = NULL, to = NULL, fig = TRUE, thr_gd = NULL, line_col = "black", pts_col = "#999999")Arguments
mat_gd | A symmetric |
mat_ld | A symmetric |
interv | A numeric or integer value indicating the interval betweenthe different distance thresholds for which the correlation coefficientsare computed. |
from | (optional) The minimum distance threshold value at which thecorrelation coefficient is computed. |
to | (optional) The maximum distance threshold value at which thecorrelation coefficient is computed. |
fig | Logical (default = TRUE) indicating whether a figure is plotted. |
thr_gd | (optional) A numeric or integer value used to removegenetic distance values from the data before the calculation.All genetic distances values above 'thr_gd' are removed from the data.This parameter can be used especially when there are outliers. |
line_col | (optional, if fig = TRUE) A character string indicating thecolor used to plot the line (default: "blue"). It must be a hexadecimal colorcode or a color used by default in R. |
pts_col | (optional, if fig = TRUE) A character string indicating thecolor used to plot the points (default: "#999999"). It must be a hexadecimalcolor code or a color used by default in R. |
Details
IDs in 'mat_gd' and 'mat_ld' must be the same and refer to the samesampling sites or populations, and both matrices must be orderedin the same way.The correlation coefficient between genetic distance and landscape distancecomputed is a Mantel correlation coefficient. If there are less than 50pairwise values, the correlation is not computed, as invan Strien et al. (2015). Such a method can be subject to criticism froma strict statistical point of view given correlation coefficients computedfrom samples of different size are compared.The matrix of genetic distance 'mat_gd' can be computed usingmat_gen_dist.The matrix of landscape distance 'mat_ld' can be computed usingmat_geo_dist when the landscape distance needed is aEuclidean geographical distance.Mantel correlation coefficients are computed usingthe functionmantel.
Value
A list of objects:
The distance at which the correlation is the highest.
The vector of correlation coefficients at the differentdistance thresholds
The vector of the different distance thresholds
A ggplot2 object to plot
Author(s)
P. Savary
References
Van Strien MJ, Holderegger R, Van Heck HJ (2015).“Isolation-by-distance in landscapes: considerations for landscape genetics.”Heredity,114(1), 27.
Examples
data("data_tuto")mat_gen <- data_tuto[[1]]mat_dist <- data_tuto[[2]]*1000res_dmc <- dist_max_corr(mat_gd = mat_gen, mat_ld = mat_dist, from = 32000, to = 42000, interv = 5000, fig = FALSE)Prune a graph using the 'percolation threshold' method
Description
The function allows to prune a graph by removingthe links with the largest weights until the graph breaks intotwo components. The returned graph is the last graph with only onecomponent.
Usage
g_percol(x, val_step = 20)Arguments
x | A symmetric |
val_step | The number of classes to create to search for thethreshold value without testing all the possibilities. By default,'val_step = 20'. |
Value
A graph object of typeigraph
Author(s)
P. Savary
Examples
data(data_ex_genind)suppressWarnings(mat_w <- graph4lg::mat_geo_dist(data = pts_pop_ex, ID = "ID", x = "x", y = "y"))g_percol(x = mat_w)Create an independence graph of genetic differentiationfrom genetic data of class genind
Description
The function allows to create genetic graphs from genetic databy applying the conditional independence principle. Populations whose allelicfrequencies covary significantly once the covariance with the otherpopulations has been taken into account are linked on the graphs.
Usage
gen_graph_indep( x, dist = "basic", cov = "sq", pcor = "magwene", alpha = 0.05, test = "EED", adj = "none", output = "igraph")Arguments
x | An object of class |
dist | A character string indicating the method used to compute themultilocus genetic distance between populations
|
cov | A character string indicating the formula used to compute thecovariance matrix from the distance matrix
|
pcor | A character string indicating the way the partial correlationmatrix is computed from the covariance matrix.
|
alpha | A numeric value corresponding to the statistical tolerancethreshold used to test the difference from 0 of the partial correlationcoefficients. By default, 'alpha=0.05'. |
test | A character string indicating the method used to test thesignificance of the partial correlation coefficients.
|
adj | A character string indicating the way of adjusting p-values toassess the significance of the p-values
|
output | A character string indicating the matrices included inthe output list.
|
Details
The function allows to vary many parameters such as the geneticdistance used, the formula used to compute the covariance, the statisticaltolerance threshold, the p-values adjustment, among others.
Value
Alist of objects of classmatrix, an object ofclassmatrix or a graph object of classigraph
Author(s)
P. Savary
References
Dyer RJ, Nason JD (2004).“Population graphs: the graph theoretic shape of genetic structure.”Molecular ecology,13(7), 1713–1727.Benjamini Y, Hochberg Y (1995).“Controlling the false discovery rate: a practical and powerful approach to multiple testing.”Journal of the royal statistical society. Series B (Methodological), 289–300.Bowcock AM, Ruiz-Linares A, Tomfohrde J, Minch E, Kidd JR, Cavalli-Sforza LL (1994).“High resolution of human evolutionary trees with polymorphic microsatellites.”nature,368(6470), 455–457.Everitt B, Hothorn T (2011).An introduction to applied multivariate analysis with R.Springer.Excoffier L, Smouse PE, Quattro JM (1992).“Analysis of molecular variance inferred from metric distances among DNA haplotypes: application to human mitochondrial DNA restriction data.”Genetics,131(2), 479–491.Fortuna MA, Albaladejo RG, Fernández L, Aparicio A, Bascompte J (2009).“Networks of spatial genetic variation across species.”Proceedings of the National Academy of Sciences,106(45), 19044–19049.Holm S (1979).“A simple sequentially rejective multiple test procedure.”Scandinavian journal of statistics, 65–70.Magwene PM (2001).“New tools for studying integration and modularity.”Evolution,55(9), 1734–1745.Wermuth N, Scheidt E (1977).“Algorithm AS 105: fitting a covariance selection model to a matrix.”Journal of the Royal Statistical Society. Series C (Applied Statistics),26(1), 88–92.Whittaker J (2009).Graphical models in applied multivariate statistics.Wiley Publishing.
Examples
data(data_ex_genind)dist_graph_test <- gen_graph_indep(x = data_ex_genind, dist = "basic", cov = "sq", pcor = "magwene", alpha = 0.05, test = "EED", adj = "none", output = "igraph")Create a graph of genetic differentiationusing a link weight threshold
Description
The function allows to construct a genetic graph whoselinks' weights are larger or lower than a specific threshold
Usage
gen_graph_thr(mat_w, mat_thr = NULL, thr, mode = "larger")Arguments
mat_w | A symmetric (pairwise) |
mat_thr | (optional) A symmetric (pairwise) distance |
thr | The threshold value (logically between min(mat_thr)and max(mat_thr))(integer or numeric) |
mode |
|
Details
If 'mat_thr' is not defined, 'mat_w' is used for the pruning.Matrices 'mat_w' and 'mat_thr' must have the same dimensions and thesame rows' and columns' names.Values in 'mat_thr' matrix must be positive. Negative values from'mat_w' are transformed into zeros.The function works only for undirected graphs.If dist objects are specified, it is assumed that colnames androw.names of mat_w and mat_thr refer to the same populations/locations.
Value
A graph object of classigraph
Author(s)
P. Savary
Examples
mat_w <- mat_gen_dist(x = data_ex_genind, dist = 'DPS')suppressWarnings(mat_thr <- mat_geo_dist(pts_pop_ex, ID = "ID", x = "x", y = "y"))mat_thr <- mat_thr[row.names(mat_w), colnames(mat_w)]graph <- gen_graph_thr(mat_w, mat_thr, thr = 6000, mode = "larger")Create a graph of genetic differentiation witha specific topology
Description
The function constructs a genetic graph witha specific topology from genetic and/or geographical distance matrices
Usage
gen_graph_topo(mat_w, mat_topo = NULL, topo = "gabriel", k = NULL)Arguments
mat_w | A symmetric (pairwise) |
mat_topo | (optional) A symmetric (pairwise) distance |
topo | Which topology does the created graph have?
|
k | (if 'topo = 'knn”) An integer which indicates the number ofnearest neighbors considered to create the K-nearest neighbor graph. k mustbe lower than the total number of nodes minus 1. |
Details
If 'mat_topo' is not defined, 'mat_w' is used for the pruning.Matrices 'mat_w' and 'mat_topo' must have the same dimensions and thesame rows' and columns' names.Values in 'mat_topo' matrix must be positive. Negative values from'mat_w' are transformed into zeros.The function works only for undirected graphs.Note that the topology 'knn' works best when 'mat_topo' contains distancevalues from a continuous value range, thereby avoiding equal distancesbetween a node and the others. are more than k nodes locatedat distances in the k-th smallest distancesIf dist objects are specified, it is assumed that colnames androw.names of mat_w and mat_topo refer to the same populations/locations.
Value
A graph object of classigraph
Author(s)
P. Savary
References
Gabriel KR, Sokal RR (1969).“A new statistical approach to geographic variation analysis.”Systematic zoology,18(3), 259–278.
Examples
mat_w <- mat_gen_dist(x = data_ex_genind, dist = 'DPS')suppressWarnings(mat_topo <- mat_geo_dist(pts_pop_ex, ID = "ID", x = "x", y = "y"))mat_topo <- mat_topo[row.names(mat_w), colnames(mat_w)]graph <- gen_graph_topo(mat_w, mat_topo, topo = "mst")Convert a GENEPOP file into a genind object
Description
The function converts a text file in the format used by GENEPOPsoftware into a genind object
Usage
genepop_to_genind(path, n.loci, pop_names = NULL, allele.digit.coding = 3)Arguments
path | A character string with the path leading to the GENEPOP filein format .txt, or alternatively the name of this file in the workingdirectory. |
n.loci | The number of loci in the GENEPOP file (integer or numeric). |
pop_names | (optional) Populations' names in the same orderas in the GENEPOP file.Vector object (class character) of the same length as the numberof populations.Without this parameter, populations are numbered from 1 to the numberof populations. |
allele.digit.coding | Number indicating whether alleles are codedwith 3 (default) or 2 digits. |
Details
This function uses functions frompegas package.GENEPOP file should can include microsatellites loci or SNPs with allele namesof length 2 or 3 (noted as 01, 02, 03 or 04 for SNPs).The loci line(s) must not start with a spacing.
Value
An object of typegenind.
Author(s)
P. Savary
References
Raymond M (1995).“GENEPOP: Population genetics software for exact tests and ecumenism. Vers. 1.2.”Journal of Heredity,86, 248–249.
See Also
For more details about GENEPOP file formatting :https://genepop.curtin.edu.au:443/help_input.htmlFor the opposite conversion, seegenind_to_genepop.The output file can be used to compute pairwise FST matrixwithmat_pw_fst
Examples
path_in <- system.file('extdata', 'gpop_simul_10_g100_04_20.txt', package = 'graph4lg')file_n <- file.path(tempdir(), "gpop_simul_10_g100_04_20.txt")file.copy(path_in, file_n, overwrite = TRUE)genepop_to_genind(path = file_n, n.loci = 20, pop_names = as.character(order(as.character(1:10))))file.remove(file_n)Convert a genind object into a GENEPOP file
Description
The function converts an object of classgenind intoa GENEPOP file.It then allows to use the functionalities of the GENEPOP software andits derived packageGENEPOP on R, as well as some functionsfrom other packages (differentiation test, F-stats calculations,HWE test,...).It is designed to be used with diploid microsatellite data withalleles coded with 2 or 3 digits or SNPs genind objects.
Usage
genind_to_genepop(x, output = "data.frame")Arguments
x | An object of class |
output | A character string indicating the option used to select whatthe function will return:
|
Value
An object of typedata.frame ifouput = "data.frame".Ifoutput is the path and/or the file name of a text file, thennothing is returned in R environment but a text file is created with thespecified file name, either in the current working directory or in thespecified folder.
Warning
Confusion
Do not confound this function withgenind2genpopfromadegenet. The latter converts an object of classgenindinto an object of classgenpop, whereasgenind_to_genepopconverts an object of classgenind into a text file compatible withGENEPOP software (Rousset, 2008).
Allele coding
This function can handle genetic data with different allele coding: 2 or 3digit coding for microsatellite data or 2 digit coding for SNPs (A,C,T,Gbecome respectively 01, 02, 03, 04).
Individuals order
When individuals in input data are not ordered by populations, individualsfrom the same population can be separated by individuals from otherpopulations. It can be problematic when calculating then pairwise distancematrices. Therefore, in such a case, individuals are ordered by populationsand populations ordered in alphabetic order.
Author(s)
P. Savary
References
Raymond M (1995).“GENEPOP: Population genetics software for exact tests and ecumenism. Vers. 1.2.”Journal of Heredity,86, 248–249.
See Also
For more details about GENEPOP file formatting :https://genepop.curtin.edu.au:443/help_input.html.For the opposite conversion, seegenepop_to_genind.The output file can be used to compute pairwise FST matrixwithmat_pw_fst
Examples
data(data_ex_genind)x <- data_ex_geninddf_genepop <- suppressWarnings(genind_to_genepop(x, output = "data.frame"))Convert a genind object into a STRUCTURE file
Description
The function converts an object of classgenind intoa STRUCTURE file.It is designed to be used with diploid microsatellite data withalleles coded with 2 or 3 digits or SNPs genind objects.
Usage
genind_to_structure(x, output = "")Arguments
x | An object of class |
output | A character string of the form |
Value
Ifoutput is the path and/or the file name of a text file, then nothing is returned in R environment but a text file is created with the specified file name, either in the current working directory or in thespecified folder.
Warning
Allele coding
This function can handle genetic data with different allele coding: 2 or 3digit coding for microsatellite data or 2 digit coding for SNPs (A,C,T,Gbecome respectively 01, 02, 03, 04).
Individuals order
When individuals in input data are not ordered by populations, individualsfrom the same population can be separated by individuals from otherpopulations. It can be problematic when calculating then pairwise distancematrices. Therefore, in such a case, individuals are ordered by populationsand populations ordered in alphabetic order.
Author(s)
P. Savary
Examples
data(data_ex_genind)x <- data_ex_genindgenind_to_structure(x, output = tempfile(fileext = ".txt"))Download Graphab if not present on the user's machine
Description
The function checks for the presence of Graphab (.jar) on theuser's machine and downloads it if absent. It also checks that users haveinstalled java on their machine.
Usage
get_graphab(res = TRUE, return = FALSE)Arguments
res | Logical indicating whether a message says if Graphab has beendownloaded or not. |
return | Logical indicating whether the function returns a 1 or a 0to indicate if Graphab has been downloaded or not. |
Details
If the download does not work, you can create a directory named'graph4lg_jar' in the directoryrappdirs::user_data_dir() and copyGraphab software downloaded fromhttps://thema.univ-fcomte.fr/productions/download.php?name=graphab&version=2.8&username=Graph4lg&institution=R
Value
If res = TRUE, the function displays a message indicating to userswhat has been done.If return = TRUE, it returns a 0 if Graphab is already on the machine anda 1 if it has been downloaded.
Author(s)
P. Savary
Examples
## Not run: get_graphab()## End(Not run)Get linkset computed in the Graphab project
Description
The function gets a linkset computed in the Graphab project
Usage
get_graphab_linkset(proj_name, linkset, proj_path = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml is. |
linkset | A character string indicating the name of the link setwhose properties are imported. The link set has been created with Graphabor using |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
Details
See more information in Graphab 2.8 manual:https://sourcesup.renater.fr/www/graphab/download/manual-2.8-en.pdf.This function works iflink{get_graphab} function works correctly.
Value
A data.frame with the link properties (from, to, cost-distance,Euclidean distance)
Author(s)
P. Savary
Examples
## Not run: get_graphab_linkset(proj_name = "grphb_ex", linkset = "lkst1")## End(Not run)Get cost values associated with a linkset in a Graphab project
Description
The function extracts the cost values associated with alinkset in a Graphab project
Usage
get_graphab_linkset_cost(proj_name, linkset, proj_path = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml will be created. |
linkset | (optional, default=NULL) A character string indicating thename of the link set used to create the graph. Link sets can be createdwith |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
Value
The function returns a data.frame with the cost values correspondingto every raster code value.
Author(s)
P. Savary
Examples
## Not run: proj_name <- "grphb_ex"get_graphab_linkset_cost(proj_name = proj_name, linkset = "lkst1")## End(Not run)Get metrics computed at the node in the Graphab project
Description
The function gets the metrics computed at the node-level inthe Graphab project
Usage
get_graphab_metric(proj_name, proj_path = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml is. |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
Details
The imported metrics describe the patches and have been computedfrom the different graphs created in the Graphab project.See more information in Graphab 2.8 manual:https://sourcesup.renater.fr/www/graphab/download/manual-2.8-en.pdf
Value
A data.frame with metrics computed at the patch level.
Author(s)
P. Savary
Examples
## Not run: get_graphab_metric(proj_name = "grphb_ex")## End(Not run)Get unique raster codes from a Graphab project
Description
The function extracts unique raster codes from a Graphab project
Usage
get_graphab_raster_codes(proj_name, mode = "all", proj_path = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml will be created. |
mode | A character string equal to either 'all' (default) or 'habitat'indicating whether the returned codes are all the codes of the source rasterused for creating the project or only the code corresponding to thehabitat patches. |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
Value
The function returns a vector of integer values corresponding tothe source raster codes (all the codes or only the one corresponding tohabitat patches).
Author(s)
P. Savary
Examples
## Not run: proj_name <- "grphb_ex"get_graphab_raster_codes(proj_name = proj_name, mode = "all")## End(Not run)Compute Gini coefficient from a numeric vector
Description
The function computes Gini coefficient from a numeric vector
Usage
gini_coeff(x, unbiased = TRUE)Arguments
x | A numeric vector with positive values |
unbiased | A logical value indicating whether the computed coefficientis biased or not. Unbiased value are equal to n/(n-1) times the biased ones. |
Value
A numeric value corresponding to the Gini coefficient of the numericvector
Author(s)
P. Savary
Examples
x <- c(10, 2, 5, 15)gini <- gini_coeff(x)Compare the partition into modules of two graphs
Description
The function computes the Adjusted Rand Index (ARI) tocompare two graphs' partitions into modules or clusters more generally.Both graphs must have the same number of nodes, but not necessarily the samenumber of links. They must also have the same node names and in thesame order.
Usage
graph_modul_compar( x, y, mode = "graph", nb_modul = NULL, algo = "fast_greedy", node_inter = "distance", data = NULL)Arguments
x | The first graph object
|
y | The second graph objectSame classes possible as for |
mode | A character string indicating whether x and y are igraph objects,vectors or columns from a data.frame. |
nb_modul | (if x and y are igraph objects) A numeric or integer valueor a numeric vector with 2 elements indicating the number of modules tocreate in both graphs.
|
algo | (if x and y are igraph objects) A character string indicating thealgorithm used to create the modules withigraph.
|
node_inter | (optional, if x and y are igraph objects,default is 'none') A character string indicating whether the links of thegraph are weighted by distances or by similarity indices. It is only usedto compute the modularity index. It can be:
Two different weightings can be used to create the modules of the two graphs.
|
data | (if x and y are columns from a data.frame) An object of classdata.frame with at least two columns and as many rows as there are nodesin the graphs compared. The columns indicate the modules of each node in2 different classifications. |
Details
This index takes values between -1 and 1. It measures how oftenpairs of nodes pertaining to the same module in one graph also pertain tothe same module in the other graph.Therefore, large values indicate that both partitions are similar.The Rand Index can be defined as the frequency of agreement between twoclassifications into discrete classes. It is the number of times a pair ofelements are classified into the same class or in two different classesin both compared classifications, divided by the total number of possiblepairs of elements. The Rand Index is between 0 and 1 but its maximum valuedepends on the number of elements. Thus, another 'adjusted' index wascreated, the Adjusted Rand Index. According to the Hubert etArabie's formula, the ARI is computed as follows:ARI=\frac{Index - Expected index}{Maximum index - Expected index}where the values of Index, Expected index and Maximum index are computedfrom a contingency table.This function usesadjustedRandIndex from packagemclust whichapplies the Hubert and Arabie's formula for the ARI.This function works for undirected graphs only.
Value
The value of the ARI
Author(s)
P. Savary
References
Dyer RJ, Nason JD (2004).“Population graphs: the graph theoretic shape of genetic structure.”Molecular ecology,13(7), 1713–1727.Hubert L, Arabie P (1985).“Comparing partitions.”Journal of classification,2(1), 193–218.Clauset A, Newman ME, Moore C (2004).“Finding community structure in very large networks.”Physical review E,70(6).Blondel VD, Guillaume J, Lambiotte R, Lefebvre E (2008).“Fast unfolding of communities in large networks.”Journal of Statistical Mechanics - Theory and Experiment,10.Brandes U, Delling D, Gaertler M, Gorke R, Hoefer M, Nikoloski Z, Wagner D (2008).“On modularity clustering.”IEEE transactions on knowledge and data engineering,20(2), 172–188.Pons P, Latapy M (2006).“Computing communities in large networks using random walks.”J. Graph Algorithms Appl.,10(2), 191–218.
Examples
data(data_ex_genind)data(pts_pop_ex)mat_dist <- suppressWarnings(graph4lg::mat_geo_dist(data=pts_pop_ex, ID = "ID", x = "x", y = "y"))mat_dist <- mat_dist[order(as.character(row.names(mat_dist))), order(as.character(colnames(mat_dist)))]graph_obs <- gen_graph_thr(mat_w = mat_dist, mat_thr = mat_dist, thr = 24000, mode = "larger")mat_gen <- mat_gen_dist(x = data_ex_genind, dist = "DPS")graph_pred <- gen_graph_topo(mat_w = mat_gen, mat_topo = mat_dist, topo = "gabriel")ARI <- graph_modul_compar(x = graph_obs, y = graph_pred)Compare the local properties of the nodes from two graphs
Description
The function computes a correlation coefficient between thegraph-theoretic metric values computed at the node-level in two graphssharing the same nodes. It allows to assess whether the connectivityproperties of the nodes in one graph are similar to that of the same nodesin the other graph. Alternatively, the correlation is computed betweena graph-theoretic metric values and the values of an attribute associatedto the nodes of a graph.
Usage
graph_node_compar( x, y, metrics = c("siw", "siw"), method = "spearman", weight = TRUE, test = TRUE)Arguments
x | An object of class |
y | An object of class |
metrics | Two-element character vector specifying the graph-theoreticmetrics computed at the node-level in the graphs or the node attributevalues to be correlated to these metrics.Graph-theoretic metrics can be:
Node attributes must have the same names as in the |
method | A character string indicating which correlation coefficientis to be computed ( |
weight | Logical which indicates whether the links are weighted duringthe calculation of the centrality indices betweenness and closeness.(default: |
test | Logical. Should significance testing be performed?(default = TRUE) |
Details
The correlation coefficients between the metrics can be computedin different ways, as initial assumptions (e.g. linear relationship) arerarely verified. Pearson's r, Spearman's rho and Kendall's tau can becomputed (from functioncor).Whenx is similar toy, then the correlation is computedbetween two metrics characterizing the nodes of the same graph.
Value
Alist summarizing the correlation analysis.
Author(s)
P. Savary
Examples
data(data_ex_genind)data(pts_pop_ex)mat_dist <- suppressWarnings(graph4lg::mat_geo_dist(data = pts_pop_ex, ID = "ID", x = "x", y = "y"))mat_dist <- mat_dist[order(as.character(row.names(mat_dist))), order(as.character(colnames(mat_dist)))]graph_obs <- gen_graph_thr(mat_w = mat_dist, mat_thr = mat_dist, thr = 9500, mode = "larger")mat_gen <- mat_gen_dist(x = data_ex_genind, dist = "DPS")graph_pred <- gen_graph_topo(mat_w = mat_gen, mat_topo = mat_dist, topo = "gabriel")res_cor <- graph_node_compar(x = graph_obs, y = graph_pred, metrics = c("siw", "siw"), method = "spearman", test = TRUE, weight = TRUE)Create a graph with a minimum planar graph topology
Description
The function constructs a graph with a minimum planargraph topology
Usage
graph_plan(crds, ID = NULL, x = NULL, y = NULL, weight = TRUE)Arguments
crds | A
|
ID | A character string indicating the name of the columnof |
x | A character string indicating the name of the columnof |
y | A character string indicating the name of the columnof |
weight | A character string indicating whether the links ofthe graph are weighted by Euclidean distances (TRUE)(default) or not (FALSE).When the graph links do not have weights in Euclidean distances, each linkis given a weight of 1. |
Details
A delaunay triangulation is performed in order to get theplanar graph.
Value
A planar graph of classigraph
Author(s)
P. Savary
Examples
data(pts_pop_ex)g_plan <- graph_plan(crds = pts_pop_ex, ID = "ID", x = "x", y = "y")Visualize the topological differences between two spatial graphs on a map
Description
The function enables to compare two spatial graphs byplotting them highlighting the topological similarities and differencesbetween them. Both graphs should share the same nodes and cannotbe directed graphs.
Usage
graph_plot_compar(x, y, crds)Arguments
x | A graph object of class |
y | A graph object of class |
crds | A
|
Details
The graphsx andy of classigraph must havenode names (not necessarily in the same order as IDs in crds,given a merging is done).
Value
A ggplot2 object to plot
Author(s)
P. Savary
Examples
data(pts_pop_ex)data(data_ex_genind)mat_w <- mat_gen_dist(data_ex_genind, dist = "DPS")mat_dist <- mat_geo_dist(data = pts_pop_ex, ID = "ID", x = "x", y = "y")mat_dist <- mat_dist[order(as.character(row.names(mat_dist))), order(as.character(colnames(mat_dist)))]g1 <- gen_graph_topo(mat_w = mat_w, topo = "mst")g2 <- gen_graph_topo(mat_w = mat_w, mat_topo = mat_dist, topo = "gabriel")g <- graph_plot_compar(x = g1, y = g2, crds = pts_pop_ex)Convert a graph into a edge list data.frame
Description
The function converts a graph into a edge list data.frame
Usage
graph_to_df(graph, weight = TRUE)Arguments
graph | A graph object of class |
weight | Logical. If TRUE (default), then the column 'link' of theoutput data.frame contains the weights of the links. If FALSE,it contains only 0 and 1. |
Details
The 'graph' nodes must have names. Links must have weights if'weight = TRUE'.
Value
An object of classdata.frame with a link ID, the origin nodes('from') and arrival nodes ('to') and the linkvalue ('link')(weighted or binary)
Author(s)
P. Savary
Examples
data(pts_pop_ex)suppressWarnings(mat_geo <- mat_geo_dist(pts_pop_ex, ID = "ID", x = "x", y = "y"))g1 <- gen_graph_thr(mat_w = mat_geo, mat_thr = mat_geo, thr = 20000)g1_df <- graph_to_df(g1, weight = TRUE)Export a spatial graph to shapefile layers
Description
The function enables to export a spatial graph toshapefile layers.
Usage
graph_to_shp( graph, crds, mode = "both", crds_crs, layer, dir_path, metrics = FALSE)Arguments
graph | A graph object of class |
crds | (if 'mode = 'spatial”) A
|
mode | Indicates which shapefile layers will be created
|
crds_crs | An integer indicating the EPSG code of the coordinatesreference system to use.The projection and datum are given in the PROJ.4 format. |
layer | A character string indicating the suffix of the name ofthe layers to be created. |
dir_path | A character string corresponding to the path to the directoryin which the shapefile layers will be exported. If |
metrics | (not considered if 'mode = 'link”) Logical. Should graphnode attributes integrated in the attribute table of the node shapefilelayer? (default: FALSE) |
Value
Create shapefile layers in the directory specified with the parameter'dir_path'.
Author(s)
P. Savary
Examples
## Not run: data(data_tuto)mat_w <- data_tuto[[1]]gp <- gen_graph_topo(mat_w = mat_w, topo = "gabriel")crds_crs <- 2154crds <- pts_pop_simullayer <- "graph_dps_gab"graph_to_shp(graph = gp, crds = pts_pop_simul, mode = "both", crds_crs = crds_crs, layer = "test_fonct", dir_path = tempdir(), metrics = FALSE) ## End(Not run)Compute an index comparing graph topologies
Description
The function computes several indices in order to compare twograph topologies. One of the graph has the "true" topology the other issupposed to reproduce. The indices are then a way to assess the reliabilityof the latter graph.Both graphs must have the same number of nodes, but not necessarily thesame number of links. They must also have the same node names and inthe same order.
Usage
graph_topo_compar(obs_graph, pred_graph, mode = "mcc", directed = FALSE)Arguments
obs_graph | A graph object of class |
pred_graph | A graph object of class |
mode | A character string specifying which index to compute in orderto compare the topologies of the graphs.
|
directed | Logical (TRUE or FALSE) specifying whether both graphsare directed or not. |
Details
The indices are calculated from a confusion matrix countingthe number of links that are in the "observed" graph ("true") and alsoin the "predicted" graph (true positives : TP), that are in the "observed"graph but not in the "predicted" graph (false negatives : FN), that are notin the "observed" graph but in the "predicted" graph (false positives : FP)and that are not in the "observed" graph and not in the "predicted" graphneither (true negatives: TN). K is the total number of links in the graphs.K is equal ton\times(n-1) if the graphs are directed and to\frac{n\times(n-1)}{2} if they are not directed, with n the numberof nodes.OP = TP + FN, ON = TN + FP, PP = TP + FP and PN = FN + TN.
The Matthews Correlation Coefficient (MCC) is computed as follows:MCC = \frac{TP\times TN-FP\times FN}{\sqrt{(TP+FP)(TP+FN)(TN+FP)(TN+FN)}}
The Kappa index is computed as follows:Kappa = \frac{K\times (TP + TN) - (ON \times PN) - (OP \times PP)}{K^{2} - (ON \times PN) - (OP \times PP)}
The False Discovery Rate (FDR) is calculated as follows:FDR = \frac{FP}{TP+FP}
The Accuracy is calculated as follows:Acc = \frac{TP + TN}{K}
The Sensitivity is calculated as follows:Sens = \frac{TP}{TP+FN}
The Specificity is calculated as follows:Spec = \frac{TN}{TN+FP}
The Precision is calculated as follows:Prec = \frac{TP}{TP+FP}
Self loops are not taken into account.
Value
The value of the index computed
Author(s)
P. Savary
References
Dyer RJ, Nason JD (2004).“Population graphs: the graph theoretic shape of genetic structure.”Molecular ecology,13(7), 1713–1727.Baldi P, Brunak S, Chauvin Y, Andersen CA, Nielsen H (2000).“Assessing the accuracy of prediction algorithms for classification: an overview.”Bioinformatics,16(5), 412–424.Matthews BW (1975).“Comparison of the predicted and observed secondary structure of T4 phage lysozyme.”Biochimica et Biophysica Acta (BBA)-Protein Structure,405(2), 442–451.
Examples
data(data_ex_genind)data(pts_pop_ex)mat_dist <- suppressWarnings(graph4lg::mat_geo_dist(data=pts_pop_ex, ID = "ID", x = "x", y = "y"))mat_dist <- mat_dist[order(as.character(row.names(mat_dist))), order(as.character(colnames(mat_dist)))]graph_obs <- gen_graph_thr(mat_w = mat_dist, mat_thr = mat_dist, thr = 15000, mode = "larger")mat_gen <- mat_gen_dist(x = data_ex_genind, dist = "DPS")graph_pred <- gen_graph_topo(mat_w = mat_gen, mat_topo = mat_dist, topo = "gabriel")graph_topo_compar(obs_graph = graph_obs, pred_graph = graph_pred, mode = "mcc", directed = FALSE)Computes custom capacities of patches in the Graphab project
Description
The function computes custom capacities of patchesin the Graphab project
Usage
graphab_capacity( proj_name, mode = "area", patch_codes = NULL, exp = NULL, ext_file = NULL, thr = NULL, linkset = NULL, codes = NULL, cost_conv = FALSE, weight = FALSE, proj_path = NULL, alloc_ram = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml is. It can be created with |
mode | A character string indicating the way capacities arecomputed. It must be either:
|
patch_codes | (optional, default=NULL) An integer value or vectorspecifying the codes corresponding to the habitat pixel whose correspondingpatches are included to compute the capacity as the area of the habitatwhen |
exp | An integer value specifying the power to which patch area areraised when |
ext_file | A character string specifying the name of the .csv file inwhich patch capacities are stored. It must be located either in the workingdirectory or in the directory defined by |
thr | (optional, default=NULL) An integer or numeric value indicatingthe maximum distance in cost distance units (except when |
linkset | (optional, default=NULL) A character string indicating thename of the link set used to take distance into account when computingthe capacity. Only used when |
codes | An integer value or a vector of integer values specifying thecodes of the raster cells taken into account when computing the capacity inthe neighbourhood of the patches, when |
cost_conv | FALSE (default) or TRUE. Logical indicating whether numeric |
weight | A logical indicating whether the cells are weighted by aweight decreasing with the distance from the patches (TRUE) or not (FALSE).The weights follow a negative exponential decline such thatwi = exp(-alpha*di), where wi is the weight of cell i, di its distance fromthe patch and alpha a parameter determined such that wi = 0.05 when di = thr. |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
alloc_ram | (optional, default = NULL) Integer or numeric valueindicating RAM gigabytes allocated to the java process. Increasing thisvalue can speed up the computations. Too large values may not be compatiblewith your machine settings. |
Details
See more information in Graphab 2.8 manual:https://sourcesup.renater.fr/www/graphab/download/manual-2.8-en.pdfBe careful, when capacity has been changed. The last changes are taken intoaccount for subsequent calculations in a project.
Author(s)
P. Savary
Examples
## Not run: graphab_capacity(proj_name = "grphb_ex", mode = "area")## End(Not run)Computes corridors from least-cost paths already computed inthe Graphab project
Description
The function computes corridors around the least-cost pathswhich have been computed in the Graphab project.
Usage
graphab_corridor( proj_name, graph, maxcost, format = "raster", cost_conv = FALSE, proj_path = NULL, alloc_ram = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml is. It can be created with |
graph | A character string indicating the name of the graph with thelinks from which the corridors are computed.This graph has been created with Graphab or using |
maxcost | An integer or numeric value indicating the maximum costdistance from the least-cost paths considered for creating the corridors,in cost distance units (except when |
format | (optional, default = "raster") A character string indicatingwhether the output is a raster file or a shapefile layer. |
cost_conv | FALSE (default) or TRUE. Logical indicating whether numeric |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
alloc_ram | (optional, default = NULL) Integer or numeric valueindicating RAM gigabytes allocated to the java process. Increasing thisvalue can speed up the computations. Too large values may not be compatiblewith your machine settings. |
Details
See more information in Graphab 2.8 manual:https://sourcesup.renater.fr/www/graphab/download/manual-2.8-en.pdfBe careful, when capacity has been changed. The last changes are taken intoaccount for subsequent calculations in a project.
Author(s)
P. Savary
Examples
## Not run: graphab_corridor(proj_name = "grphb_ex", graph = "graph", maxcost = 1000, format = "raster", cost_conv = FALSE)## End(Not run)Create a graph in the Graphab project
Description
The function creates a graph from a link set in a Graphab project
Usage
graphab_graph( proj_name, linkset = NULL, name = NULL, thr = NULL, cost_conv = FALSE, proj_path = NULL, alloc_ram = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml is. It can be created with |
linkset | (optional, default=NULL) A character string indicating thename of the link set used to create the graph. If |
name | (optional, default=NULL) A character string indicating thename of the graph created. If |
thr | (optional, default=NULL) An integer or numeric value indicatingthe maximum distance associated with the links of the created graph. Itallows users to create a pruned graph based on a distance threshold. Note thatwhen the link set used has a planar topology, the graph is necessarily apruned graph (not complete) and adding this threshold parameter can removeother links. When the link set has been created with cost-distances, theparameter is expressed in cost-distance units whereas when the link set isbased upon Euclidean distances, the parameter is expressed in meters. |
cost_conv | FALSE (default) or TRUE. Logical indicating whether numeric |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
alloc_ram | (optional, default = NULL) Integer or numeric valueindicating RAM gigabytes allocated to the java process. Increasing thisvalue can speed up the computations. Too large values may not be compatiblewith your machine settings. |
Details
By default, intra-patch distances are considered for metriccalculation. See more information in Graphab 2.8 manual:https://sourcesup.renater.fr/www/graphab/download/manual-2.8-en.pdf
Author(s)
P. Savary
Examples
## Not run: graphab_graph(proj_name = "grphb_ex", linkset = "lcp", name = "graph")## End(Not run)Creates a raster with interpolated connectivity metric values from metricsalready computed in the Graphab project
Description
The function creates a raster with interpolated connectivitymetric values from a metric already computed in the Graphab project.
Usage
graphab_interpol( proj_name, name, reso, linkset, graph, var, dist, prob = 0.05, thr = NULL, summed = FALSE, proj_path = NULL, alloc_ram = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml is. It can be created with |
name | A character string indicating the name of the raster to becreated after the interpolation. |
reso | An integer indicating the spatial resolution in meters of theraster resulting from the metric interpolation. |
linkset | A character string indicating the name of the link set usedfor the interpolation. It should be the one used to create the used graphand the metric. |
graph | A character string indicating the name of the graph from whichthe metric was computed and whose links are considered for a potentialmulti-linkage with patches.This graph has been created with Graphab or using |
var | A character string indicating the name of the already computedmetric to be interpolated. |
dist | A numeric or integer value specifying the distance at which weassume a probability equal to |
prob | A numeric or integer value specifying the probabilityat distance |
thr | (default NULL) If NULL, the value of each pixel is computed fromthe value of the metric at the nearest habitat patch, weighted by aprobability depending on distance. If an integer, the value of each pixeldepends on the values of the metric taken at several of the nearest habitatpatches, up to a distance (cost or Euclidean distance, depending on the typeof linkset) equal to |
summed | Logical (default = FALSE) only used if |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
alloc_ram | (optional, default = NULL) Integer or numeric valueindicating RAM gigabytes allocated to the java process. Increasing thisvalue can speed up the computations. Too large values may not be compatiblewith your machine settings. |
Details
See more information in Graphab 2.8 manual:https://sourcesup.renater.fr/www/graphab/download/manual-2.8-en.pdfBe careful, when capacity has been changed. The last changes are taken intoaccount for subsequent calculations in a project.
Author(s)
P. Savary
Examples
## Not run: graphab_interpol(proj_name = "grphb_ex", name = "F_interp", reso = 20, linkset = "lcp", graph = "graph", var = "F_d600_p0.5_beta1_graph", dist = 600, prob = 0.5)## End(Not run)Create a link set in the Graphab project
Description
The function creates a link set between habitat patches in theGraphab project.
Usage
graphab_link( proj_name, distance = "cost", name, cost = NULL, topo = "planar", remcrosspath = FALSE, proj_path = NULL, alloc_ram = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml is. It can be created with |
distance | A character string indicating whether links between patchesare computed based on:
In the resulting link set, each link will be associated with itscorresponding cost-distance and the length of the least-cost path in meters(if |
name | A character string indicating the name of the created linkset. |
cost | This argument could be:
|
topo | A character string indicating the topology of the createdlink set. It can be:
|
remcrosspath | (optional, default = FALSE) A logical indicating whetherlinks crossing patches are removed (TRUE). |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
alloc_ram | (optional, default = NULL) Integer or numeric valueindicating RAM gigabytes allocated to the java process. Increasing thisvalue can speed up the computations. Too large values may not be compatiblewith your machine settings. |
Details
By default, links crossing patches are not ignored nor broken intotwo links. For example, a link from patches A to C crossing patch Bis created. It takes into account the distance inside patch B. It can be aproblem when computing BC index. See more information in Graphab 2.8 manual:https://sourcesup.renater.fr/www/graphab/download/manual-2.8-en.pdf
Author(s)
P. Savary, T. Rudolph
Examples
## Not run: df_cost <- data.frame(code = 1:5, cost = c(1, 10, 100, 1000, 1))graphab_link(proj_name = "grphb_ex", distance = "cost", name = "lcp", cost = df_cost, topo = "complete")## End(Not run)Compute connectivity metrics from a graph in the Graphab project
Description
The function computes connectivity metrics on a graph from alink set in a Graphab project
Usage
graphab_metric( proj_name, graph, metric, multihab = FALSE, dist = NULL, prob = 0.05, beta = 1, cost_conv = FALSE, return_val = TRUE, proj_path = NULL, alloc_ram = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml is. |
graph | A character string indicating the name of the graph on whichthe metric is computed. This graph has been created with Graphabor using |
metric | A character string indicating the metric which will be computedon the graph. This metric can be:
For most metrics, the interaction probability is computed for each pair ofpatches from the path that minimizes the distance d (or the cost) betweenthem. It then maximizes |
multihab | A logical (default = FALSE) indicating whether the'multihabitat' mode is used when computing the metric. It only applies tothe following metrics: 'EC', 'F', 'IF' and 'BC'. If TRUE, then the projectmust have been created with the option |
dist | A numeric or integer value specifying the distance at whichdispersal probability is equal to |
prob | A numeric or integer value specifying the dispersal probabilityat distance |
beta | A numeric or integer value between 0 and 1 specifying theexponent associated with patch areas in the computation of metricsweighted by patch area. By default, |
cost_conv | FALSE (default) or TRUE. Logical indicating whether numeric |
return_val | Logical (default = TRUE) indicating whether metric valuesare returned in R (TRUE) or only stored in the patch attribute layer (FALSE) |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
alloc_ram | (optional, default = NULL) Integer or numeric valueindicating RAM gigabytes allocated to the java process. Increasing thisvalue can speed up the computations. Too large values may not be compatiblewith your machine settings. |
Details
The metrics are described in Graphab 2.8 manual:https://sourcesup.renater.fr/www/graphab/download/manual-2.8-en.pdfGraphab software makes possible the computation of other metrics.Be careful, when the same metric is computed several times, the optionreturn=TRUE is not returning the right columns. In these cases,useget_graphab_metric.
Value
Ifreturn_val=TRUE, the function returns adata.framewith the computed metric values and the corresponding patch ID when themetric is local or delta metric, or the numeric value of the global metric.
Author(s)
P. Savary
Examples
## Not run: graphab_metric(proj_name = "grphb_ex", graph = "graph", metric = "PC", dist = 1000, prob = 0.05, beta = 1)## End(Not run)Create modules from a graph in the Graphab project
Description
The function creates modules from a graph by maximisingmodularity
Usage
graphab_modul( proj_name, graph, dist, prob = 0.05, beta = 1, nb = NULL, return = TRUE, proj_path = NULL, alloc_ram = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml is. |
graph | A character string indicating the name of the graph on whichthe modularity index is computed. This graph has been created with Graphabor using |
dist | A numeric or integer value specifying the distance at whichdispersal probability is equal to |
prob | A numeric or integer value specifying the dispersal probabilityat distance |
beta | A numeric or integer value between 0 and 1 specifying theexponent associated with patch areas in the computation of metricsweighted by patch area. By default, |
nb | (optional, default=NULL) An integer or numeric value indicatingthe number of modules to be created. By default, it is the number thatmaximises the modularity index. |
return | Logical (default=TRUE) indicating whether results are returnedto user. |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
alloc_ram | (optional, default = NULL) Integer or numeric valueindicating RAM gigabytes allocated to the java process. Increasing thisvalue can speed up the computations. Too large values may not be compatiblewith your machine settings. |
Details
This function maximises a modularity index by searching for thenode partition involves a large number of links within modules and a smallnumber of inter-module links. Each link is given a weight in the computation,such as the weightw_{ij} of the link between patches i and j is:
w_{ij} = (a_{i} a_{j})^\beta e^{-\alpha d_{ij}}
.This function does not allow users to convert automatically Euclideandistances into cost-distances.See more information in Graphab 2.8 manual:https://sourcesup.renater.fr/www/graphab/download/manual-2.8-en.pdf
Value
Ifreturn=TRUE, the function returns a message indicatingwhether the partition has been done. New options are being developed.
Author(s)
P. Savary
Examples
## Not run: graphab_modul(proj_name = "grphb_ex", graph = "graph", dist = 1000, prob = 0.05, beta = 1)## End(Not run)Add a point set to the Graphab project
Description
The function adds a spatial point set to the Graphab project,allowing users to identify closest habitat patch from each point andget corresponding connectivity metrics.
Usage
graphab_pointset( proj_name, linkset, pointset, id = "ID", return_val = TRUE, proj_path = NULL, alloc_ram = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml is. |
linkset | A character string indicating the name of the link set used.The link set is here used to get the defined cost values and compute thedistance from the point to the patches. Link sets can be createdwith |
pointset | Can be either;
The point ID column must be 'ID' by default but can also be specifiedby the |
id | A character string indicating the name of the column in eitherthe .csv table, data.frame or attribute table, corresponding to the IDof the points. By default, it should be 'ID'. This column is used for namingthe points when returning the output. |
return_val | Logical (default=TRUE) indicating whether the metricsassociated with closest habitat patches from the points are returned tousers. |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
alloc_ram | (optional, default = NULL) Integer or numeric valueindicating RAM gigabytes allocated to the java process. Increasing thisvalue can speed up the computations. Too large values may not be compatiblewith your machine settings. |
Details
Point coordinates must be in the same coordinate reference systemas the habitat patches (and initial raster layer). See more information inGraphab 2.8 manual:https://sourcesup.renater.fr/www/graphab/download/manual-2.8-en.pdf
Value
Ifreturn_val=TRUE, the function returns adata.framewith the properties of the nearest patch to every point in the point set,as well as the distance from each point to the nearest patch.
Author(s)
P. Savary
Examples
## Not run: graphab_pointset(proj_name = "grphb_ex", graph = "graph", pointset = "pts.shp")## End(Not run)Create a Graphab project
Description
The function creates a Graphab project from a raster file onwhich habitat patches can be delimited.
Usage
graphab_project( proj_name, raster, habitat, nomerge = FALSE, minarea = 0, nodata = NULL, maxsize = NULL, con8 = FALSE, alloc_ram = NULL, proj_path = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml will be created. |
raster | A character string indicating the name of the .tif raster fileor of its path. If the path is not specified, the raster must be present inthe current working directory. Raster cell values must be in INT2S encoding. |
habitat | An integer or numeric value or vector indicating thecode.s (cell value.s) of the habitat cells in the raster file. |
nomerge | (optional, default=FALSE) A logical indicating whethercontiguous patches corresponding to different pixel codes are merged(FALSE, default) or not merged (TRUE).Be careful, the |
minarea | (optional, default=0) An integer or numeric value specifiyingthe minimum area in hectares for a habitat patch size to become a graph node. |
nodata | (optional, default=NULL) An integer or numeric valuespecifying the code in the raster file associated with nodata value(often corresponding to peripheric cells) |
maxsize | (optional, default=NULL) An integer or numeric valuespecifying the maximum side length of the rectangular full extent of eachhabitat patch in metric units. If this side length exceeds |
con8 | (optional, default=FALSE) A logical indicating whether aneighborhood of 8 pixels (TRUE) is used for patch definition. By default, |
alloc_ram | (optional, default = NULL) Integer or numeric valueindicating RAM gigabytes allocated to the java process. Increasing thisvalue can speed up the computations. Too large values may not be compatiblewith your machine settings. |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
Details
A habitat patch consists of the central pixel with its eightneighbors if they are of the same value (8-connexity) and the pathgeometry is not simplified. See more information in Graphab 2.8 manual:https://sourcesup.renater.fr/www/graphab/download/manual-2.8-en.pdf
Author(s)
P. Savary, T. Rudolph
Examples
## Not run: proj_name <- "grphb_ex"raster <- "rast_ex.tif"habitat <- 5graphab_project(proj_name = proj_name, raster = raster, habitat = habitat)## End(Not run)Describe the objects of a Graphab project
Description
The function describes the objects of a Graphab project
Usage
graphab_project_desc( proj_name, mode = "patches", linkset = NULL, proj_path = NULL, fig = FALSE, return_val = TRUE)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml is. |
mode | A character string indicating the objects of the project thatare described. It must be either:
|
linkset | A character string indicating the name of the link setwhose properties are imported. The link set has been created with Graphabor using |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory. It should be used when theproject directory is not in the current working directory. Default is NULL.When 'proj_path = NULL', the project directory is equal to |
fig | Logical (default = FALSE) indicating whether to plot a figure ofthe resulting spatial graph. The figure is plotted using function |
return_val | Logical (default = TRUE) indicating whether the projectfeatures are returned as a list (TRUE) or only displayed in theR console (FALSE). |
Author(s)
P. Savary
Examples
## Not run: graphab_project_desc(proj_name = "grphb_ex", mode = "patches", fig = FALSE)## End(Not run)Create landscape graphs from Graphab link set
Description
The function creates a landscape graph from a link set createdwith Graphab software or different functions of this package and convertsit into a graph object of classigraph.The graph has weighted links and is undirected.Nodes attributes present in the Graphab project are included, includingconnectivity metrics when computed
Usage
graphab_to_igraph( proj_name, linkset, nodes = "patches", weight = "cost", proj_path = NULL, fig = FALSE, crds = FALSE)Arguments
proj_name | A character string indicating the project name. It is alsothe name of the directory in which proj_name.xml file is found. By default,'proj_name' is searched into the current working directory |
linkset | A character string indicating the name of the linkset used tocreate the graph links. The linkset must have been created previously (seethe function |
nodes | A character string indicating whether the nodes of the createdgraph are given all the attributes or metrics computed in Graphab or onlythose specific to a given graph previously created with
|
weight | A character string ("euclid" or "cost") indicatingwhether to weight the links with Euclidean distance orcost-distance (default) values. |
proj_path | (optional) A character string indicating the path to thedirectory that contains the project directory ('proj_name'). By default,'proj_name' is searched into the current working directory |
fig | Logical (default = FALSE) indicating whether to plot a figure ofthe resulting spatial graph. The figure is plotted using function |
crds | Logical (default = FALSE) indicating whether to create an objectof class |
Value
A graph object of classigraph (if crds = FALSE) or alist of objects: a graph object of classigraph and adata.frame with the nodes spatial coordinates (if crds = TRUE).
Author(s)
P. Savary
References
Foltête J, Clauzel C, Vuidel G (2012).“A software tool dedicated to the modelling of landscape networks.”Environmental Modelling & Software,38, 316–327.
Examples
## Not run: proj_path <- system.file('extdata',package='graph4lg')proj_name <- "grphb_ex"linkset <- "lkst1"nodes <- "graph"graph <- graphab_to_igraph(proj_name = proj_name, linkset = "lkst1", nodes = "graph", links = links, weights = "cost", proj_path = proj_path, crds = FALSE, fig = FALSE) ## End(Not run)Convert a file fromgstudio orpopgraph into a genind object
Description
The function converts a file formatted to usegstudio orpopgraph package into a genind object (adegenet package)
Usage
gstud_to_genind(x, pop_col, ind_col = NULL)Arguments
x | An object of class |
pop_col | A character string indicating the name of the column withpopulations' names in |
ind_col | (optional) A character string indicating the name of thecolumn with individuals' ID in |
Details
This function uses functions frompegas package.It can handle genetic data where alleles codings do not have same length,(99:101, for example).If the names of the loci include '.' characters, they willbe replaced by '_'.
Value
An object of classgenind.
Author(s)
P. Savary
Examples
data("data_ex_gstud")x <- data_ex_gstudpop_col <- "POP"ind_col <- "ID"data_genind <- gstud_to_genind(x, pop_col, ind_col)Compute the harmonic mean of a numeric vector
Description
The function computes the harmonic mean of a numeric vector
Usage
harm_mean(x)Arguments
x | A numeric vector |
Value
A numeric value corresponding to the harmonic mean of the vector
Author(s)
P. Savary
Examples
x <- c(10, 2, 5, 15)hm <- harm_mean(x)Compute dispersal kernel parameters
Description
The function computes the constant parameters of a dispersalkernel with a negative exponential distribution
Usage
kernel_param(p, d_disp, mode = "A")Arguments
p | A numeric value indicating the dispersal probability at a distanceequal to 'd_disp' under a negative exponential distribution. |
d_disp | A numeric value indicating the distance to which dispersalprobability is equal to 'p' under a negative exponential distribution. |
mode | A character string indicating the value to return:
|
Details
If the resulting parameter when mode = "A" is a and the resultingparameter when mode = "B" is b, then we have:p = exp(-a.d_disp) = 10^(-b.d_disp) and a = b.ln(10)
Value
A numeric value
Author(s)
P. Savary
Examples
p <- 0.5d_disp <- 3000alpha <- kernel_param(p, d_disp, mode = "A")Compare two link sets created in a Graphab project
Description
The function compares two link sets created in a Graphab projectboth quantitatively and spatially.
Usage
link_compar( proj_name, linkset1, linkset2, buffer_width = 200, min_length = NULL, proj_path = NULL)Arguments
proj_name | A character string indicating the Graphab project name.The project name is also the name of the project directory in which thefile proj_name.xml is. It can be created with |
linkset1 | A character string indicating the name of the first link setinvolved in the comparison. The link set has to be present in the projectand can be created with |
linkset2 | A character string indicating the name of the second link setinvolved in the comparison. The link set has to be present in the projectand can be created with |
buffer_width | (default=200) An integer or numeric valueindicating the width of the buffer created in each side of the links priorto spatial intersection. It is expressed in meters. |
min_length | (optional, default=NULL) An integer or numeric valueindicating the minimum length in meters of the links to be compared. Linkswhose length is larger than |
proj_path | (optional, default=NULL) A character string indicating thepath to the directory that contains the project directory. It should be usedwhen the project directory is not in the current working directory.Default is NULL. When 'proj_path = NULL', the project directory is equalto |
Details
The function compares two link sets linking the same habitat patchesof the Graphab project but computed using different cost scenarios. Itcreates a buffer in each side of every link and then overlaps every linkin linkset1 with the same link in linkset2. It returns the area of bothbuffered links and the area of their intersection. It also computes theMantel correlation coefficient between the cost distances associated to thesame links in both linksets.
Author(s)
P. Savary
Examples
## Not run: link_compar(proj_name = "grphb_ex", linkset1 = "lcp1", linkset2 = "lcp2" buffer_width = 200)## End(Not run)Convert a loci object into a genind object
Description
This function is exactly the same asloci2genindfrompegas package
Usage
loci_to_genind(x, ploidy = 2, na.alleles = c("NA"))Arguments
x | An object of class |
ploidy | An integer indicating the ploidy level(by default, 'ploidy = 2') |
na.alleles | A character vector indicating the coding of the allelesto be treated as missing data (by default, 'na.alleles = c("NA")') |
Value
An object of classgenind
Author(s)
P. Savary
Examples
data("data_ex_loci")genind <- loci_to_genind(data_ex_loci, ploidy = 2, na.alleles = "NA")Compute cost distances between points on a raster
Description
The function computes cost-distances associated to least costpaths between point pairs on a raster with specified cost values.
Usage
mat_cost_dist( raster, pts, cost, method = "gdistance", return = "mat", direction = 8, parallel.java = 1, alloc_ram = NULL)Arguments
raster | A parameter indicating the raster file on which cost distancesare computed. It can be:
All the raster cell values must be present in the column 'code' from |
pts | A parameter indicating the points between which cost distancesare computed. It can be either:
The point coordinates must be in the same spatial coordinate reference systemas the raster file. |
cost | A
|
method | A character string indicating the method used to compute thecost distances. It must be:
|
return | A character string indicating whether the returned object is a |
direction | An integer (4, 8, 16) indicating the directions in whichmovement can take place from a cell. Only used when |
parallel.java | An integer indicating how many computer cores are usedto run the .jar file. By default, |
alloc_ram | (optional, default = NULL) Integer or numeric valueindicating RAM gigabytes allocated to the java process when used. Increasingthis value can speed up the computations. Too large values may not becompatible with your machine settings. |
Value
The function returns:
If
return="mat", a pairwisematrixwith cost-distancevalues between points.If
return="df", an object of typedata.framewith three columns:from: A character string indicating the ID of the point of origin.
to: A character string indicating the ID of the point of destination.
cost_dist: A numeric indicating the accumulated cost-distance alongthe least-cost path between point ID1 and point ID2.
Author(s)
P. Savary
Examples
## Not run: x <- raster::raster(ncol=10, nrow=10, xmn=0, xmx=100, ymn=0, ymx=100)raster::values(x) <- sample(c(1,2,3,4), size = 100, replace = TRUE)pts <- data.frame(ID = 1:4, x = c(10, 90, 10, 90), y = c(90, 10, 10, 90))cost <- data.frame(code = 1:4, cost = c(1, 10, 100, 1000))mat_cost_dist(raster = x, pts = pts, cost = cost, method = "gdistance")## End(Not run)Compute a pairwise matrix of genetic distances between populations
Description
The function computes a pairwise matrix of genetic distancesbetween populations and allows to implement several formula.
Usage
mat_gen_dist(x, dist = "basic", null_val = FALSE)Arguments
x | An object of class |
dist | A character string indicating the method used to compute themultilocus genetic distance between populations
|
null_val | (optional) Logical. Should negative and null FST, FST_lin,GST or D values be replaced by half the minimum positive value?This option allows to compute Gabriel graphs from these "distances".Default is null_val = FALSE.This option only works if 'dist = 'FST” or 'FST_lin' or 'GST' or 'D' |
Details
Negative values are converted into 0.Euclidean genetic distanced_{ij} between population i and jis computed as follows:
d_{ij}^{2} = \sum_{k=1}^{n} (x_{ki} - x_{kj})^{2}
wherex_{ki} is the allelic frequency of allele k in population i and n isthe total number of alleles. Note that when 'dist = 'weight”, the formulabecomes
d_{ij}^{2} = \sum_{k=1}^{n} (1/(K*p_{k}))(x_{ki} - x_{kj})^{2}
where K is the number of alleles at the locus of the allele k andp_{k}is the frequency of the allele k in all populations.Note that when 'dist = 'PCA”, n is the number of conserved independentprincipal components andx_{ki} is the value taken by the principalcomponent k in population i.
Value
An object of classmatrix
Author(s)
P. Savary
References
Bowcock AM, Ruiz-Linares A, Tomfohrde J, Minch E, Kidd JR, Cavalli-Sforza LL (1994).“High resolution of human evolutionary trees with polymorphic microsatellites.”nature,368(6470), 455–457.Excoffier L, Smouse PE, Quattro JM (1992).“Analysis of molecular variance inferred from metric distances among DNA haplotypes: application to human mitochondrial DNA restriction data.”Genetics,131(2), 479–491.Dyer RJ, Nason JD (2004).“Population graphs: the graph theoretic shape of genetic structure.”Molecular ecology,13(7), 1713–1727.Fortuna MA, Albaladejo RG, Fernández L, Aparicio A, Bascompte J (2009).“Networks of spatial genetic variation across species.”Proceedings of the National Academy of Sciences,106(45), 19044–19049.Weir BS, Cockerham CC (1984).“Estimating F-statistics for the analysis of population structure.”evolution,38(6), 1358–1370.Hedrick PW (2005).“A standardized genetic differentiation measure.”Evolution,59(8), 1633–1638.Jost L (2008).“GST and its relatives do not measure differentiation.”Molecular ecology,17(18), 4015–4026.
Examples
data(data_ex_genind)x <- data_ex_genindD <- mat_gen_dist(x = x, dist = "basic")Compute Euclidean geographic distances between points
Description
The function computes Euclidean geographic distance betweenpoints given their spatial coordinates either in a metric projectedCoordinate Reference System or in a polar coordinates system.
Usage
mat_geo_dist( data, ID = NULL, x = NULL, y = NULL, crds_type = "proj", gc_formula = "vicenty")Arguments
data | An object of class :
|
ID | (if |
x | (if |
y | (if |
crds_type | A character string indicating the type of coordinatereference system:
|
gc_formula | A character string indicating the formula used to computethe Great Circle distance:
|
Details
When a projected coordinate reference system is used, it calculatesclassical Euclidean geographic distance between two points usingPythagora's theorem. When a polar coordinate reference system is used, itcalculates the Great circle distance between points using different methods.Unlessmethod = "polar", whendata is adata.frame,it assumes projected coordinates by default.
Value
A pairwise matrix of geographic distances between points in meters
Author(s)
P. Savary
Examples
# Projected CRSdata(pts_pop_simul)mat_dist <- mat_geo_dist(data=pts_pop_simul, ID = "ID", x = "x", y = "y")#Polar CRScity_us <- data.frame(name = c("New York City", "Chicago", "Los Angeles", "Atlanta"), lat = c(40.75170, 41.87440, 34.05420, 33.75280), lon = c(-73.99420, -87.63940, -118.24100, -84.39360))mat_geo_us <- mat_geo_dist(data = city_us, ID = "name", x = "lon", y = "lat", crds_type = "polar")Compute a pairwise genetic distance matrix between populationsusing Bowcock et al. (1994) formula
Description
The function computes the pairwise DPS, a genetic distancebased on the proportion of shared alleles.
Usage
mat_pw_dps(x)Arguments
x | An object of class |
Details
The formula used is inspired from MSA software :
D_{PS}=1-\frac{\sum_{d}^{D}\sum_{k}^{K}\min (f_{a_{kd}i},f_{a_{kd}j})}{D}
such asa_{kd} is the allelek at locusdD is the total number of lociK is the allele number at each locus\gamma_{a_{kd^{ij}}}=0 if individualsi andjdo not share allelea_{kd}\gamma_{a_{kd^{ij}}}=1 if one of individualsi andjhas a copy ofa_{kd}\gamma_{a_{kd^{ij}}}=2 if both individuals have 2 copiesofa_{kd} (homozygotes)f_{a_{kd}i} is allelea_{kd} frequency inindividuali (0, 0.5 or 1).More information in :Bowcock et al., 1994and Microsatellite Analyser software (MSA) manual.This function uses functions fromadegenet packageNote that in the paper of Bowcock et al. (1994), the denominator is 2D.But, in MSA software manual, the denominator is D.
Value
A pairwise matrix of genetic distances between populations
Author(s)
P. Savary
References
Bowcock AM, Ruiz-Linares A, Tomfohrde J, Minch E, Kidd JR, Cavalli-Sforza LL (1994).“High resolution of human evolutionary trees with polymorphic microsatellites.”nature,368(6470), 455–457.
Examples
data("data_ex_genind")dist_bowcock <- mat_pw_dps(data_ex_genind)Compute a pairwise FST matrix between populations
Description
The function computes the pairwise FST matrix betweenpopulations from an object of classgenind
Usage
mat_pw_fst(x)Arguments
x | An object of class |
Details
The formula used is that of Weir et Cockerham (1984).This functions uses directly the functionpairwise.WCfstfromhierfstat.
Value
A pairwisematrix of FST with as many rows and columns asthere are populations in the input data.
Warnings
Negative values are converted into 0
Author(s)
P. Savary
References
Weir BS, Cockerham CC (1984).“Estimating F-statistics for the analysis of population structure.”evolution,38(6), 1358–1370.
Examples
## Not run: data("data_ex_genind")mat_fst <- mat_pw_fst(data_ex_genind)## End(Not run)Vector of custom colors
Description
Vector of custom colors
Usage
mypaletteFormat
An object of classcharacter of length 27.
Examples
mypalette[1]Extract patch areas from a categorical raster
Description
The function extracts patch areas from a categorical raster
Usage
patch_areas(raster, class, edge_size = 0, neighborhood = 8, surf_min = 0)Arguments
raster | A RasterLayer object corresponding to a categorical raster layer |
class | An integer value or vector with the value(s) corresponding tothe code values of the raster layer within which points will be sampled.are computed. |
edge_size | An integer value indicating the width of the edge(in meters) of the raster layer which is ignored during the sampling(default = 0). It prevents from sampling in the margins of the study area. |
neighborhood | An integer value indicating which cells are consideredadjacent when contiguous patches are delineated (it should be 8(default, Queen's case) or 4 (Rook's case)). This parameter is ignoredwhen |
surf_min | An integer value indicating the minimum surface of a patchconsidered for the sampling in number of raster cells. This parameter is usedwhatever the |
Value
A data.frame with the areas of the patches
Author(s)
P. Savary
Plot graphs
Description
The function enables to plot graphs, whether spatial or not.
Usage
plot_graph_lg( graph, crds = NULL, mode = "aspatial", node_inter = NULL, link_width = NULL, node_size = NULL, module = NULL, pts_col = NULL)Arguments
graph | A graph object of class |
crds | (optional, default = NULL) If 'mode = 'spatial”, it is a
This argument is not used when 'mode = 'aspatial” and mandatory when 'mode ='spatial”. |
mode | A character string indicating whether the graph isspatial ('mode = 'spatial”) or not ('mode = 'aspatial” (default)) |
node_inter | (optional, default = NULL) A character string indicatingwhether the links of the graph are weighted by distances or by similarityindices. It is only used when 'mode = 'aspatial” to compute the nodepositions with Fruchterman and Reingold algorithm. It can be equal to:
|
link_width | (optional, default = NULL) A character string indicatinghow the width of the link is set on the figure. Their width can be:
|
node_size | (optional, default = NULL) A character string indicatingthe graph node attribute used to set the node size on the figure. It must bethe name of a numeric or integer node attribute from the graph. |
module | (optional, default = NULL) A character string indicatingthe graph node modules used to set the node color on the figure. It must bethe name of a node attribute from the graph with discrete values. |
pts_col | (optional, default = NULL) A character string indicating thecolor used to plot the nodes (default: "#F2B950"). It must be a hexadecimalcolor code or a color used by default in R. It cannot be used if 'module' isspecified. |
Details
When the graph is not spatial ('mode = 'aspatial”),the nodes coordinates are calculated with Fruchterman et Reingold algorithm.The graph objectgraph of classigraph must have node names(not necessarily in the same order as IDs in crds, given a merging is done).
Value
A ggplot2 object to plot
Author(s)
P. Savary
References
Fruchterman TM, Reingold EM (1991).“Graph drawing by force-directed placement.”Software: Practice and experience,21(11), 1129–1164.
Examples
data(pts_pop_ex)data(data_ex_genind)mat_w <- mat_gen_dist(data_ex_genind, dist = "DPS")gp <- gen_graph_topo(mat_w = mat_w, topo = "mst")g <- plot_graph_lg(graph = gp, crds = pts_pop_ex, mode = "spatial", link_width = "inv_w")Plot histograms of link weights
Description
The function enables to plot histogram to visualize thedistribution of the link weights
Usage
plot_w_hist(graph, fill = "#396D35", class_width = NULL)Arguments
graph | A graph object of class |
fill | A character string indicating the color used to fillthe bars (default: "#396D35"). It must be a hexadecimal color code ora color used by default in R. |
class_width | (default values: NULL) A numeric or an integer specifyingthe width of the classes displayed on the histogram. When it is notspecified, the width is equal to the difference between the minimum andmaximum values divided by 80. |
Value
A ggplot2 object to plot
Author(s)
P. Savary
Examples
data(data_ex_genind)mat_w <- mat_gen_dist(data_ex_genind, dist = "DPS")gp <- gen_graph_topo(mat_w = mat_w, topo = "gabriel")hist <- plot_w_hist(gp)Compute population-level genetic indices
Description
The function computes population-level genetic indices from anobject of classgenind.
Usage
pop_gen_index(x, pop_names = NULL, indices = c("Nb_ind", "A", "He", "Ho"))Arguments
x | An object of class |
pop_names | (optional) A character vector indicating population names.It is of the same length as the number of populations. Without thisargument, populations are given the names they have initially in the'genind' object (which is sometimes only a number). The order of thepopulation names must match with their order in the 'genind' object.The function does not reorder them. Users must be careful. |
indices | (optional) A character vector indicating the population-levelindices to compute. These indices can be:
By default, |
Value
An object of classdata.frame whose rowscorrespond to populations and columns to population attributes(ID, size, genetic indices). By default, the first column corresponds tothe population names (ID). The order of the columns depends on thevector 'indices'.
Author(s)
P. Savary
Examples
data(data_ex_genind)x <- data_ex_genindpop_names <- levels(x@pop)df_pop_indices <- pop_gen_index(x = x, pop_names = pop_names, indices = c("Nb_ind", "A"))Compute population-level rarefied genetic indices with ADZE software
Description
The function computes population-level rarefied genetic indicesfrom an object of classgenind with the ADZE software.
Usage
pop_rare_gen_index(x, max_g = NULL, pop_names = NULL, OS = "linux")Arguments
x | An object of class |
max_g | (optional default = NULL) The maximum standardized sample sizeused by ADZE software (MAX_G) in ADZE manual. It is equal to twice theminimum number of individuals considered for the rarefaction analysis. Bydefault, it is equal to twice the number of individuals in the smallestpopulation. Ohterwise, it must be either a numeric or integer value. |
pop_names | (optional) A character vector indicating population names.It is of the same length as the number of populations. Without thisargument, populations are given the names they have initially in the'genind' object (which is sometimes only a number). The order of thepopulation names must match with their order in the 'genind' object.The function does not reorder them. Users must be careful. |
OS | A character string indicating whether you use a Linux ('linux')or Windows ('win') operating system. |
Value
An object of classdata.frame whose rowscorrespond to populations and columns to population attributes(ID, size, genetic indices). By default, the first column corresponds tothe population names (ID). The order of the columns depends on thevector 'indices'.
Author(s)
P. Savary
pts_pop_ex : details on simulated populations
Description
Simulation dataset10 populations located on a simulated landscape
Usage
pts_pop_exFormat
An object of class 'data.frame' with the following columns :
- ID
Population ID of the 10 populations
- x
Site longitude (RGF93)
- y
Site latitude (RGF93)
References
Landguth EL, Cushman SA (2010).“CDPOP: a spatially explicit cost distance population genetics program.”Molecular Ecology Resources,10(1), 156–161.There are as many rows as there are sampled populations.
Examples
data("pts_pop_ex")str(pts_pop_ex)pts_pop_simul : details on simulated populations
Description
Simulation dataset50 populations located on a simulated landscape
Usage
pts_pop_simulFormat
An object of class 'data.frame' with the following columns :
- ID
Population ID of the 50 populations
- x
Site longitude (RGF93)
- y
Site latitude (RGF93)
References
Landguth EL, Cushman SA (2010).“CDPOP: a spatially explicit cost distance population genetics program.”Molecular Ecology Resources,10(1), 156–161.There are as many rows as there are sampled populations.
Examples
data("pts_pop_simul")str(pts_pop_simul)Convert a pairwise matrix into an edge-list data.frame
Description
The function converts a pairwise matrix into an edge-listdata.frame
Usage
pw_mat_to_df(pw_mat)Arguments
pw_mat | A pairwise matrix which can be:
|
Value
An object of classdata.frame
Author(s)
P. Savary
Examples
data(data_tuto)pw_mat <- data_tuto[[1]]df <- pw_mat_to_df(pw_mat)Reorder the rows and columns of a symmetric matrix
Description
The function reorders the rows and columns of a symmetricmatrix according to a specified order.
Usage
reorder_mat(mat, order)Arguments
mat | An object of class |
order | A character vector with the rows and columns names of the matrixin the order in which they will be ordered by the function. All its elementsmust be rows and columns names of the matrix |
Details
The matrixmat must be symmetric and have rows and columnsnames. Its values are not modified.
Value
A reordered symmetric matrix
Author(s)
P. Savary
Examples
mat <- matrix(rnorm(36), 6)mat[lower.tri(mat)] <- t(mat)[lower.tri(mat)]row.names(mat) <- colnames(mat) <- c("A", "C", "E", "B", "D", "F")order <- c("A", "B", "C", "D", "E", "F")mat <- reorder_mat(mat = mat, order = order)Sample points or patches on a categorical raster layer
Description
The function samples points or patches on a categorical rasterlayer.
Usage
sample_raster( raster, class, nb_pts, dist_min = 0, edge_size = 0, by_patch = TRUE, neighborhood = 8, surf_min = 0, prop_area = TRUE, step_max = 1000, output = "df", desc = TRUE)Arguments
raster | A RasterLayer object corresponding to a categorical raster layer |
class | An integer value or vector with the value(s) corresponding tothe code values of the raster layer within which points will be sampled. |
nb_pts | An integer value indicating the number of points to be sampled |
dist_min | An integer value indicating the minimum distance separatingthe sampled points (default = 0). |
edge_size | An integer value indicating the width of the edge of theraster layer which is ignored during the sampling (default = 0). It preventsfrom sampling in the margins of the study area. |
by_patch | A logical value indicating whether contiguous patches withcells having the same code value are delineated prior tosampling (default = TRUE). It prevents from sampling several points in thesame contiguous patch. |
neighborhood | An integer value indicating which cells are consideredadjacent when contiguous patches are delineated (it should be 8(default, Queen's case) or 4 (Rook's case)). This parameter is ignoredwhen |
surf_min | An integer value indicating the minimum surface of a patchconsidered for the sampling in number of raster cells. This parameter is usedwhatever the |
prop_area | A logical value indicating whether sampling in large patchesis more likely (default = TRUE). If |
step_max | An integer value indicating how many sampling steps areperformed to identify a point set satisfying all the conditions beforereturning an error. |
output | A character string indicating the type of returned output:
|
desc | A logical value indicating whether the result should bedescribed or not (default = FALSE). If |
Value
A list of object(s) with one or several elements according to theoutput anddesc arguments.
Author(s)
P. Savary
Scaling function
Description
Scales values between 0 and 1
Usage
sc01(x)Arguments
x | Numeric or integer vector |
Examples
x <- runif(min = 3, max = 15, n = 20)x01 <- sc01(x)Plot scatterplots of genetic distance vs landscape distance
Description
The function enables to plot scatterplots to visualize therelationship between genetic distance (or differentiation) and landscapedistance (Euclidean distance, cost-distance, etc.)between populations orsample sites.
Usage
scatter_dist( mat_gd, mat_ld, method = "loess", thr_gd = NULL, thr_ld = NULL, se = TRUE, smooth_col = "black", pts_col = "#999999")Arguments
mat_gd | A symmetric |
mat_ld | A symmetric |
method | A character string indicating the smoothing methodused to fit a line on the scatterplot. Possible values are the same aswith function 'geom_smooth()' fromggplot2 : 'lm', 'glm', 'gam','loess' (default). |
thr_gd | (optional) A numeric or integer value used to remove valuesfrom the data before to plot. All genetic distances values above |
thr_ld | (optional) A numeric or integer value used to remove valuesfrom the data before to plot. All landscape distances values above |
se | Logical (optional, default = TRUE) indicating whether theconfidence interval around the smooth line is displayed. |
smooth_col | (optional) A character string indicating the colorused to plot the smoothing line (default: "blue"). It must be a hexadecimalcolor code or a color used by default in R. |
pts_col | (optional) Character string indicating the colorused to plot the points (default: "#999999"). It must be a hexadecimal colorcode or a color used by default in R. |
Details
IDs inmat_gd andmat_ld must be the same and referto the same sampling sites or populations, and both matrices must be orderedin the same way.Matrix of genetic distancemat_gd can be computed usingmat_gen_dist.Matrix of landscape distancemat_ld can be computed usingmat_geo_dist when the landscape distance needed is aEuclidean geographical distance.
Value
A ggplot2 object to plot
Author(s)
P. Savary
Examples
data(data_tuto)mat_dps <- data_tuto[[1]]mat_dist <- suppressWarnings(mat_geo_dist(data = pts_pop_simul, ID = "ID", x = "x", y = "y"))mat_dist <- mat_dist[order(as.character(row.names(mat_dist))), order(as.character(colnames(mat_dist)))]scatterplot_ex <- scatter_dist(mat_gd = mat_dps, mat_ld = mat_dist)Plot scatterplots of distances to visualize the graph pruning intensity
Description
The function enables to plot scatterplots of the relationshipbetween two distances (often a genetic distance and a landscape distancebetween populations or sample sites), while highlighting the population pairsbetween which a link was conserved during the creation of a graph whosenodes are populations (or sample sites). It thereby allows to visualize thegraph pruning intensity.
Usage
scatter_dist_g( mat_y, mat_x, graph, thr_y = NULL, thr_x = NULL, pts_col_1 = "#999999", pts_col_2 = "black")Arguments
mat_y | A symmetric (complete) |
mat_x | A symmetric (complete) |
graph | A graph object of class |
thr_y | (optional) A numeric or integer value used to remove valuesfrom the data before to plot. All values from |
thr_x | (optional) A numeric or integer value used to remove valuesfrom the data before to plot. All values from |
pts_col_1 | (optional) A character string indicating the color used toplot the points associated to all populations or sample sitespairs (default: "#999999"). It must be a hexadecimal colorcode or a color used by default in R. |
pts_col_2 | (optional) A character string indicating the color used toplot the points associated to populations or sample sites pairs connected onthe graph (default: "black"). It must be a hexadecimal colorcode or a color used by default in R. |
Details
IDs inmat_y andmat_x must be the same and referto the same sampling sites or populations, and both matrices must be orderedin the same way.Matrices of genetic distance can be computed usingmat_gen_dist.Matrices of landscape distance can be computed usingmat_geo_dist when the landscape distance needed is aEuclidean geographical distance.This function is based uponscatter_dist function.
Value
A ggplot2 object to plot
Author(s)
P. Savary
Examples
data(data_tuto)mat_gen <- data_tuto[[1]]mat_dist <- suppressWarnings(mat_geo_dist(data=pts_pop_simul, ID = "ID", x = "x", y = "y"))mat_dist <- mat_dist[order(as.character(row.names(mat_dist))), order(as.character(colnames(mat_dist)))]x <- gen_graph_topo(mat_w = mat_gen, mat_topo = mat_dist, topo = "gabriel")scat <- scatter_dist_g(mat_y = mat_gen, mat_x = mat_dist, graph = x)Convert a file in STRUCTURE format into a genind object
Description
The function converts a text file in STRUCTURE format intoa genind object to use in R
Usage
structure_to_genind( path, pop_names = NULL, loci_names = NULL, ind_names = NULL)Arguments
path | A character string indicating the path to the STRUCTURE file informat .txt, or alternatively the name of the file in the working directory.The STRUCTURE file must only have :
The row for loci names is optional but recommended.Each individual is displayed on 2 rows. |
pop_names | (optional) A character vector indicating the populationnames in the same order as in the STRUCTURE file. It is of the same lengthas the number of populations. Without this argument, populations arenumbered from 1 to the total number of individuals. |
loci_names | A character vector with the names of the loci if notspecified in the file first row. This argument is mandatory if theSTRUCTURE file does not include the names of the loci in the first row.In other cases, the names of the loci is extracted from the file first row |
ind_names | (optional) A character vector indicating the individualnames in the same order as in the STRUCTURE file. It is of the same lengthas the number of individuals. Without this argument, individuals arenumbered from 1 to the total number of individuals. |
Details
The column order of the resulting object can be different fromthat of objects returned bygstud_to_genindandgenepop_to_genind, depending on allele and loci codingThis function uses functions frompegas package.For details about STRUCTURE file format :STRUCTURE user manual
Value
An object of typegenind.
Author(s)
P. Savary
Examples
data("data_ex_genind")loci_names <- levels(data_ex_genind@loc.fac)pop_names <- levels(data_ex_genind@pop)ind_names <- row.names(data_ex_genind@tab)path_in <- system.file('extdata', 'data_ex_str.txt', package = 'graph4lg')file_n <- file.path(tempdir(), "data_ex_str.txt")file.copy(path_in, file_n, overwrite = TRUE)str <- structure_to_genind(path = file_n, loci_names = loci_names, pop_names = pop_names, ind_names = ind_names)file.remove(file_n)