Learn R Programming

genetics (version 1.3.8.1.3)

order.genotype: Order/sort genotype/haplotype object

Description

Order/sort genotype or haplotype object according to order of allele names or genotypes

Usage

# S3 method for genotype
order(..., na.last=TRUE, decreasing=FALSE,
  alleleOrder=allele.names(x), genotypeOrder=NULL)

# S3 method for genotype sort(x, decreasing=FALSE, na.last=NA, ..., alleleOrder=allele.names(x), genotypeOrder=NULL)

genotypeOrder(x) genotypeOrder(x) <- value

Arguments

genotype or haplotype in order method; not used for sort method

x

genotype or haplotype in sort method

na.last

as in default order or sort

decreasing

as in default order or sort

alleleOrder

character, vector of allele names in wanted order

genotypeOrder

character, vector of genotype/haplotype names in wanted order

value

the same as in argument order.genotype

Value

The same as in order or sort

Details

Argument genotypeOrder can be usefull, when you want that some genotypes appear "together", whereas they are not "together" by allele order.

Both methods (order and sort) work with genotype and haplotype classes.

If alleleOrder is given, genotypeOrder has no effect.

Genotypes/haplotypes, with missing alleles in alleleOrder are treated as NA and ordered according to order arguments related to NA values. In such cases a warning is issued ("Found data values not matching specified alleles. Converting to NA.") and can be safely ignored. Genotypes present in x, but not specified in genotypeOrder, are also treated as NA.

Value of genotypeOrder such as "B/A" matches also "A/B" in case of genotypes.

Only unique values in argument alleleOrder or genotypeOrder are used i.e. first occurrence prevails.

See Also

genotype, allele.names, order, and sort

Examples

Run this code
# NOT RUN {
  x <- c("C/C", "A/C", "A/A", NA, "C/B", "B/A", "B/B", "B/C", "A/C")
  alleles <- c("A", "B", "C")

  g <- genotype(x, alleles=alleles, reorder="yes")
  ## "C/C" "A/C" "A/A" NA    "B/C" "A/B" "B/B" "B/C" "A/C"

  h <- haplotype(x, alleles=alleles)
  ## "C/C" "A/C" "A/A" NA    "C/B" "B/A" "B/B" "B/C" "A/C"

  ## --- Standard usage ---

  sort(g)
  ## "A/A" "A/B" "A/C" "A/C" "B/B" "B/C" "B/C" "C/C" NA

  sort(h)
  ## "A/A" "A/C" "A/C" "B/A" "B/B" "B/C" "C/B" "C/C" NA

  ## --- Reversed order of alleles ---

  sort(g, alleleOrder=c("B", "C", "A"))
  ## "B/B" "B/C" "B/C" "A/B" "C/C" "A/C" "A/C" "A/A" NA
  ## note that A/B comes after B/C since it is treated as B/A;
  ## order of alleles (not in alleleOrder!) does not matter for a genotype

  sort(h, alleleOrder=c("B", "C", "A"))
  ## "B/B" "B/C" "B/A" "C/B" "C/C" "A/C" "A/C" "A/A" NA

  ## --- Missing allele(s) in alleleOrder ---

  sort(g, alleleOrder=c("B", "C"))
  ## "B/B" "B/C" "B/C" "C/C" "A/C" "A/A" NA    "A/B" "A/C"

  sort(g, alleleOrder=c("B"))
  ## "B/B" "C/C" "A/C" "A/A" NA    "B/C" "A/B" "B/C" "A/C"
  ## genotypes with missing allele are treated as NA

  sort(h, alleleOrder=c("B", "C"))
  ## "B/B" "B/C" "C/B" "C/C" "A/C" "A/A" NA    "B/A" "A/C"

  sort(h, alleleOrder=c("B"))
  ## "B/B" "C/C" "A/C" "A/A" NA    "C/B" "B/A" "B/C" "A/C"

  ## --- Use of genotypeOrder ---

  sort(g, genotypeOrder=c("A/A", "C/C", "B/B", "A/B", "A/C", "B/C"))
  ## "A/A" "C/C" "B/B" "A/B" "A/C" "A/C" "B/C" "B/C" NA

  sort(h, genotypeOrder=c("A/A", "C/C", "B/B",
                          "A/C", "C/B", "B/A", "B/C"))
  ## "A/A" "C/C" "B/B" "A/C" "A/C" "C/B" "B/A" "B/C" NA

  ## --- Missing genotype(s) in genotypeOrder ---

  sort(g, genotypeOrder=c(       "C/C",        "A/B", "A/C", "B/C"))
  ## "C/C" "A/B" "A/C" "A/C" "B/C" "B/C" "A/A" NA    "B/B"

  sort(h, genotypeOrder=c(       "C/C",        "A/B", "A/C", "B/C"))
  ## "C/C" "A/C" "A/C" "B/C" "A/A" NA    "C/B" "B/A" "B/B"
# }

Run the code above in your browser using DataLab