order.genotype: Order/sort genotype/haplotype object

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

View source: R/order.genotype.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## S3 method for class 'genotype'
order(..., na.last=TRUE, decreasing=FALSE,
  alleleOrder=allele.names(x), genotypeOrder=NULL)

## S3 method for class '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

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.

Value

The same as in order or sort

Author(s)

Gregor Gorjanc

See Also

genotype, allele.names, order, and sort

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  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"

Example output

Loading required package: combinat

Attaching package: 'combinat'

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

    combn

Loading required package: gdata
sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to locate valid perl interpreter
gdata: 
gdata: read.xls() will be unable to read Excel XLS and XLSX files
gdata: unless the 'perl=' argument is used to specify the location of a
gdata: valid perl intrpreter.
gdata: 
gdata: (To avoid display of this message in the future, please ensure
gdata: perl is installed and available on the executable search path.)
sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLX' (Excel 97-2004) files.

gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLSX' (Excel 2007+) files.

gdata: Run the function 'installXLSXsupport()'
gdata: to automatically download and install the perl
gdata: libaries needed to support Excel XLS and XLSX formats.

Attaching package: 'gdata'

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

    nobs

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

    object.size

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

    startsWith

Loading required package: gtools
Loading required package: MASS
Loading required package: mvtnorm


NOTE: THIS PACKAGE IS NOW OBSOLETE.



  The R-Genetics project has developed an set of enhanced genetics

  packages to replace 'genetics'. Please visit the project homepage

  at http://rgenetics.org for informtion.




Attaching package: 'genetics'

The following objects are masked from 'package:base':

    %in%, as.factor, order

[1] "A/A" "A/B" "A/C" "A/C" "B/B" "B/C" "B/C" "C/C" NA   
Alleles: A B C 
[1] "A/A" "A/C" "A/C" "B/A" "B/B" "B/C" "C/B" "C/C" NA   
Alleles: A B C 
[1] "B/B" "B/C" "B/C" "A/B" "C/C" "A/C" "A/C" "A/A" NA   
Alleles: A B C 
[1] "B/B" "B/C" "B/A" "C/B" "C/C" "A/C" "A/C" "A/A" NA   
Alleles: A B C 
[1] "B/B" "B/C" "B/C" "C/C" "A/C" "A/A" NA    "A/B" "A/C"
Alleles: A B C 
Warning message:
In genotype(x, alleles = alleleOrder, reorder = reorder) :
  Found data values not matching specified alleles. Converting to NA.
[1] "B/B" "C/C" "A/C" "A/A" NA    "B/C" "A/B" "B/C" "A/C"
Alleles: A B C 
Warning message:
In genotype(x, alleles = alleleOrder, reorder = reorder) :
  Found data values not matching specified alleles. Converting to NA.
[1] "B/B" "B/C" "C/B" "C/C" "A/C" "A/A" NA    "B/A" "A/C"
Alleles: A B C 
Warning message:
In genotype(x, alleles = alleleOrder, reorder = reorder) :
  Found data values not matching specified alleles. Converting to NA.
[1] "B/B" "C/C" "A/C" "A/A" NA    "C/B" "B/A" "B/C" "A/C"
Alleles: A B C 
Warning message:
In genotype(x, alleles = alleleOrder, reorder = reorder) :
  Found data values not matching specified alleles. Converting to NA.
[1] "A/A" "C/C" "B/B" "A/B" "A/C" "A/C" "B/C" "B/C" NA   
Alleles: A B C 
[1] "A/A" "C/C" "B/B" "A/C" "A/C" "C/B" "B/A" "B/C" NA   
Alleles: A B C 
[1] "C/C" "A/B" "A/C" "A/C" "B/C" "B/C" "A/A" NA    "B/B"
Alleles: A B C 
[1] "C/C" "A/C" "A/C" "B/C" "A/A" NA    "C/B" "B/A" "B/B"
Alleles: A B C 

genetics documentation built on March 1, 2021, 9:06 a.m.