R: Methods for manipulating a Bimap object in a data-frame style
Bimap-toTable
R Documentation
Methods for manipulating a Bimap object in a data-frame style
Description
These methods are part of the Bimap interface
(see ?Bimap for a quick overview of the Bimap
objects and their interface).
Usage
## Extract all the columns of the map (links + right attributes)
toTable(x)
nrow(x)
ncol(x)
#dim(x)
## S4 method for signature 'FlatBimap'
head(x, ...)
## S4 method for signature 'FlatBimap'
tail(x, ...)
## Extract only the links of the map
links(x)
count.links(x)
nhit(x)
## Col names and col metanames
colnames(x, do.NULL=TRUE, prefix="col")
colmetanames(x)
Lkeyname(x)
Rkeyname(x)
keyname(x)
tagname(x)
Rattribnames(x)
Rattribnames(x) <- value
Arguments
x
A Bimap object (or a list or an environment for nhit).
...
Further arguments to be passed to or from other methods (see
head or tail
for the details).
do.NULL
Ignored.
prefix
Ignored.
value
A character vector containing the names of the new right attributes
(must be a subset of the current right attribute names)
or NULL.
Details
toTable(x) turns Bimap object x into a
data frame (see section "Flat representation of a bimap" in
?Bimap for a short introduction to this concept).
For simple maps (i.e. no tags and no right attributes),
the resulting data frame has only 2 columns, one for the left
keys and one for the right keys, and each row in the data frame
represents a link (or edge) between a left and a right key.
For maps with tagged links (i.e. a tag is associated to each
link), toTable(x) has one additional colmun for the tags
and there is still one row per link.
For maps with right attributes (i.e. a set of attributes is
associated to each right key), toTable(x) has one
additional colmun per attribute. So for example if x has
tagged links and 2 right attributes, toTable(x) will
have 5 columns: one for the left keys, one for the right keys,
one for the tags, and one for each right attribute (always the
rightmost columns).
Note that if at least one of the right attributes is multivalued
then more than 1 row can be needed to represent the same link
so the number of rows in toTable(x) can be strictly
greater than the number of links in the map.
nrow(x) is equivalent to (but more efficient than)
nrow(toTable(x)).
ncol(x) is equivalent to (but more efficient than)
ncol(toTable(x)).
colnames(x) is equivalent to (but more efficient than)
colnames(toTable(x)). Columns are named accordingly to
the names of the SQL columns where the data are coming from.
An important consequence of this that they are not necessarily
unique.
colmetanames(x) returns the metanames for the column of
x that are not right attributes. Valid column metanames
are "Lkeyname", "Rkeyname" and "tagname".
Lkeyname, Rkeyname, tagname and
Rattribnames return the name of the column (or columns)
containing the left keys, the right keys, the tags and the right
attributes, respectively.
Like toTable(x), links(x) turns x into a
data frame but the right attributes (if any) are dropped.
Note that dropping the right attributes produces a data frame
that has eventually less columns than toTable(x)
and also eventually less rows because now exactly 1 row is
needed to represent 1 link.
count.links(x) is equivalent to (but more efficient than)
nrow(links(x)).
nhit(x) returns a named integer vector indicating the
number of "hits" for each key in x i.e. the number of links
that start from each key.
Value
A data frame for toTable and links.
A single integer for nrow, ncol and count.links.
A character vector for colnames, colmetanames
and Rattribnames.
A character string for Lkeyname, Rkeyname
and tagname.
A named integer vector for nhit.
Author(s)
H. Pages
See Also
Bimap,
BimapFormatting,
Bimap-envirAPI
Examples
library(GO.db)
x <- GOSYNONYM
x
toTable(x)[1:4, ]
toTable(x["GO:0007322"])
links(x)[1:4, ]
links(x["GO:0007322"])
nrow(x)
ncol(x)
dim(x)
colnames(x)
colmetanames(x)
Lkeyname(x)
Rkeyname(x)
tagname(x)
Rattribnames(x)
links(x)[1:4, ]
count.links(x)
y <- GOBPCHILDREN
nhy <- nhit(y) # 'nhy' is a named integer vector
identical(names(nhy), keys(y)) # TRUE
table(nhy)
sum(nhy == 0) # number of GO IDs with no children
names(nhy)[nhy == max(nhy)] # the GO ID(s) with the most direct children
## Some sanity check
sum(nhy) == count.links(y) # TRUE
## Changing the right attributes of the GOSYNONYM map (advanced
## users only)
class(x) # GOTermsAnnDbBimap
as.list(x)[1:3]
colnames(x)
colmetanames(x)
tagname(x) # untagged map
Rattribnames(x)
Rattribnames(x) <- Rattribnames(x)[3:1]
colnames(x)
class(x) # AnnDbBimap
as.list(x)[1:3]
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(AnnotationDbi)
Loading required package: stats4
Loading required package: BiocGenerics
Loading required package: parallel
Attaching package: 'BiocGenerics'
The following objects are masked from 'package:parallel':
clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, parApply, parCapply, parLapply,
parLapplyLB, parRapply, parSapply, parSapplyLB
The following objects are masked from 'package:stats':
IQR, mad, xtabs
The following objects are masked from 'package:base':
Filter, Find, Map, Position, Reduce, anyDuplicated, append,
as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
rbind, rownames, sapply, setdiff, sort, table, tapply, union,
unique, unsplit
Loading required package: Biobase
Welcome to Bioconductor
Vignettes contain introductory material; view with
'browseVignettes()'. To cite Bioconductor, see
'citation("Biobase")', and for packages 'citation("pkgname")'.
Loading required package: IRanges
Loading required package: S4Vectors
Attaching package: 'S4Vectors'
The following objects are masked from 'package:base':
colMeans, colSums, expand.grid, rowMeans, rowSums
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/AnnotationDbi/Bimap-toTable.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Bimap-toTable
> ### Title: Methods for manipulating a Bimap object in a data-frame style
> ### Aliases: Bimap-toTable toTable toTable,FlatBimap-method
> ### toTable,Bimap-method as.data.frame,Bimap-method nrow
> ### nrow,Bimap-method nrow,FlatBimap-method nrow,AnnDbTable-method
> ### nrow,AnnDbBimap-method nrow,Go3AnnDbBimap-method ncol
> ### ncol,Bimap-method dim,Bimap-method head,FlatBimap-method
> ### tail,FlatBimap-method links links,Bimap-method links,FlatBimap-method
> ### links,AnnDbBimap-method links,Go3AnnDbBimap-method count.links
> ### count.links,Bimap-method count.links,Go3AnnDbBimap-method nhit
> ### nhit,Bimap-method nhit,environment-method nhit,list-method colnames
> ### colnames,FlatBimap-method colnames,AnnDbBimap-method colmetanames
> ### colmetanames,FlatBimap-method colmetanames,AnnDbBimap-method Lkeyname
> ### Lkeyname,Bimap-method Lkeyname,AnnDbBimap-method Rkeyname
> ### Rkeyname,Bimap-method Rkeyname,AnnDbBimap-method keyname
> ### keyname,Bimap-method tagname tagname,Bimap-method
> ### tagname,AnnDbBimap-method Rattribnames Rattribnames,Bimap-method
> ### Rattribnames,AnnDbBimap-method Rattribnames<-
> ### Rattribnames<-,FlatBimap-method Rattribnames<-,AnnDbBimap-method
> ### Rattribnames<-,Go3AnnDbBimap-method
> ### Keywords: methods
>
> ### ** Examples
>
> library(GO.db)
> x <- GOSYNONYM
> x
SYNONYM map for GO (object of class "GOTermsAnnDbBimap")
> toTable(x)[1:4, ]
synonym go_id Term Ontology
1 GO:0019952 GO:0000003 reproduction BP
2 GO:0019952 GO:0000003 reproduction BP
3 GO:0019952 GO:0000003 reproduction BP
4 GO:0050876 GO:0000003 reproduction BP
Definition
1 The production of new individuals that contain some portion of genetic material inherited from one or more parent organisms.
2 The production of new individuals that contain some portion of genetic material inherited from one or more parent organisms.
3 The production of new individuals that contain some portion of genetic material inherited from one or more parent organisms.
4 The production of new individuals that contain some portion of genetic material inherited from one or more parent organisms.
Synonym Secondary
1 reproductive physiological process <NA>
2 GO:0019952 GO:0019952
3 GO:0050876 GO:0050876
4 reproductive physiological process <NA>
> toTable(x["GO:0007322"])
synonym go_id Term Ontology
1 GO:0007322 GO:0000747 conjugation with cellular fusion BP
2 GO:0007322 GO:0000747 conjugation with cellular fusion BP
3 GO:0007322 GO:0000747 conjugation with cellular fusion BP
4 GO:0007322 GO:0000747 conjugation with cellular fusion BP
5 GO:0007322 GO:0000747 conjugation with cellular fusion BP
6 GO:0007322 GO:0000747 conjugation with cellular fusion BP
Definition
1 A conjugation process that results in the union of cellular and genetic information from compatible mating types. An example of this process is found in Saccharomyces cerevisiae.
2 A conjugation process that results in the union of cellular and genetic information from compatible mating types. An example of this process is found in Saccharomyces cerevisiae.
3 A conjugation process that results in the union of cellular and genetic information from compatible mating types. An example of this process is found in Saccharomyces cerevisiae.
4 A conjugation process that results in the union of cellular and genetic information from compatible mating types. An example of this process is found in Saccharomyces cerevisiae.
5 A conjugation process that results in the union of cellular and genetic information from compatible mating types. An example of this process is found in Saccharomyces cerevisiae.
6 A conjugation process that results in the union of cellular and genetic information from compatible mating types. An example of this process is found in Saccharomyces cerevisiae.
Synonym Secondary
1 cell fusion <NA>
2 mating <NA>
3 GO:0007322 GO:0007322
4 GO:0007333 GO:0007333
5 GO:0030461 GO:0030461
6 GO:0030477 GO:0030477
> links(x)[1:4, ]
synonym go_id
1 GO:0019952 GO:0000003
2 GO:0050876 GO:0000003
3 GO:0006594 GO:0000050
4 GO:0006871 GO:0000050
> links(x["GO:0007322"])
synonym go_id
1 GO:0007322 GO:0000747
>
> nrow(x)
[1] 14176
> ncol(x)
[1] 7
> dim(x)
[1] 14176 7
> colnames(x)
[1] "synonym" "go_id" "Term" "Ontology" "Definition"
[6] "Synonym" "Secondary"
> colmetanames(x)
[1] "Lkeyname" "Rkeyname"
> Lkeyname(x)
[1] "synonym"
> Rkeyname(x)
[1] "go_id"
> tagname(x)
[1] NA
> Rattribnames(x)
[1] "Term" "Ontology" "Definition" "Synonym" "Secondary"
>
> links(x)[1:4, ]
synonym go_id
1 GO:0019952 GO:0000003
2 GO:0050876 GO:0000003
3 GO:0006594 GO:0000050
4 GO:0006871 GO:0000050
> count.links(x)
[1] 1790
>
> y <- GOBPCHILDREN
> nhy <- nhit(y) # 'nhy' is a named integer vector
> identical(names(nhy), keys(y)) # TRUE
[1] TRUE
> table(nhy)
nhy
0 1 2 3 4 5 6 7 8 9 10 11 12
11648 4318 4567 2775 1445 940 602 433 318 226 178 151 120
13 14 15 16 17 18 19 20 21 22 23 24 25
75 75 66 37 50 44 45 26 23 24 26 19 12
26 27 28 29 30 31 32 33 34 35 36 37 38
7 12 12 11 12 6 5 2 7 10 9 3 5
39 40 41 42 43 44 45 46 47 48 49 50 51
5 11 6 3 2 5 5 6 4 6 4 4 3
52 53 54 55 56 57 58 60 61 62 64 65 66
1 4 2 3 1 2 2 2 3 2 4 1 1
67 68 69 71 73 74 76 78 79 82 84 85 86
2 2 1 2 1 3 2 1 1 1 2 2 1
88 89 90 91 92 96 98 100 101 103 106 120 145
1 1 1 1 1 2 1 1 1 1 1 1 1
149 176 180 199 257 420
1 1 1 1 1 1
> sum(nhy == 0) # number of GO IDs with no children
[1] 11648
> names(nhy)[nhy == max(nhy)] # the GO ID(s) with the most direct children
[1] "GO:0044767"
>
> ## Some sanity check
> sum(nhy) == count.links(y) # TRUE
[1] TRUE
>
> ## Changing the right attributes of the GOSYNONYM map (advanced
> ## users only)
> class(x) # GOTermsAnnDbBimap
[1] "GOTermsAnnDbBimap"
attr(,"package")
[1] "AnnotationDbi"
> as.list(x)[1:3]
$`GO:0000004`
GOID: GO:0008150
Term: biological_process
Ontology: BP
Definition: Any process specifically pertinent to the functioning of
integrated living units: cells, tissues, organs, and organisms. A
process is a collection of molecular events with a defined
beginning and end.
Synonym: biological process
Synonym: physiological process
Synonym: GO:0000004
Synonym: GO:0007582
Secondary: GO:0000004
Secondary: GO:0007582
$`GO:0000021`
GOID: GO:0007131
Term: reciprocal meiotic recombination
Ontology: BP
Definition: The cell cycle process in which double strand breaks are
formed and repaired through a double Holliday junction
intermediate. This results in the equal exchange of genetic
material between non-sister chromatids in a pair of homologous
chromosomes. These reciprocal recombinant products ensure the
proper segregation of homologous chromosomes during meiosis I and
create genetic diversity.
Synonym: female meiotic recombination
Synonym: gene conversion with reciprocal crossover
Synonym: GO:0000021
Synonym: GO:0007145
Secondary: GO:0000021
Secondary: GO:0007145
$`GO:0000029`
GOID: GO:0006450
Term: regulation of translational fidelity
Ontology: BP
Definition: Any process that modulates the ability of the translational
apparatus to interpret the genetic code.
Synonym: regulation of translational accuracy
Synonym: GO:0000029
Secondary: GO:0000029
> colnames(x)
[1] "synonym" "go_id" "Term" "Ontology" "Definition"
[6] "Synonym" "Secondary"
> colmetanames(x)
[1] "Lkeyname" "Rkeyname"
> tagname(x) # untagged map
[1] NA
> Rattribnames(x)
[1] "Term" "Ontology" "Definition" "Synonym" "Secondary"
> Rattribnames(x) <- Rattribnames(x)[3:1]
> colnames(x)
[1] "synonym" "go_id" "Definition" "Ontology" "Term"
> class(x) # AnnDbBimap
[1] "AnnDbBimap"
attr(,"package")
[1] "AnnotationDbi"
> as.list(x)[1:3]
$`GO:0000004`
[1] "GO:0008150"
$`GO:0000021`
[1] "GO:0007131"
$`GO:0000029`
[1] "GO:0006450"
>
>
>
>
>
> dev.off()
null device
1
>