haploFreq: Haplotype Frequencies With a Covariate

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/haplotype.R

Description

This utility function extracts the absolute frequencies of haplotypes with respect to a categorical variable (a factor). The output is useful when ploting haplotype networks.

Usage

1
haploFreq(x, fac, split = "_", what = 2, haplo = NULL)

Arguments

x

a set of DNA sequences (as an object of class "DNAbin").

fac

a factor giving the categorical variable (can be missing).

split

a single character (see details).

what

a single integer (see details).

haplo

an object of class "haplotype".

Details

The frequencies of each haplotype in x are counted with respect to a factor which is either specified with fac, or extracted from the labels of x. In the second case, these labels are split with respect to the character specified in split and the what'th substrings are extracted and taken as the categorical variable (see example).

If haplo is specified, the haplotype frequencies are taken from it, otherwise they are calculated from x.

Value

a matrix of counts.

Author(s)

Klaus Schliep and Emmanuel Paradis

See Also

haplotype, haploNet

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## generate some artificial data from 'woodmouse':
data(woodmouse)
x <- woodmouse[sample(15, size = 50, replace = TRUE), ]
## labels IdXXX_PopXXX_LocXXX
rownames(x) <- paste("Id", 1:50, "_Pop", 1:2, "_Loc", 1:5, sep = "")
head(labels(x))
h <- haplotype(x)
## frequencies of haplotypes wrt 'Pop':
f.pop <- haploFreq(x, haplo = h)
## frequencies of haplotypes wrt 'Loc':
f.loc <- haploFreq(x, what = 3, haplo = h)
nt <- haploNet(h)
fq <- attr(nt, "freq")
op <- par(mfcol = c(1, 2))
plot(nt, size = fq, pie = f.pop, labels = FALSE)
plot(nt, size = fq, pie = f.loc, labels = FALSE)
par(op)

Example output

Loading required package: ape
Loading required package: adegenet
Loading required package: ade4

   /// adegenet 2.0.1 is loaded ////////////

   > overview: '?adegenet'
   > tutorials/doc/questions: 'adegenetWeb()' 
   > bug reports/feature requests: adegenetIssues()



Attaching package: 'pegas'

The following object is masked from 'package:ade4':

    amova

The following object is masked from 'package:ape':

    mst

[1] "Id1_Pop1_Loc1" "Id2_Pop2_Loc2" "Id3_Pop1_Loc3" "Id4_Pop2_Loc4"
[5] "Id5_Pop1_Loc5" "Id6_Pop2_Loc1"

pegas documentation built on May 17, 2021, 9:08 a.m.