Sets-methods: Methods for 'Sets' Objects

Description Usage Arguments Accessors Dimensions Combining Subsetting Duplication and uniqueness Coercion from Sets Coercion to Sets Author(s) See Also Examples

Description

This page documents the S4 generics and methods defined for objects inheriting of the Sets class. In the usage below, object and x represent an object of class inheriting from Sets, and value is an object of a class specified in the S4 method signature or as outlined in 'Accessors'.

Usage

 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
relations(object)

relations(object) <- value

elements(object)

elementInfo(object)

elementInfo(object) <- value

sets(object)

setInfo(object)

setInfo(object) <- value

nElements(object)

nSets(object)

setLengths(object)

elementLengths(object)

## S4 method for signature 'Sets'
relations(object)

## S4 replacement method for signature 'Sets'
relations(object) <- value

## S4 method for signature 'Sets'
elementInfo(object)

## S4 replacement method for signature 'Sets'
elementInfo(object) <- value

## S4 method for signature 'Sets'
setInfo(object)

## S4 replacement method for signature 'Sets'
setInfo(object) <- value

## S4 method for signature 'Sets'
elements(object)

## S4 method for signature 'Sets'
sets(object)

## S4 method for signature 'Sets'
length(x)

## S4 method for signature 'Sets'
nElements(object)

## S4 method for signature 'Sets'
nSets(object)

## S4 method for signature 'Sets'
setLengths(object)

## S4 method for signature 'Sets'
elementLengths(object)

## S3 method for class 'Sets'
c(x, ...)

## S4 method for signature 'Sets,ANY,ANY,ANY'
x[i, j, ..., drop = TRUE]

## S3 method for class 'Sets'
subset(x, ...)

## S4 method for signature 'Sets'
duplicated(x, incomparables = FALSE, ...)

## S4 method for signature 'Sets'
unique(x, incomparables = FALSE, ...)

union.Sets(x, y, ...)

as.DataFrame.Sets(object, ...)

## S3 method for class 'Sets'
as.data.frame(x, ...)

## S3 method for class 'Sets'
as.list(x, ...)

## S3 method for class 'Sets'
as.matrix(x, ...)

as.Sets.list(list, ...)

as.Sets.matrix(matrix, ...)

Arguments

object, x

An object of class inheriting from Sets.

value

An object of a class specified in the S4 method signature or as outlined in 'Accessors'.

...

Additional arguments passed to and from other methods.

i

index specifying elements to extract or replace.

j

Ignored.

drop

A logical scalar indicating whether to remove orphan elements and sets from the elementInfo and setInfo slots, respectively.

incomparables

Ignored.

y

An object of class inheriting from Sets.

list

A list of named character vectors. The names are taken as the set identifiers. The character vectors are taken as identifiers of elements that are member of each set.

matrix

A matrix. The matrix will be coerced to logical type and relations indicating TRUE will be stored in the Sets.

Accessors

relations(object) returns the relations slot. A Hits objets storing the integer index of elements (from) and sets (to) in the elementInfo and setInfo slots, respectively, and associated relation metadata (mcols).

elementInfo(object) returns the elementInfo slot. An IdVector objets storing the unique element identifiers (ids) and associated element metadata (mcols).

setInfo(object) returns the setInfo slot. An IdVector objets storing the unique set identifiers (ids) and associated set metadata (mcols).

elements(object) returns an IdVector element identifiers and associated metadata as ordered in relations(object)$element (i.e., of length equal to length(object)).

sets(object) returns an IdVector of set identifiers and associated metadata as ordered in relations(object)$set. (i.e., of length equal to length(object)).

Dimensions

length(x) returns the total count of relations.

nElements(object) returns the count of unique elements.

nSets(object) returns the count of unique sets.

setLengths(object) returns the count of relations per set.

elementLengths(object) returns the count of relations per element.

Combining

c(x, ...) combines its arguments

Subsetting

x[i, drop=TRUE] returns new Sets object of the same class as x made of the elements selected by i. i can be missing; an NA-free logical, numeric, or character vector or factor (as ordinary vector or Rle object); or an IntegerRanges object. The drop logical value controls whether the metadata of elements and sets orphaned during the subsetting should be removed from the elementInfo and setInfo slots, respectively.

subset(object, subset, ..., drop=TRUE) returns subsets of relations which meet conditions. The subset argument should be a logical expression referring to any of "element", "set", and any available relation metadata indicating elements or rows to keep: missing values are taken as false. The drop logical scalar controls whether elements and sets orphaned during the subsetting should be removed from the elementInfo and setInfo slots, respectively.

Duplication and uniqueness

duplicated(x) determines which relations of a Sets are duplicates of relations with smaller subscripts, and returns a logical vector indicating which relations are duplicates.

unique(x) returns a Sets like x but with duplicate relations removed.

union(x) returns a Sets composed of the union of relations in x and y.

Coercion from Sets

as(object, "DataFrame") and as.DataFrame(object) return a nested DataFrame including columns "element", "set", "relationData", "elementInfo", and "setInfo".

as(x, "data.frame") and as.data.frame(x) return a flattened data.frame including "element", "set", and columns in mcols(relations(x)) if any.

as(x, "list") and as.list(x) return a named list. Names are set identifiers, and values are character vectors of element identifiers.

as(x, "matrix") and as.matrix(x) return a matrix with elements as rows, sets as columns, and a logical value to indicate membership.

Coercion to Sets

as(list, "Sets") and as.Sets(object) return a Sets from a list of character vectors.

as(matrix, "Sets") and as.Sets(object) return a Sets from an incidence matrix.

Author(s)

Kevin Rue-Albrecht

See Also

Sets.

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Constructor ----

# Visually intuitive definition of sets
sets <- list(
  set1=c("A", "B"),
  set2=c("B", "C", "D"),
  set3=c("E"))

bs <- as(sets, "Sets")
bs

# Accessors ----

relations(bs)

bs1 <- bs
mcols(relations(bs1))[["NEW"]] <- paste0("value", seq_len(length(bs1)))

elementInfo(bs)

bs1 <- bs
mcols(elementInfo(bs1))[["NEW"]] <- paste0("value", seq_len(nElements(bs1)))

setInfo(bs)

bs1 <- bs
mcols(setInfo(bs1))[["NEW"]] <- paste0("value", seq_len(nSets(bs1)))

elements(bs)
ids(elements(bs))
mcols(elements(bs))

sets(bs)
ids(sets(bs))
mcols(sets(bs))

# Dimensions ----

length(bs)
nElements(bs)
nSets(bs)
setLengths(bs)
elementLengths(bs)

# Combining ----

bs1 <- c(bs, bs)

# Subsetting ----

bs1 <- bs[1:5]
bs1 <- bs[1:5, , drop=FALSE] # keep metadata of orphan elements and sets

bs1 <- subset(bs, set == "set1" | element == "E")
bs1

# Duplication and uniqueness ----

bs1 <- bs
relations(bs1) <- rep(relations(bs1), each=2)
table(duplicated(bs1))
unique(bs1)
bs1 <- union(bs, bs)

# Coercion from Sets ----

DF1 <- as(bs, "DataFrame")

df1 <- as.data.frame(bs)

l1 <- as(bs, "list")

m1 <- as(bs, "matrix")

bs1 <- bs
mcols(relations(bs1))[["membership"]] <- runif(length(bs1))
fs <- as(bs1, "FuzzySets")

# Fetch a sample of GO annotations
library(org.Hs.eg.db)
gs <- import(org.Hs.egGO)
bs1 <- as(gs, "Sets")
gs1 <- as(bs1, "GOSets")

# Coercion to Sets ----

# list
bs1 <- as(list(set1=c("A", "B"), set2=c("B", "C")), "Sets")
# matrix
bs1 <- as(m1, "Sets")

kevinrue/unisets documentation built on May 15, 2020, 10:48 p.m.