| 1 |
Notes on the POA implementation |
| 2 |
=============================== |
| 3 |
|
| 4 |
Lineage |
| 5 |
------- |
| 6 |
|
| 7 |
The POA is an implementation of the partial order aligner of Lee, |
| 8 |
Grasso, Sharlow (2002). |
| 9 |
|
| 10 |
Our original implementations were done in F# then C# by Pat Marks. |
| 11 |
These was limited to global alignment and couldn't cope with large |
| 12 |
sequences due to memory limitations---there was no capability to do |
| 13 |
banded alignment. I ported the C# implementation to C++ in |
| 14 |
ConsenusCore for use in Quiver. |
| 15 |
|
| 16 |
All of these implementations are in the same spirit, and the only |
| 17 |
principle difference between them and the description in the Lee paper |
| 18 |
is that our implementations do not maintain the equality relations |
| 19 |
determined by aligned residues (bases). I see this as a bit of a |
| 20 |
limitation which forces our hand in some ways. It would be nice to |
| 21 |
have this information. |
| 22 |
|
| 23 |
|
| 24 |
Details of current implementation |
| 25 |
--------------------------------- |
| 26 |
|
| 27 |
Basically, we maintain a graph that reads can be aligned against; the |
| 28 |
aligned read can then be inserted into the graph. At any point a |
| 29 |
"consensus" of the graph can be retrieved. Information about each |
| 30 |
vertex is contained in a PoaNode struct. |
| 31 |
|
| 32 |
Unlike Pat's implementation, I chose *not* to retain "read pointer" |
| 33 |
information (readId, readPosition) in each PoaNode, because I was |
| 34 |
concerned that this would bloat the graph data, and in particular |
| 35 |
would add considerably to the memory consumption of Quiver. I work |
| 36 |
around this limitation as I will describe shortly. |
| 37 |
|
| 38 |
The ConsensusCore POA implementation is totally sufficient for |
| 39 |
Quiver's purposes but not sufficient for LAAMM, where very long reads |
| 40 |
can be added to the POA and naive Smith-Waterman approaches are memory |
| 41 |
inefficient. To support sparse-memory usage, the ConsensusCore |
| 42 |
exposes an API that allows plug-in banding... the client needs only |
| 43 |
provide an "SdpRangeFinder" implementation that identifies SDP anchors |
| 44 |
to be used in determining the subrange of each read that should be |
| 45 |
aligned. This code was left "pluggable" so that we would not need to |
| 46 |
add a dependency on SDP algorithms in ConsensusCore. LAAMM implements |
| 47 |
an SdpRangeFinder based on Seqan. |
| 48 |
|
| 49 |
The other "pluggable" aspect is that the read extent information is |
| 50 |
not maintained at all by the ConsensusCore POA; rather, when the |
| 51 |
client inserts a read to the graph, it can get the path of vertices |
| 52 |
the read traces. It can then, later, see how this path intersects the |
| 53 |
consensus path, to determine extents. (It has not escaped my notice |
| 54 |
that the extents should really be based on the "aligned residue" |
| 55 |
equivalence relation, which we do not maintain, but in practice this |
| 56 |
is probably fine). |
| 57 |
|
| 58 |
I am on the fence about adding readpointers into the base |
| 59 |
graph---perhaps templated out, so Quiver doesn't get bloated. It |
| 60 |
seems a more direct way of encoding the information, if we could do it |
| 61 |
compactly enough. |
| 62 |
|
| 63 |
|
| 64 |
Notes on coverage, minCoverage |
| 65 |
------------------------------ |
| 66 |
|
| 67 |
In LOCAL or SEMIGLOBAL uses of the POA (so, CCS and LAAMM, but not |
| 68 |
Quiver), reads may represent only a portion of the template---they do |
| 69 |
not go end-to-end. For these modes we need to maintain some |
| 70 |
information about |
| 71 |
|
| 72 |
Each POA node knows how many reads it represents (pass through the |
| 73 |
vertex, basically). We also maintain information about the total |
| 74 |
effective width of the graph at any point "the coverage" (known as |
| 75 |
SpanningReads in this codebase). Formally, we can think of the |
| 76 |
coverage of a vertex as the number of reads that pass through this |
| 77 |
vertex, plus any other reads which pass through at least one ancestor |
| 78 |
and at least one descendant of this vertex. Pat implements coverage |
| 79 |
exactly from this definition, using the readpointers in his POA. The |
| 80 |
ConsensusCore POA, since it does not maintain the readpointers, can't |
| 81 |
do this, so instead we use a different approach ("tagSpan" approach) |
| 82 |
where, when each read is added, we incremement the spanning coverage |
| 83 |
for all vertices "covered" by the read. This approach may be |
| 84 |
suboptimal, and we should explore that. |
| 85 |
|
| 86 |
The coverage information is only important in determining consensus. |
| 87 |
Briefly, we calculate the consensus by looking for a path maximizing a |
| 88 |
score determined as a sum of vertex scores, where each vertex score is |
| 89 |
determined as |
| 90 |
|
| 91 |
(2 * numReads[v] - coverage[v] - epsilon) |
| 92 |
|
| 93 |
so that if a vertex represents less than half of the coverage at its |
| 94 |
position, its score for inclusion in the POA consensus will be |
| 95 |
negative (discouraging inclusion in the consensus). |
| 96 |
|
| 97 |
`minCoverage` is a parameter to some of the API methods which From the |
| 98 |
API user's point of view, `minCoverage` represents a lower-bound |
| 99 |
estimate of the "basal" level of coverage over the span of the |
| 100 |
template under consideration. It is used to |
| 101 |
|
| 102 |
Given minCoverage, the vertex score becomes |
| 103 |
|
| 104 |
(2 * numReads[v] - max(coverage[v], minCoverage) - epsilon) |
| 105 |
|
| 106 |
so minCoverage bounds the computed coverage from below. A minCoverage |
| 107 |
of 0 thus has no effect; a minCoverage chosen too large could |
| 108 |
discourage inclusion of "borderline" consensus bases. In practice |
| 109 |
this might manifest as consensus sequences that are truncated at the |
| 110 |
ends. |
| 111 |
|
| 112 |
The value of minCoverage is unclear---it was unclear why it was added, |
| 113 |
why it was deemed necessary. It might be helpful if we could use it |
| 114 |
to completely replace the local coverage calculation. We need to do |
| 115 |
some experiments on extensive datasets to see how, in practice, this |
| 116 |
affects observed truncations in HLA datasets. |
| 117 |
|
| 118 |
|
| 119 |
Known issues |
| 120 |
------------ |
| 121 |
|
| 122 |
- TODO: Pruning not yet implemented |
| 123 |
- TODO: Explore efficacy of coverage, minCoverage in CCS and LAA contexts. |
| 124 |
- TODO: Explore bad truncation phenotypes |
| 125 |
- TODO: Better |
| 126 |
|
| 127 |
- Local coverage is calculated using the old "tagSpan" approach, |
| 128 |
rather than the fwd/backward union approach Pat developed later. |
| 129 |
Not clear how big of a problem this is. |
| 130 |
|
| 131 |
- The boost graph library is a headache. |
| 132 |
|
| 133 |
- The core code for the alignment dynamic programming, and the |
| 134 |
traceback-and-thread operation, is trickier than it needs to be. |
| 135 |
Each of these methods is implementing a simple state machine, but |
| 136 |
the code does not reflect this simplicity. |
| 137 |
|
| 138 |
|
| 139 |
--- |
| 140 |
David Alexander, 2015 |