Genetic diversity
Genetic diversity is provided by two lightweight extensions, so you only load what your data needs:
- sequences — load
BioSequences(using Diversity, BioSequences) to build aGeneticTypefrom a vector of alignedBioSequences; - VCF — load
PopGen(using Diversity, PopGen) to build aGeneticTypefrom aPopGen.PopDataobject read from a VCF file.
Similarity between types is derived from pairwise genetic distances, mirroring the gen2dist() / dist2sim() pipeline in the R package rdiversity.
Usage
Using the functionality in the package is simple:
- Create genetic data, either a vector of aligned
BioSequences or aPopGen.PopDataobject (e.g. read from a VCF file withPopGen.vcf) - Create a
GeneticType(anAbstractTypessubtype) from it - Create a
Metacommunityfrom that - Calculate diversity!
Sequences
julia> using Diversity, BioSequencesjulia> seqs = [dna"ACGTACGT", dna"ACGAACGT", dna"TTTTTTTT"]3-element Vector{BioSequences.LongSequence{BioSequences.DNAAlphabet{4}}}: ACGTACGT ACGAACGT TTTTTTTTjulia> gt = GeneticType(seqs; names = ["a", "b", "c"])DiversityBioSequencesExt.GeneticFASTA{Vector{BioSequences.LongSequence{BioSequences.DNAAlphabet{4}}}}(BioSequences.LongSequence{BioSequences.DNAAlphabet{4}}[ACGTACGT, ACGAACGT, TTTTTTTT], ["a", "b", "c"], 3, [1.0 0.8571428571428572 0.1428571428571429; 0.8571428571428572 1.0 0.0; 0.1428571428571429 0.0 1.0])julia> calcsimilarity(gt, 1.0)3×3 Matrix{Float64}: 1.0 0.857143 0.142857 0.857143 1.0 0.0 0.142857 0.0 1.0julia> metagen = Metacommunity([0.3, 0.3, 0.4], gt)Metacommunity{Float64, Vector{Float64}, Matrix{Float64}, DiversityBioSequencesExt.GeneticFASTA{Vector{BioSequences.LongSequence{BioSequences.DNAAlphabet{4}}}}, Onecommunity} with 3 species in 1 subcommunity measuring Genetic (sequence) diversity. Species names: a, b, c Subcommunity names: 1julia> meta_gamma(metagen, 0)1×8 DataFrame Row │ div_type measure q type_level type_name partition_le ⋯ │ String String Int64 String String String ⋯ ─────┼────────────────────────────────────────────────────────────────────────── 1 │ Genetic (sequence) Gamma 0 types metacommunit ⋯ 3 columns omitted
Sequences a and b differ at one site out of eight and are correspondingly similar; both are far from c, which shares no site with either. The metacommunity therefore holds rather less than three types' worth of diversity.
VCF
The example below reads the small biallelic VCF that ships with the package, and builds a similarity matrix using biallelic Manhattan distances — matching rdiversity's gen2dist(vcf, biallelic = TRUE):
julia> using Diversity, PopGenjulia> pd = PopGen.vcf(Diversity.path("data", "biallelic.vcf"); silent = true)PopData{Diploid, 3 SNP loci} Samples: 3 Populations: 1julia> gt = GeneticType(pd; distance = :manhattan)DiversityPopGenExt.GeneticVCF{PopGenCore.PopData}(PopData{Diploid, 3 SNP loci} Samples: 3 Populations: 1, ["s1", "s2", "s3"], 3, [1.0 0.0 0.25; 0.0 1.0 0.25; 0.25 0.25 1.0])julia> gettypenames(gt, true)3-element Vector{String}: "s1" "s2" "s3"julia> calcsimilarity(gt, 1.0)3×3 Matrix{Float64}: 1.0 0.0 0.25 0.0 1.0 0.25 0.25 0.25 1.0julia> metagen = Metacommunity([0.2 0.1; 0.1 0.3; 0.2 0.1], gt)Metacommunity{Float64, Matrix{Float64}, Matrix{Float64}, DiversityPopGenExt.GeneticVCF{PopGenCore.PopData}, Subcommunities} with 3 species in 2 subcommunities measuring Genetic (VCF) diversity. Species names: s1, s2, s3 Subcommunity names: 1, 2julia> meta_gamma(metagen, 0)1×8 DataFrame Row │ div_type measure q type_level type_name partition_level ⋯ │ String String Int64 String String String ⋯ ─────┼────────────────────────────────────────────────────────────────────────── 1 │ Genetic (VCF) Gamma 0 types metacommunity ⋯ 2 columns omitted
Here the samples are the types, so a metacommunity is a matrix of sample abundances with one column per subcommunity.
The distance (:manhattan or :hamming), transform (:linear or :exponential), k and normalise keyword arguments control how the pairwise distances and the resulting similarity matrix are calculated.
vcf_dataframe(pd) converts a PopData back into the VCF-body layout that rdiversity's gen2dist() consumes, so the same data can drive both the Julia and the R calculation — which is how the two are cross-validated against each other in test/run_rcall.jl.
- Diversity.API
- Diversity.Ecology
- The framework
- Genetic diversity
- Diversity.Hill
- Diversity.jl
- Diversity.Jost
- Building a metacommunity
- Phylogenetic diversity
- Coming from vegan
Diversity.APIDiversity.DiversityDiversity.EcologyDiversity.HillDiversity.JostDiversity.ShortNamesDiversity.individualDiversityDiversity.metacommunityDiversityDiversity.subcommunityDiversityDiversity.API.AbstractMetacommunityDiversity.API.AbstractPartitionDiversity.API.AbstractTypesDiversity.AbstractGeneticDiversity.AbstractPhyloTypesDiversity.DiversityLevelDiversity.DiversityMeasureDiversity.GammaDiversity.GeneralTypesDiversity.GeneralTypesDiversity.MetacommunityDiversity.NormalisedAlphaDiversity.NormalisedBetaDiversity.NormalisedRhoDiversity.OnecommunityDiversity.PhyloBranchesDiversity.PowerMeanMeasureDiversity.RawAlphaDiversity.RawBetaDiversity.RawRhoDiversity.RelativeEntropyMeasureDiversity.SpeciesDiversity.SubAssemblageDiversity.SubcommunitiesDiversity.TaxonomyDiversity.UniqueTypesDiversity.API._addedoutputcolsDiversity.API._calcabundanceDiversity.API._calcordinarinessDiversity.API._calcsimilarityDiversity.API._countsubcommunitiesDiversity.API._counttypesDiversity.API._getabundanceDiversity.API._getaddedoutputDiversity.API._getdiversitynameDiversity.API._getmetaabundanceDiversity.API._getmetaordinariness!Diversity.API._getordinariness!Diversity.API._getpartitionDiversity.API._getscaleDiversity.API._getsubcommunitynamesDiversity.API._gettypenamesDiversity.API._gettypesDiversity.API._getweightDiversity.API._subsetpartitionDiversity.API._subsettypesDiversity.API.floattypesDiversity.API.mcmatchDiversity.API.typematchDiversity.Ecology.faith_pdDiversity.Ecology.generalisedfaith_pdDiversity.Ecology.generalisedjaccardDiversity.Ecology.generalisedrichnessDiversity.Ecology.generalisedshannonDiversity.Ecology.generalisedsimpsonDiversity.Ecology.gowerDiversity.Ecology.jaccardDiversity.Ecology.pielouDiversity.Ecology.richnessDiversity.Ecology.shannonDiversity.Ecology.simpsonDiversity.GeneticTypeDiversity.Hill.hillnumberDiversity.Jost.jostalphaDiversity.Jost.jostbetaDiversity._getmetaDiversity.addedoutputcolsDiversity.calcsimilarityDiversity.countsubcommunitiesDiversity.counttypesDiversity.diversityDiversity.getASCIINameDiversity.getFullNameDiversity.getNameDiversity.getabundanceDiversity.getaddedoutputDiversity.getdiversitynameDiversity.getmetaabundanceDiversity.getmetaordinariness!Diversity.getordinariness!Diversity.getpartitionDiversity.getsubcommunitynamesDiversity.gettypenamesDiversity.gettypesDiversity.getweightDiversity.hassimilarityDiversity.inddivDiversity.meta_gammaDiversity.metadivDiversity.norm_meta_alphaDiversity.norm_meta_betaDiversity.norm_meta_rhoDiversity.norm_sub_alphaDiversity.norm_sub_betaDiversity.norm_sub_rhoDiversity.powermeanDiversity.qDDiversity.qDZDiversity.raw_meta_alphaDiversity.raw_meta_betaDiversity.raw_meta_rhoDiversity.raw_sub_alphaDiversity.raw_sub_betaDiversity.raw_sub_rhoDiversity.sub_gammaDiversity.subdivDiversity.vcf_dataframe