Learn R Programming

paramlink (version 1.1-0)

markers: Marker functions

Description

Functions for setting and manipulating marker genotypes for 'linkdat' objects.

Usage

marker(x, ..., allelematrix, alleles=NULL, afreq=NULL, missing=0,
       chrom=NA, pos=NA, name=NA, mutmat=NULL)

addMarker(x, m, ...)

setMarkers(x, m, annotations=NULL, missing=0)

getMarkers(x, markernames=NULL, chroms=NULL, fromPos=NULL, toPos=NULL)

removeMarkers(x, markers, markernames=NULL, chroms=NULL, from=NULL, to=NULL)

modifyMarker(x, marker, ids, genotype, alleles, afreq, chrom, name, pos)

modifyMarkerMatrix(x, ids, new.alleles)

swapGenotypes(x, ids)

transferMarkerdata(from, to)

mendelianCheck(x, remove=FALSE, verbose=!remove)

Arguments

x

a linkdat object

...

an even number of vectors, indicating individuals and their genotypes. See examples.

allelematrix

a matrix with one row per pedigree member and two columns per marker, containing the alleles for a single marker.

m

a marker object or a matrix with alleles. (In setMarkers this matrix can contain data of several markers.)

missing

a numeric - or character - of length 1, indicating the code for missing alleles.

chrom

NA or an integer (the chromosome number of the marker).

pos

NA or a non-negative real number indicating the genetic position (in cM) of the marker.

name

NA or a character (the name of the marker).

mutmat

a mutation matrix, or a list of two such matrices named "female" and "male". The matrix/matrices must be square, with the allele labels as dimnames, and each row must sum to 1 (after rounding to 3 decimals).

annotations

a list of marker annotations.

markernames

NULL or a character vector.

chroms

NULL or a numeric vector of chromosome numbers.

fromPos, toPos

NULL or a single numeric.

marker, markers

a numeric indicating which marker(s) to use/modify.

ids

a numeric indicating individual(s) to be modified. In swapGenotypes this must have length 2.

genotype

a vector of length 1 or 2, containing the genotype to be given the ids individuals. See examples.

alleles

a numeric or character vector containing allele names.

afreq

a numerical vector with allele frequencies. An error is given if they don't sum to 1 (rounded to 3 decimals).

new.alleles

a numerical matrix of dimensions length(ids), 2*x$nMark. Entries refer to the internal allele numbering.

from, to

linkdat objects, or list of linkdat objects.

remove

a logical. If FALSE, the function returns the indices of markers found to incorrect. If TRUE, a new linkdat object is returned, where the incorrect markers have been deleted.

verbose

a logical. If TRUE, details of the markers failing the tests are shown.

Value

The marker function returns an object of class marker: This is a numerical 2-column matrix with one row per individual, and attributes 'alleles' (a character vector with allele names), 'nalleles' (the number of alleles) and 'missing' (the input symbol for missing marker alleles), 'chrom' (chromosome number), 'name' (marker identifier), 'pos' (chromosome position in cM).

For addMarker, setMarkers, removeMarkers, modifyMarker, modifyMarkerMatrix and swapGenotypes, a linkdat object is returned, whose markerdata element has been set/modified.

For getMarkers a numeric vector containing marker numbers (i.e. their indices in x$markerdata) for the markers whose "name" attribute is contained in markernames, "chrom" attribute is contained in chroms, and "pos" attribute is between from and to. NULL arguments are skipped, so getMarkers(x) will return seq_len(x$nMark) (i.e. all markers).

For transferMarkerdata, a linkdat object (or a list of such) similar to to, but where all individuals also present in from have marker genotypes copied over. Any previous marker data is erased.

For mendelianCheck, a numeric containing the indices of the markers that did not pass the tests, or (if remove=TRUE) a new linkdat object where the failing markers are removed.

See Also

linkdat

Examples

Run this code
# NOT RUN {
x = linkdat(toyped)
x = removeMarkers(x,1) # removing the only marker of x.
x

# Creating a SNP with alleles 'a' and 'b', for which individual 1 is heterozygous, 
# 2 and 4 are homozygous for the 'b' allele, and missing genotype for individual 3:
m1 = marker(x, 1, c('a','b'), c(2,4), c('b','b')) 
x = addMarker(x, m1)

# A rare SNP for which all individuals are homozygous for the common allele.
# The 'alleles' argument must be specified since only one allele is present.
m2 = marker(x, 1:4, 1, alleles=1:2, afreq=c(0.99, 0.01))
x = addMarker(x, m2)

# Creating a Mendelian error in the first marker
x = modifyMarker(x, marker=1, ids=3, genotype='a') 

# Making the second marker triallelic, with heterozygous parents.
x = modifyMarker(x, marker=2, ids=1:2, genotype=1:2, alleles=1:3)

# Testing mendelianCheck
err_index = mendelianCheck(x, remove=FALSE)
stopifnot(err_index==1)

xnew = mendelianCheck(x, remove=TRUE)
stopifnot(all.equal(xnew, removeMarkers(x, 1)))

### Testing transferMarkerdata
x0 = list(singleton(id=5), nuclearPed(noffs=2))
x = markerSim(x0, N=5, alleles=1:5, verbose=FALSE, available=4:5)
y0 = nuclearPed(noffs=3)
y = transferMarkerdata(x, y0)
stopifnot(all.equal(x[[1]], branch(y,5)))
stopifnot(all.equal(x[[2]], subset(y,1:4)))
# }

Run the code above in your browser using DataLab