Attempt at "fixing" the consensus sequence in a homopolymer region
Source:R/cluster.R
fix_homopolymers.RdAttempt at "fixing" the consensus sequence in a homopolymer region
Value
a data frame with these columns:
consensus: the "fixed" consensus sequence
n_adjusted the number of "fixed" homopolymer stretches
Details
Resolves N-ambiguities in the consensus if surrounded by a homopolymer stretch, replacing them with the corresponding reference sequence. This sequence is assumed to be the most likely true sequence, following the concept of DADA2, which is also based on the assumption that there are at least a few error-free reads present. It is clear that this might not be true in all cases if there are very long homopolymer stretches present.
Ns are usually found on the left side (or near it), as minimap2 tends to left-align gaps, and if there is an ambiguous situation (base + gap), the consensus becomes an N.
A consensus/reference pairwise alignment is done with DECIPHER
The leftmost N is identified
The first non-N base downstream (right) is assumed to be the repeated base (usually true if gaps are left-aligned). Jump to 7. if none is found.
The longest stretch of the given base/N/gaps is searched in the aligned consensus
If the aligned reference contains only the given base and gaps within the range identified in 4., then the consensus sequence is replaced with the aligned reference
Go back to 2., searching for the next N
Remove all gaps from the consensus and return this sequence