count_kmers: Count k-mers of one, particular type for a given collection...

Description Usage Arguments Details Value See Also Examples

View source: R/count_kmers.R

Description

This is an in-memory, probabilistic, highly-optimized, and multi-threaded implementation of k-mer counting algorithm.

The function supports

  1. several types of k-mers (contiguous, gapped, and positional variants)

  2. all biological sequences (in particular, nucleic acids and proteins)

  3. two common in-memory representations of sequences, i.e., string vectors and list of string vectors

Moreover, several extra features are provided (for more information see details'):

  1. configurable k-mer alphabet (i.e., which elements of a sequence should be considered during the k-mer counting procedure)

  2. verbose mode

  3. configurable batch size (i.e., how many sequences are processed in a single step)

  4. configurable dimension of the hash value of a k-mer

  5. possibility to compute k-mers with or without their frequencies

  6. possibility to compute a result k-mer matrix with or without human-readable k-mer (column) names

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
count_kmers(
  sequences,
  k = length(kmer_gaps) + 1,
  kmer_alphabet = getOption("seqR_kmer_alphabet_default"),
  positional = getOption("seqR_positional_default"),
  kmer_gaps = c(),
  with_kmer_counts = getOption("seqR_with_kmer_counts_default"),
  with_kmer_names = getOption("seqR_with_kmer_names_default"),
  batch_size = getOption("seqR_batch_size_default"),
  hash_dim = getOption("seqR_hash_dim_default"),
  verbose = getOption("seqR_verbose_default")
)

Arguments

sequences

input sequences of one of two supported types, either string vector or list of string vectors

k

an integer representing the length of a k-mer

kmer_alphabet

a string vector representing the elements that should be used during the construction of k-mers. By default, all elements that are present in sequences are taking into account

positional

a single logical value that determines whether positional k-mer variant should be considered

kmer_gaps

an integer vector representing the lengths of gaps between consecutive k-mer elements. The length of the vector should be equal to k - 1

with_kmer_counts

a single logical value that determines whether the result should contain k-mer frequencies

with_kmer_names

a single logical value that determines whether the result should contain human-readable k-mer names

batch_size

a single integer value that represents the number of sequences that are being processed in a single step

hash_dim

a single integer value (1 <= hash_dim <= 500) representing the length of a hash vector that is internally used in the algorithm

verbose

a single logical value that denotes whether a user wants to get extra information on the current state of computations

Details

The comprehensive description of supported features is available in vignette("features-overview", package = "seqR").

Value

a Matrix value that represents a result k-mer matrix. The result is a sparse matrix in order to reduce memory consumption. The i-th row of the matrix represents k-mers found in the i-th input sequence. Each column represents a distinct k-mer. The names of columns conform to human-readable schema for k-mers, if parameter with_kmer_names = TRUE

See Also

Function that counts many k-mer variants in the single invocation: count_multimers

Function that merges several k-mer matrices (rbind): rbind_columnwise

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
batch_size <- 1

# Counting 1-mers af two DNA sequences
count_kmers(
   c("ACAT", "ACC"),
   batch_size=batch_size)

# Counting 2-mers of two DNA sequences
count_kmers(
    c("ACAT", "ACC"),
    k=2,
    batch_size=batch_size)

# Counting positional 2-mers of two DNA sequences
count_kmers(
    c("ACAT", "ACC"),
    k=2,
    positional=TRUE,
    batch_size=batch_size)

# Counting positional 2-mers of two DNA sequences (second representation)
count_kmers(
     list(c("A", "C", "A", "T"), c("A", "C", "C")),
     k=2,
     positional=TRUE,
     batch_size=batch_size)

# Counting 3-mers of two DNA sequences, considering only A and C elements
count_kmers(
    c("ACAT", "ACC"),
    k=2,
    kmer_alphabet=c("A", "C"),
    batch_size=batch_size)

# Counting gapped 3-mers with lengths of gaps 1 and 2
count_kmers(
    c("ACATACTAT", "ACCCCCC"),
    kmer_gaps=c(1,2),
    batch_size=batch_size)

seqR documentation built on Oct. 6, 2021, 1:10 a.m.