Pick the most frequent element in each column of the alignment matrix.
Arguments
- align
A TALE alignment as a character matrix, one row per array and one column per alignment position, with
NAfor gaps.as.matrix()on atales_msareturns one (seeas.matrix.tales_msa), filled with RVDs or domain codes.
Details
A column has a consensus only when one element is strictly more
common than every other. Where two or more are tied for most frequent –
as happens whenever each array carries a different repeat at that
position – the result is NA, because there is no agreement to
report. NA is likewise returned when the most common thing at a
position is a gap.
See also
Other TALE alignment:
as.matrix.tales_msa(),
is_tales_msa(),
tales_align(),
tales_consensus_match(),
tales_msa(),
tales_msa_params(),
tales_msa_width(),
validate_tales_msa()
Examples
# column 1: HD is a clear majority. column 2: a three-way tie, no consensus.
aln <- matrix(c("HD", "HD", "NI",
"NG", "NI", "HD"),
nrow = 3, dimnames = list(c("A1", "A2", "A3"), NULL))
aln
#> [,1] [,2]
#> A1 "HD" "NG"
#> A2 "HD" "NI"
#> A3 "NI" "HD"
tales_consensus(aln)
#> [1] "HD" NA
# From a tales_msa, such as tales_align() returns
msa <- tales_msa(data.frame(
array_id = c("A1", "A1", "A1", "A2", "A2", "A3", "A3", "A3"),
position_in_array = c(1L, 2L, 3L, 1L, 2L, 1L, 2L, 3L),
alignment_position = c(1L, 2L, 3L, 1L, 3L, 1L, 2L, 3L),
rvd = c("NTERM", "HD", "CTERM", "NTERM", "CTERM", "NTERM", "HD", "CTERM")
))
tales_consensus(as.matrix(msa))
#> [1] "NTERM" "HD" "CTERM"