Bimap-keys {AnnotationDbi} | R Documentation

## Methods for manipulating the keys of a Bimap object

### Description

These methods are part of the Bimap interface (see `?Bimap` for a quick overview of the Bimap objects and their interface).

### Usage

      #length(x)
      isNA(x)
      mappedkeys(x)
      count.mappedkeys(x)
      keys(x) <- value
      #x[i]

### Arguments

`x` | A Bimap object. If the method being caled is `keys(x)`, then x can also be a AnnotationDb object or one of that objects progeny.
`value` | A character vector containing the new keys (must be a subset of the current keys).
`i` | A character vector containing the keys of the map elements to extract.

### Details

`keys(x)` returns the set of all valid keys for map `x`. For example, `keys(hgu95av2GO)` is the set of all probe set IDs for chip hgu95av2 from Affymetrix.

Please Note that in addition to `Bimap` objest, `keys(x)` will also work for `AnnotationDb` objects and related objects such as `OrgDb` and `ChipDb` objects.

Note also that the double bracket operator `[[` for Bimap objects is guaranteed to work only with a valid key and will raise an error if the key is invalid. (See `?`Bimap-envirAPI`` for more information about this operator.)

`length(x)` is equivalent to (but more efficient than) `length(keys(x))`.

A valid key is not necessarily mapped (`[[` will return an `NA` on an unmapped key).

`isNA(x)` returns a logical vector of the same length as `x` where the `TRUE` value is used to mark keys that are NOT mapped and the `FALSE` value to mark keys that ARE mapped.

`mappedkeys(x)` returns the subset of `keys(x)` where only mapped keys were kept.

`count.mappedkeys(x)` is equivalent to (but more efficient than) `length(mappedkeys(x))`.

Two (almost) equivalent forms of subsetting a Bimap object are provided: (1) by setting the keys explicitely and (2) by using the single bracket operator `[` for Bimap objects. Let's say the user wants to restrict the mapping to the subset of valid keys stored in character vector `mykeys`. This can be done either with `keys(x) <- mykeys` (form (1)) or with `y <- x[mykeys]` (form (2)). Please note that form (1) alters object `x` in an irreversible way (the original keys are lost) so form (2) should be preferred.

All the methods described on this pages are "directed methods" i.e. what they return DOES depend on the direction of the Bimap object that they are applied to (see `?direction` for more information about this).

### Value

A character vector for `keys` and `mappedkeys`.

A single non-negative integer for `length` and `count.mappedkeys`.

A logical vector for `isNA`.

A Bimap object of the same subtype as `x` for `x[i]`.

### Author(s)

H. Pagès

### See Also

Bimap, Bimap-envirAPI, Bimap-toTable, BimapFormatting, AnnotationDb, select, columns

### Examples

      library(hgu95av2.db)
      x <- hgu95av2GO
      x
      length(x)
      count.mappedkeys(x)
      x[1:3]
      links(x[1:3])

      ## Keep only the mapped keys
      keys(x) <- mappedkeys(x)
      length(x)
      count.mappedkeys(x)
      x # now it is a submap

      ## The above subsetting can also be achieved with
      x <- hgu95av2GO[mappedkeys(hgu95av2GO)]

      ## mappedkeys() and count.mappedkeys() also work with an environment
      ## or a list
      z <- list(k1=NA, k2=letters[1:4], k3="x")
      mappedkeys(z)
      count.mappedkeys(z)

      ## retrieve the set of primary keys for the ChipDb object named 'hgu95av2.db'
      keys <- keys(hgu95av2.db)
      head(keys)

[Package AnnotationDbi version 1.46.1 Index]