'Degenerates' amino acid or nucleic sequence by aggregating elements to bigger groups.

degenerate(seq, element_groups)

Arguments

seq

character vector or matrix representing single sequence.

element_groups

encoding of elements: list of groups to which elements of sequence should be aggregated. Must have unique names.

Value

A character vector or matrix (if input is a matrix) containing aggregated elements.

Note

Characters not present in the element_groups will be converted to NA with a warning.

See also

l2n to easily convert information stored in biological sequences from letters to numbers. calc_ed to calculate distance between encodings.

Examples

sample_seq <- c(1, 3, 1, 3, 4, 4, 3, 1, 2) table(sample_seq)
#> sample_seq #> 1 2 3 4 #> 3 1 3 2
# aggregate sequence to purins and pyrimidines deg_seq <- degenerate(sample_seq, list(w = c(1, 4), s = c(2, 3))) table(deg_seq)
#> deg_seq #> s w #> 4 5