The scripts hosted here have been migrated to the git repo: The following geneticsrelated R functions were primarily written for my own research. However, (I'd like to think) I've written them to be generic enough to be useful to others. Please feel free to download, use, and modify as you please with the understanding that they are released under the GNU GPL. Please drop me an email if you spot a bug or have ideas for improvement. Statistical FunctionsPlotting Functions Example Data geno_to_allelecnt.R A
function to convert biallelic unphased SNP genotypes, such
as {AA,CC,GG,TT,AC,AG,AT,CG,CT,GT}, to number of
copies/counts {0,1,2} of the reference (or arbitrary)
allele.
simgeno.R[See example II and simgeno.R for example and usage.] Very
simple function to generate a biallelic unphased SNP
genotype matrix in the format
{AA,CC,GG,TT,AC,AG,AT,CG,CT,GT}. Used predominantly to
test geno_to_allelecnt.R.
calc_EHHS.R[See example II for usage and purpose.] A
function to calculate the normalised homozygosity between
the ith and jth loci, EHHS_{(geno)i,j}, for
a given chromosome / linkage group (Tang,
Thornton, Stoneking 2007)
calc_iES.R A
function to calculate the integrated EHHS statistic, iES,
as described in Tang, Thornton and Stoneking (2007). You'd probably want to
calculate the EHHS first!
calc_LD.R Given
a biallelic genotype matrix, calculates one or more
measures of linkage disequilibrium between all
locuspairs. The available LD measures include: D,
D',
r^{2},
X^{2}
(chisquare), X^{2}'
(chisquareprime).
calc_snp_stats.R[See example I for example data and usage.] A
function to calculate basic SNP stats, including: allele
frequency (p), MAF (minor allele frequency), MGF (minor
genotype frequency), and tests for deviation from HWE (X^{2}
test and Fisher's Exact test).
gwas_lm.R[See example I for example data and usage.]
Performs singlelocus (SNP) genomewide association tests
for one or more traits simultaneously under one or more of
five inheritance models (additive, codominance,
dominance, recessive, overdominance) using linear
regression.
calc_hwe_fisher.R A
script to test for deviation from HWE using Fisher's Exact
test. This test is also incorporated into calc_snp_stats.R.
calc_hwe_chisq.R[See example I for example data and usage.] A
script to test for deviation from HWE using Pearson's
ChiSquared test. This test is also incorporated into calc_snp_stats.R.
calc_neiFis_multispop.R[See example I for example data and usage.] A
script to calculate inbreeding coefficients, Fis, for each subpopulation using a
given set of SNP markers.
calc_neiFis_onepop.R[See example I for example data and usage.] A
script to calculate inbreeding coefficients, Fis, for a given population
using a given set of SNP markers.
calc_wcFstats.R[See example I for example data and usage.] A
script to estimate the variance components and fixation
indices as described in Weir & Cockerham 1984 Evolution
38(6) : 13581370.
calc_wcFst_spop_pairs.R[See example I for example data and usage. ] A
script to estimate Fst (theta) values for each pair of
subpopulations using the method of Weir & Cockerham 1984 Evolution
38(6): 13581370.
calc_allele_sharing.R[See example I for example data and usage.]
Calculates allele sharing distances between pairs of
individuals (c.f. Gao & Stramer 2007 BMC Genetics 8:34).
plclust_in_colour.R[See example I for example data and usage.] A modification of (wrapper to) plclust for plotting
hclust
(hierarchical cluster) objects with coloured leaf
labels.
plot_marker_lox.RGenerates
a visual representation of the genetic positions of a set
of markers.
plot_markers_by_set.RA
function to plot sets of markers on a map where the
markers are coloured based on a defined variable.
Example IexampleI.R
Download and read
exampleI.R first. This script contains several very
simple lines of codes for creating a geno and a subpop object, and
their usages in the following scripts:
exampleI_data.RData
calc_wcFstats(geno, subpop) calc_wcFst_spop_pairs(geno, subpop) calc_neiFis_onepop(geno) calc_snp_stats(geno) calc_neiFis_multispop(geno,subpop) calc_LD(geno) calc_allele_sharing(geno) [See NJ tree of using resulting allelesharing distance matrix.] calc_hwe_chisq(geno) calc_hwe_fisher(geno) A R workspace containing
an instance of a geno
and subpop objects
used in exampleI.R; i.e. the actual datasets
corresponding to the outputs in exampleI.R.
exampleI_functions.RData
A R workspace containing
all functions used in exampleI.R.
