Last data update: 2014.03.03

R: Set operations on Hits objects
Hits-setopsR Documentation

Set operations on Hits objects

Description

Perform set operations on Hits objects.

Details

union(x, y), intersect(x, y), setdiff(x, y), and setequal(x, y) work on Hits objects x and y only if the objects are compatible Hits objects, that is, if they have the same subject and query lengths. These operations return respectively the union, intersection, (asymmetric!) difference, and equality of the sets of hits in x and y.

Value

union returns a Hits object obtained by appending to x the hits in y that are not already in x.

intersect returns a Hits object obtained by keeping only the hits in x that are also in y.

setdiff returns a Hits object obtained by dropping from x the hits that are in y.

setequal returns TRUE if x and y contain the same sets of hits and FALSE otherwise.

union, intersect, and setdiff propagate the names and metadata columns of their first argument (x).

Author(s)

Herv<c3><83><c2><a9> Pag<c3><83><c2><a8>s and Michael Lawrence

See Also

  • Hits objects.

  • Hits-comparison for comparing and ordering hits.

  • BiocGenerics::union, BiocGenerics::intersect, and BiocGenerics::setdiff in the BiocGenerics package for general information about these generic functions.

Examples

x <- Hits(c(2, 4, 4, 4, 5, 5), c(3, 1, 3, 2, 3, 2), 6, 3,
          score=11:16)
x

y <- Hits(c(1, 3, 4, 4, 5, 5, 5), c(3, 3, 2, 1, 2, 1, 3), 6, 3,
          score=21:27)
y

union(x, y)
union(y, x)  # same hits as in union(x, y), but in different order

intersect(x, y)
intersect(y, x)  # same hits as in intersect(x, y), but in
                 # different order

setdiff(x, y)
setdiff(y, x)

setequal(x, y)

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(S4Vectors)
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


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/S4Vectors/Hits-setops.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Hits-setops
> ### Title: Set operations on Hits objects
> ### Aliases: Hits-setops union,Hits,Hits-method
> ### Keywords: methods
> 
> ### ** Examples
> 
> x <- Hits(c(2, 4, 4, 4, 5, 5), c(3, 1, 3, 2, 3, 2), 6, 3,
+           score=11:16)
> x
Hits object with 6 hits and 1 metadata column:
           from        to |     score
      <integer> <integer> | <integer>
  [1]         2         3 |        11
  [2]         4         1 |        12
  [3]         4         3 |        13
  [4]         4         2 |        14
  [5]         5         3 |        15
  [6]         5         2 |        16
  -------
  nLnode: 6 / nRnode: 3
> 
> y <- Hits(c(1, 3, 4, 4, 5, 5, 5), c(3, 3, 2, 1, 2, 1, 3), 6, 3,
+           score=21:27)
> y
Hits object with 7 hits and 1 metadata column:
           from        to |     score
      <integer> <integer> | <integer>
  [1]         1         3 |        21
  [2]         3         3 |        22
  [3]         4         2 |        23
  [4]         4         1 |        24
  [5]         5         2 |        25
  [6]         5         1 |        26
  [7]         5         3 |        27
  -------
  nLnode: 6 / nRnode: 3
> 
> union(x, y)
Hits object with 9 hits and 1 metadata column:
           from        to |     score
      <integer> <integer> | <integer>
  [1]         2         3 |        11
  [2]         4         1 |        12
  [3]         4         3 |        13
  [4]         4         2 |        14
  [5]         5         3 |        15
  [6]         5         2 |        16
  [7]         1         3 |        21
  [8]         3         3 |        22
  [9]         5         1 |        26
  -------
  nLnode: 6 / nRnode: 3
> union(y, x)  # same hits as in union(x, y), but in different order
Hits object with 9 hits and 1 metadata column:
           from        to |     score
      <integer> <integer> | <integer>
  [1]         1         3 |        21
  [2]         3         3 |        22
  [3]         4         2 |        23
  [4]         4         1 |        24
  [5]         5         2 |        25
  [6]         5         1 |        26
  [7]         5         3 |        27
  [8]         2         3 |        11
  [9]         4         3 |        13
  -------
  nLnode: 6 / nRnode: 3
> 
> intersect(x, y)
Hits object with 4 hits and 1 metadata column:
           from        to |     score
      <integer> <integer> | <integer>
  [1]         4         1 |        12
  [2]         4         2 |        14
  [3]         5         3 |        15
  [4]         5         2 |        16
  -------
  nLnode: 6 / nRnode: 3
> intersect(y, x)  # same hits as in intersect(x, y), but in
Hits object with 4 hits and 1 metadata column:
           from        to |     score
      <integer> <integer> | <integer>
  [1]         4         2 |        23
  [2]         4         1 |        24
  [3]         5         2 |        25
  [4]         5         3 |        27
  -------
  nLnode: 6 / nRnode: 3
>                  # different order
> 
> setdiff(x, y)
Hits object with 2 hits and 1 metadata column:
           from        to |     score
      <integer> <integer> | <integer>
  [1]         2         3 |        11
  [2]         4         3 |        13
  -------
  nLnode: 6 / nRnode: 3
> setdiff(y, x)
Hits object with 3 hits and 1 metadata column:
           from        to |     score
      <integer> <integer> | <integer>
  [1]         1         3 |        21
  [2]         3         3 |        22
  [3]         5         1 |        26
  -------
  nLnode: 6 / nRnode: 3
> 
> setequal(x, y)
[1] FALSE
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>