Individuals are assigned to populations based on associated specimen metadata stored in the dartR genlight object.

This script deletes all individuals apart from those in listed populations (pop.list). Monomorphic loci and loci that are scored all NA are optionally deleted (mono.rm=TRUE). The script also optionally recalculates locus metatdata statistics to accommodate the deletion of individuals from the dataset (recalc=TRUE).

The script returns a dartR genlight object with the retained populations and the recalculated locus metadata. The script works with both genlight objects containing SNP genotypes and Tag P/A data (SilicoDArT).

gl.keep.pop(
  x,
  pop.list,
  as.pop = NULL,
  recalc = FALSE,
  mono.rm = FALSE,
  verbose = NULL
)

Arguments

x

Name of the genlight object [required].

pop.list

List of populations to be retained [required].

as.pop

Temporarily assign another locus metric as the population for the purposes of deletions [default NULL].

recalc

If TRUE, recalculate the locus metadata statistics [default FALSE].

mono.rm

If TRUE, remove monomorphic and all NA loci [default FALSE].

verbose

Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress but not results; 3, progress and results summary; 5, full report [default 2 or as specified using gl.set.verbosity].

Value

A reduced dartR genlight object

See also

gl.drop.pop to drop rather than keep specified populations

Author

Custodian: Arthur Georges – Post to https://groups.google.com/d/forum/dartr

Examples

 # SNP data
   gl2 <- gl.keep.pop(testset.gl, pop.list=c('EmsubRopeMata', 'EmvicVictJasp'))
#> Starting gl.keep.pop 
#>   Processing genlight object with SNP data
#>   Checking for presence of nominated populations
#>   Retaining only populations EmsubRopeMata, EmvicVictJasp 
#>   Warning: Resultant dataset may contain monomorphic loci
#>   Locus metrics not recalculated
#> Completed: gl.keep.pop 
#> 
   gl2 <- gl.keep.pop(testset.gl, pop.list=c('EmsubRopeMata', 'EmvicVictJasp'),
   mono.rm=TRUE,recalc=TRUE)
#> Starting gl.keep.pop 
#>   Processing genlight object with SNP data
#>   Checking for presence of nominated populations
#>   Retaining only populations EmsubRopeMata, EmvicVictJasp 
#>   Deleting monomorphic loc
#>   Recalculating locus metrics
#> Completed: gl.keep.pop 
#> 
   gl2 <- gl.keep.pop(testset.gl, pop.list=c('Female'),as.pop='sex')
#> Starting gl.keep.pop 
#>   Processing genlight object with SNP data
#>   Temporarily setting population assignments to sex as specified by the as.pop parameter
#>   Checking for presence of nominated populations
#>   Retaining only populations Female 
#>   Warning: Resultant dataset may contain monomorphic loci
#>   Locus metrics not recalculated
#>   Resetting population assignments to initial state
#> Completed: gl.keep.pop 
#> 
 # Tag P/A data
   gs2 <- gl.keep.pop(testset.gs, pop.list=c('EmsubRopeMata','EmvicVictJasp'))
#> Starting gl.keep.pop 
#>   Processing genlight object with Presence/Absence (SilicoDArT) data
#>   Checking for presence of nominated populations
#>   Retaining only populations EmsubRopeMata, EmvicVictJasp 
#>   Locus metrics not recalculated
#> Completed: gl.keep.pop 
#>