tcR (version 1.1)

intersect: Intersection between sets of sequences or any elements.

Description

Functions for the intersection of data frames with TCR / BCR data.

intersect - overwrites base::intersect function. If supplied with parameters x and y, than runs base::intersect on them. If not, than returns number of similar elements in the given objects or matrix with count of similar elements among each objects in the given list.

intersectCount - similar to tcR::intersect, but with fewer parameters and only for two objects.

intersectIndices - returns matrix M with two columns, where element with index M[i, 1] in the first given object is similar to an element with index M[i, 2] in the second given object.

intersectLogic - returns logic vector with TRUE values in positions, where element in the first given data frame is found in the second given data frame.

Usage

intersect(.alpha = NULL, .beta = NULL, .type = "00e", .head = -1, .norm = F,
          .verbose = F, x = NULL, y = NULL)

intersectCount(.alpha, .beta, .method = c('exact', 'hamm', 'lev'), .col = NULL)

intersectIndices(.alpha, .beta, .method = c('exact', 'hamm', 'lev'), .col = NULL)

intersectLogic(.alpha, .beta, .method = c('exact', 'hamm', 'lev'), .col = NULL)

Arguments

.alpha
Either first vector or data.frame or list with data.frames.
.beta
Second vector or data.frame or type of intersection procedure (see the .type parameter) if .alpha is a list.
.type
Types of intersection procedure if .alpha and .beta is data frames. String with 3 characters (see 'Details' for more information).
.head
Parameter for the head function, applied before intersecting.
.norm
If TRUE than normalise result by product of length or nrows of the given data.
.verbose
If T than produce output of processing the data.
x,y
Parameters leaved for compatability with code which uses base::intersect. If provided than replaces .alpha and .beta respectively.
.method
Method to use for intersecting string elements: 'exact' for exact matching, 'hamm' for matching strings which have
.col
Which columns use for fetching values to intersect. First supplied column matched with .method, others as exact values.

Value

  • intersect returns (normalised) number of similar elements or matrix with numbers of elements.

    intersectCount returns number of similar elements.

    intersectIndices returns 2-row matrix with the first column stands for an index of an element in the given x, and the second column stands for an index of an element of y which is similar to a relative element in x;

    intersectLogic returns logical vector of length(x) or nrow(x), where TRUE at position i means that element with index {i} has been found in the y

Details

Parameter .type of the cross function is a string of length 3 [0an][0vja][ehl], where:
  1. First character defines which elements intersect ("a" for elements from the column "CDR3.amino.acid.sequence", "n" for elements from the column "CDR3.nucleotide.sequence", other characters - intersect elements as specified);
  2. Second character defines which columns additionaly script should use ('0' for cross with no additional columns, 'v' for cross using the "V.segments" column, 'j' for cross using "J.segments" column, 'a' for cross using both "V.segments" and "J.segments" columns);
  3. Third character defines a method of search for similar sequences is use: "e" stands for the exact match of sequnces, "h" for match elements which have the Hamming distance between them equal to or less than 1, "l" for match elements which have the Levenshtein distance between tham equal to or less than 1.

See Also

vis.heatmap, vis.group.boxplot

Examples

Run this code
data(twb)
# Equivalent to intersect(twb[[1]]$CDR3.nucleotide.sequence,
#                         twb[[2]]$CDR3.nucleotide.sequence)
# or intersectCount(twb[[1]]$CDR3.nucleotide.sequence,
#                    twb[[2]]$CDR3.nucleotide.sequence)
# First "n" stands for a "CDR3.nucleotide.sequence" column, "e" for exact match.
twb.12.n0e <- intersect(twb[[1]], twb[[2]], 'n0e')
stopifnot(twb.12.n0e == 46)
# First "a" stands for "CDR3.amino.acid.sequence" column.
# Second "v" means that intersect should also use the "V.segments" column.
intersect(twb[[1]], twb[[2]], 'ave')
# Works also on lists, performs all possible pairwise intersections.
intersect(twb, 'ave')
# Plot results.
vis.heatmap(intersect(twb, 'ave'), .title = 'twb - (ave)-intersection', .labs = '')
# Get elements which are in both twb[[1]] and twb[[2]].
# Elements are tuples of CDR3 nucleotide sequence and corresponding V-segment
imm.1.2 <- intersectLogic(twb[[1]], twb[[2]],
                           .col = c('CDR3.amino.acid.sequence', 'V.segments'))
head(twb[[1]][imm.1.2, c('CDR3.amino.acid.sequence', 'V.segments')])

Run the code above in your browser using DataCamp Workspace