Repository navigation
Expand file tree
/
Copy pathzip_gaf.cpp
More file actions
1349 lines (1270 loc) · 61.4 KB
/
Copy pathzip_gaf.cpp
File metadata and controls
1349 lines (1270 loc) · 61.4 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
zip_gaf.cpp -- GafWalks (v3): observed haplotype walks from a graphmap GAF, and the GAF audit.
Layout
names GAF/graph name canonicalization (the design prototype's gaf_name_to_sn) and SN resolution
GafReader line input through `bgzip -@ t -dc` (BGZF) or `gzip -dc`, keeping only the head of
each line (the 12 mandatory fields and the first 512 bytes of tags), so the multi-GB
cg/ds tags are never copied
GafIndex projection of every record onto handles (the design prototype's path_to_handles, plus a
link check), excursions (as the design prototype cut them, in canonical frame), owners and weights, the
per-node excursion index, partial walk ends, and per-record reference coverage for
the audit (as in the design prototype)
GafWalks the WalkSource: observed excursions of a site, creator owners, observed Allowed
(as the prototype's iv_from_excs), and the creator-vs-observed diagnostic (the prototype's
"creator reconstruction exactness")
GafAudit the prototype audit's window and revisit checks, per zipped piece
*/
#include "zip_gaf.hpp"
#include "zip_edit.hpp"
#include <chrono>
#include <numeric>
#include <unordered_map>
namespace zip {
// ================================================================ names
namespace {
// true while unwinding from an error (outputs and summaries are then skipped)
inline bool unwinding() {
#if __cplusplus >= 201703L
return std::uncaught_exceptions() > 0;
#else
return std::uncaught_exception();
#endif
}
const uint8_t KIND_X = 255; // anchors on two different SNs (possible only with several rank-0 SNs)
// "id=HG00320.1|JBHIKI010000013.1" -> "HG00320#1#JBHIKI010000013.1"; "id=GRCh38|chr16" ->
// "GRCh38#0#chr16" (the design prototype's gaf_name_to_sn); "id=X" -> "X"; anything else is unchanged.
std::string canon_name(const std::string& x) {
if (x.compare(0, 3, "id=") != 0) return x;
std::string y = x.substr(3);
size_t bar = y.find('|');
if (bar == std::string::npos) return y;
std::string samp = y.substr(0, bar), ctg = y.substr(bar + 1);
size_t dot = samp.rfind('.');
if (dot != std::string::npos) return samp.substr(0, dot) + "#" + samp.substr(dot + 1) + "#" + ctg;
return samp + "#0#" + ctg;
}
// the haplotype of a canonical contig name: its first two '#' fields ("HG00320#1"), else the name
std::string hap_name(const std::string& c) {
size_t p = c.find('#');
if (p == std::string::npos) return c;
size_t q = c.find('#', p + 1);
if (q == std::string::npos) return c;
return c.substr(0, q);
}
std::string last_field(const std::string& c) {
size_t p = c.rfind('#');
return p == std::string::npos ? c : c.substr(p + 1);
}
// the executable `name` on PATH, or ""
std::string find_on_path(const char* name) {
const char* p = getenv("PATH");
if (!p) return std::string();
std::string path(p);
size_t i = 0;
while (i <= path.size()) {
size_t j = path.find(':', i);
if (j == std::string::npos) j = path.size();
std::string dir = path.substr(i, j - i);
if (dir.empty()) dir = ".";
std::string f = dir + "/" + name;
struct stat st;
if (stat(f.c_str(), &st) == 0 && S_ISREG(st.st_mode) && access(f.c_str(), X_OK) == 0) return f;
i = j + 1;
}
return std::string();
}
// a bgzip that decompresses BGZF with -@ threads: htslib's, version 1.4 or later
bool usable_bgzip(const std::string& path) {
ProcResult r = run_process({path, "--version"}, std::string(), 1024);
if (!r.ok()) return false;
size_t p = r.out.find("(htslib) ");
if (p == std::string::npos) return false;
int major = 0, minor = 0;
if (sscanf(r.out.c_str() + p + 9, "%d.%d", &major, &minor) != 2) return false;
return major > 1 || (major == 1 && minor >= 4);
}
// ================================================================ GafReader
class GafReader {
public:
GafReader(const std::string& path, int threads) : path_(path), buf_(4u << 20) {
int fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
if (fd < 0) fail(EXIT_INPUT, strf("cannot open GAF %s: %s", path.c_str(), strerror(errno)));
unsigned char h[18];
memset(h, 0, sizeof(h));
ssize_t n = pread(fd, h, sizeof(h), 0);
if (!(n >= 2 && h[0] == 0x1f && h[1] == 0x8b)) {
fd_ = fd;
method_ = "plain";
return;
}
::close(fd);
// BGZF: gzip with FEXTRA whose first subfield is 'BC'; bgzip decompresses it in parallel
bool bgzf = n >= 18 && (h[3] & 4) != 0 && h[12] == 'B' && h[13] == 'C';
std::string bg = bgzf ? find_on_path("bgzip") : std::string();
if (!bg.empty() && !usable_bgzip(bg)) bg.clear();
std::vector<std::string> argv;
if (!bg.empty()) {
int t = std::max(1, std::min(threads, 16));
argv = {bg, "-@", std::to_string(t), "-dc", "--", path};
method_ = strf("bgzip -@ %d", t);
} else {
argv = {"gzip", "-dc", "--", path};
method_ = "gzip";
}
int p[2];
if (pipe2(p, O_CLOEXEC) != 0) fail(EXIT_INPUT, strf("pipe: %s", strerror(errno)));
posix_spawn_file_actions_t fa;
posix_spawn_file_actions_init(&fa);
posix_spawn_file_actions_addopen(&fa, 0, "/dev/null", O_RDONLY, 0);
posix_spawn_file_actions_adddup2(&fa, p[1], 1);
int rc = spawn_child(pid_, argv, &fa);
posix_spawn_file_actions_destroy(&fa);
::close(p[1]);
if (rc != 0) {
::close(p[0]);
pid_ = -1;
fail(EXIT_INPUT, strf("cannot run %s to read %s: %s", argv[0].c_str(), path.c_str(), strerror(rc)));
}
fd_ = p[0];
}
~GafReader() {
if (fd_ >= 0) ::close(fd_);
if (pid_ > 0) {
kill(pid_, SIGTERM);
int st;
reap_child(pid_, st, nullptr);
}
}
GafReader(const GafReader&) = delete;
GafReader& operator=(const GafReader&) = delete;
// The next line's head: fields 1-12 in full, then at most 512 bytes of tags (the tail of a
// longer line is skipped without copying). False at end of input.
bool next(std::string& head) {
head.clear();
int tabs = 0;
size_t tag_bytes = 0;
bool got = false;
while (true) {
if (pos_ >= len_ && !fill()) {
if (!got) return false;
++lineno_;
return true;
}
got = true;
const char* s = buf_.data() + pos_;
size_t n = len_ - pos_;
const char* nl = (const char*)memchr(s, '\n', n);
size_t seg = nl ? (size_t)(nl - s) : n;
size_t i = 0;
while (i < seg && tabs < 12) {
const char* t = (const char*)memchr(s + i, '\t', seg - i);
size_t upto = t ? (size_t)(t - s) + 1 : seg;
head.append(s + i, upto - i);
if (t) ++tabs;
i = upto;
}
if (tabs >= 12 && i < seg && tag_bytes < 512) {
size_t take = std::min(seg - i, (size_t)512 - tag_bytes);
head.append(s + i, take);
tag_bytes += take;
}
pos_ += seg + (nl ? 1 : 0);
if (nl) {
++lineno_;
if (!head.empty() && head.back() == '\r') head.pop_back();
return true;
}
}
}
// close and check the decompressor's exit status
void close() {
if (fd_ >= 0) { ::close(fd_); fd_ = -1; }
if (pid_ > 0) {
int st = 0;
bool waited = reap_child(pid_, st, nullptr);
pid_ = -1;
if (!waited) fail(EXIT_INPUT, strf("cannot read the exit status of the decompressor of GAF %s", path_.c_str()));
if (!(WIFEXITED(st) && WEXITSTATUS(st) == 0))
fail(EXIT_INPUT, strf("decompressing GAF %s failed (corrupt or truncated?)", path_.c_str()));
}
}
uint64_t line_number() const { return lineno_; }
const std::string& method() const { return method_; }
private:
bool fill() {
if (eof_) return false;
check_abort(); // once per buffer: a stop signal does not wait for a multi-GB GAF
while (true) {
ssize_t n = read(fd_, buf_.data(), buf_.size());
if (n < 0) {
if (errno == EINTR) continue;
fail(EXIT_INPUT, strf("read error on GAF %s: %s", path_.c_str(), strerror(errno)));
}
pos_ = 0;
len_ = (size_t)n;
if (n == 0) { eof_ = true; return false; }
return true;
}
}
std::string path_, method_;
int fd_ = -1;
pid_t pid_ = -1;
std::vector<char> buf_;
size_t pos_ = 0, len_ = 0;
bool eof_ = false;
uint64_t lineno_ = 0;
};
inline bool parse_i64(const char* p, size_t n, int64_t& out) {
if (n == 0 || n > 18) return false;
int64_t v = 0;
for (size_t i = 0; i < n; ++i) {
if (p[i] < '0' || p[i] > '9') return false;
v = v * 10 + (p[i] - '0');
}
out = v;
return true;
}
// "name:lo-hi" (the last ':' starts the interval); false if the step is not of that form
bool parse_stable(const char* t, size_t n, size_t& name_len, int64_t& lo, int64_t& hi) {
size_t c = n;
while (c > 0 && t[c - 1] != ':') --c;
if (c <= 1) return false; // no ':' or an empty name
size_t d = c;
while (d < n && t[d] != '-') ++d;
if (d >= n) return false;
if (!parse_i64(t + c, d - c, lo) || !parse_i64(t + d + 1, n - d - 1, hi)) return false;
name_len = c - 1;
return true;
}
struct RefIv {
int32_t sn;
int64_t lo, hi;
bool operator<(const RefIv& o) const { return sn != o.sn ? sn < o.sn : (lo != o.lo ? lo < o.lo : hi < o.hi); }
};
// sort and merge intervals that overlap or touch (the design prototype's merge_iv)
void merge_ivs(std::vector<RefIv>& v) {
std::sort(v.begin(), v.end());
size_t k = 0;
for (size_t i = 0; i < v.size(); ++i) {
if (k > 0 && v[k - 1].sn == v[i].sn && v[i].lo <= v[k - 1].hi) v[k - 1].hi = std::max(v[k - 1].hi, v[i].hi);
else v[k++] = v[i];
}
v.resize(k);
}
// longest overlap of [ta, tb) on `sn` with the sorted, merged intervals [b, e). Merged intervals
// of one SN are disjoint, so their ends are sorted as well: the search starts at the first one
// ending after ta (those ending earlier overlap by <= 0), and the scan stops at the first one
// starting at or after tb.
int64_t max_overlap(const RefIv* b, const RefIv* e, int32_t sn, int64_t ta, int64_t tb) {
const RefIv* it = std::partition_point(b, e, [&](const RefIv& x) { return x.sn < sn || (x.sn == sn && x.hi <= ta); });
int64_t best = 0;
for (; it != e && it->sn == sn && it->lo < tb; ++it) best = std::max(best, std::min(it->hi, tb) - std::max(it->lo, ta));
return best;
}
} // namespace
// ================================================================ GafIndex
struct GafLoadStats {
uint64_t lines = 0, comments = 0, records = 0, secondary = 0, unmapped = 0, foreign = 0, projected = 0;
uint64_t failed = 0, f_name = 0, f_misaligned = 0, f_overrun = 0, f_gap = 0, f_empty = 0, f_no_link = 0, f_length = 0;
uint64_t handles = 0, alt_handles = 0, occurrences = 0;
uint64_t partial_walks = 0, partial_handles = 0, no_ref_records = 0;
std::string first_failure;
};
class GafIndex {
public:
GafIndex(const Graph& g, const std::string& path, const Options& opt);
~GafIndex();
GafIndex(const GafIndex&) = delete;
GafIndex& operator=(const GafIndex&) = delete;
const Graph& g;
std::string path;
// contigs (GAF query names, canonical), haplotypes
std::vector<std::string> contig;
std::vector<uint32_t> contig_hap;
std::vector<int32_t> contig_sn; // the graph SN of the same name, -1 if none
std::vector<uint32_t> contig_records; // projected records (the design prototype's ctg_lines)
std::vector<std::string> hap;
std::vector<uint32_t> sn_contig; // graph SN -> contig, NONE if absent from the GAF
// distinct canonical observed excursions, in first-seen order
std::vector<Handle> dep, arr;
std::vector<uint32_t> alt_off;
std::vector<Handle> alts;
std::vector<uint32_t> own_off, own_contig; // owners sorted by contig id (one per contig)
std::vector<int64_t> own_qs; // smallest query start of that contig's records
std::vector<uint32_t> weight; // distinct haplotypes
std::vector<uint8_t> kind; // Kind
std::vector<int64_t> wlo, whi;
// per node
std::vector<uint32_t> node_exc_off, node_exc; // excursions through each alt node (sorted, unique)
std::vector<uint8_t> node_partial; // touched by a partial walk end or an unprojectable record
// per record (audit)
std::vector<uint32_t> rec_contig;
std::vector<uint32_t> rec_cov_off;
std::vector<RefIv> rec_cov; // merged rank-0 coverage
std::vector<uint32_t> node_rec_off, node_rec; // records walking each alt node
std::vector<uint32_t> ctg_cov_off;
std::vector<RefIv> ctg_cov;
GafLoadStats st;
std::string method;
double seconds = 0;
size_t n_exc() const { return dep.size(); }
bool anchored_in(const Site& s, uint32_t id) const {
return s.is_anchor_node(g, handle_node(dep[id])) && s.is_anchor_node(g, handle_node(arr[id]));
}
// the excursion as a foundation Excursion with its GAF owners (src GAF)
Excursion make_excursion(uint32_t id) const;
bool key_equal(uint32_t id, const Excursion& e) const {
if (dep[id] != e.dep || arr[id] != e.arr || alt_off[id + 1] - alt_off[id] != e.alts.size()) return false;
return std::equal(e.alts.begin(), e.alts.end(), alts.begin() + alt_off[id]);
}
bool has_contig(uint32_t id, uint32_t c) const {
return std::binary_search(own_contig.begin() + own_off[id], own_contig.begin() + own_off[id + 1], c);
}
private:
std::vector<std::vector<NodeId>> sn_nodes_; // every SN: its nodes sorted by SO
std::unordered_map<std::string, int32_t> canon_sn_, last_sn_, name_cache_;
std::unique_ptr<AtomicWriter> dump_exc_, dump_ctg_;
int32_t resolve_sn(const std::string& name);
int project_interval(int32_t sn, int64_t lo, int64_t hi, bool rev, std::vector<Handle>& hs) const;
int project_path(const char* p, size_t n, int64_t ps, int64_t pe, std::vector<Handle>& hs, uint32_t& resolved, bool& bare);
void touch_path(const char* p, size_t n, int64_t ps, int64_t pe);
void touch_interval(int32_t sn, int64_t lo, int64_t hi);
void write_dumps(const std::string& dir);
public:
// the finished --dump writers (gaf_excursions.tsv, gaf_contigs.tsv), committed by main
std::vector<AtomicWriter*> dump_writers() const;
};
namespace {
enum ProjResult { P_OK = 0, P_NAME, P_MISALIGNED, P_OVERRUN, P_GAP, P_EMPTY, P_NO_LINK, P_LENGTH };
const char* proj_name(int r) {
switch (r) {
case P_NAME: return "unknown sequence or segment name";
case P_MISALIGNED: return "step does not start on a node boundary";
case P_OVERRUN: return "step does not end on a node boundary";
case P_GAP: return "step crosses a gap between nodes";
case P_EMPTY: return "empty step";
case P_NO_LINK: return "consecutive steps are not linked in the graph";
case P_LENGTH: return "path length differs from column 7";
default: return "ok";
}
}
} // namespace
int32_t GafIndex::resolve_sn(const std::string& name) {
auto it = name_cache_.find(name);
if (it != name_cache_.end()) return it->second;
int32_t sn = g.find_sn(name);
if (sn < 0) {
auto c = canon_sn_.find(canon_name(name));
if (c != canon_sn_.end()) sn = c->second;
}
if (sn < 0 && name.find('#') == std::string::npos && name.find('|') == std::string::npos) {
auto c = last_sn_.find(name);
if (c != last_sn_.end()) sn = c->second;
}
if (sn < -1) sn = -1; // ambiguous canonical or last-field match
name_cache_[name] = sn;
return sn;
}
int GafIndex::project_interval(int32_t sn, int64_t lo, int64_t hi, bool rev, std::vector<Handle>& hs) const {
if (hi <= lo) return P_EMPTY;
const std::vector<NodeId>& v = sn_nodes_[(size_t)sn];
auto it = std::upper_bound(v.begin(), v.end(), lo, [&](int64_t x, NodeId n) { return x < g.start(n); });
if (it == v.begin()) return P_MISALIGNED;
--it;
if (g.start(*it) != lo) return P_MISALIGNED;
size_t first = hs.size();
int64_t pos = lo;
while (pos < hi) {
if (it == v.end()) return P_OVERRUN;
if (g.start(*it) != pos) return P_GAP;
hs.push_back(make_handle(*it, false));
pos = g.end(*it);
++it;
}
if (pos != hi) return P_OVERRUN;
if (rev) {
std::reverse(hs.begin() + (std::ptrdiff_t)first, hs.end());
for (size_t k = first; k < hs.size(); ++k) hs[k] = flip(hs[k]);
}
return P_OK;
}
// Project a GAF path onto handles. `resolved` counts the steps whose name is known to this graph
// (0: the record belongs to another graph). A bare sequence name (no orientation) is the '+'
// path over that sequence, of which [ps, pe) is aligned.
int GafIndex::project_path(const char* p, size_t n, int64_t ps, int64_t pe, std::vector<Handle>& hs, uint32_t& resolved, bool& bare) {
hs.clear();
resolved = 0;
bare = false;
if (n == 0) return P_EMPTY;
if (p[0] != '>' && p[0] != '<') {
bare = true;
std::string name(p, n);
int32_t sn = resolve_sn(name);
if (sn >= 0) {
++resolved;
if (pe <= ps) return P_EMPTY;
const std::vector<NodeId>& v = sn_nodes_[(size_t)sn];
auto it = std::upper_bound(v.begin(), v.end(), ps, [&](int64_t x, NodeId y) { return x < g.start(y); });
if (it == v.begin() || g.end(*(it - 1)) <= ps) return P_GAP;
--it;
int64_t pos = g.start(*it);
while (pos < pe) {
if (it == v.end()) return P_OVERRUN;
if (g.start(*it) != pos) return P_GAP;
hs.push_back(make_handle(*it, false));
pos = g.end(*it);
++it;
}
return P_OK;
}
NodeId x = g.find_name(name);
if (x == NONE) return P_NAME;
++resolved;
hs.push_back(make_handle(x, false));
return P_OK;
}
int result = P_OK;
size_t i = 0;
while (i < n) {
bool rev = p[i] == '<';
size_t j = i + 1;
while (j < n && p[j] != '>' && p[j] != '<') ++j;
const char* t = p + i + 1;
size_t tl = j - i - 1;
i = j;
if (tl == 0) { if (result == P_OK) result = P_EMPTY; continue; }
// after a failure, names are still resolved, so that a record that touches this graph
// anywhere counts as failed rather than as belonging to another graph
size_t nl = 0;
int64_t lo = 0, hi = 0;
if (parse_stable(t, tl, nl, lo, hi)) {
int32_t sn = resolve_sn(std::string(t, nl));
if (sn >= 0) {
++resolved;
if (result == P_OK) result = project_interval(sn, lo, hi, rev, hs);
continue;
}
}
NodeId x = g.find_name(std::string(t, tl));
if (x == NONE) { if (result == P_OK) result = P_NAME; continue; }
++resolved;
if (result == P_OK) hs.push_back(make_handle(x, rev));
}
return result;
}
void GafIndex::touch_interval(int32_t sn, int64_t lo, int64_t hi) {
const std::vector<NodeId>& v = sn_nodes_[(size_t)sn];
auto it = std::upper_bound(v.begin(), v.end(), lo, [&](int64_t x, NodeId n) { return x < g.start(n); });
if (it != v.begin()) --it;
for (; it != v.end() && g.start(*it) < hi; ++it)
if (g.end(*it) > lo && !g.is_ref(*it)) node_partial[*it] = 1;
}
// best effort for a record that could not be projected: every alt node it may walk is "partial"
void GafIndex::touch_path(const char* p, size_t n, int64_t ps, int64_t pe) {
if (n == 0) return;
if (p[0] != '>' && p[0] != '<') {
std::string name(p, n);
int32_t sn = resolve_sn(name);
if (sn >= 0) touch_interval(sn, ps, pe);
else {
NodeId x = g.find_name(name);
if (x != NONE && !g.is_ref(x)) node_partial[x] = 1;
}
return;
}
size_t i = 0;
while (i < n) {
size_t j = i + 1;
while (j < n && p[j] != '>' && p[j] != '<') ++j;
const char* t = p + i + 1;
size_t tl = j - i - 1;
i = j;
size_t nl = 0;
int64_t lo = 0, hi = 0;
if (tl > 0 && parse_stable(t, tl, nl, lo, hi)) {
int32_t sn = resolve_sn(std::string(t, nl));
if (sn >= 0) { touch_interval(sn, lo, hi); continue; }
}
NodeId x = g.find_name(std::string(t, tl));
if (x != NONE && !g.is_ref(x)) node_partial[x] = 1;
}
}
GafIndex::GafIndex(const Graph& g_, const std::string& path_, const Options& opt) : g(g_), path(path_) {
auto t0 = std::chrono::steady_clock::now();
long rss0 = self_peak_rss_kb();
const size_t N = g.nodes.size();
const size_t NS = g.sn_names.size();
// every SN's nodes by SO, and the name maps (-2 marks an ambiguous canonical / last-field name)
sn_nodes_.assign(NS, std::vector<NodeId>());
for (NodeId n = 0; n < (NodeId)N; ++n)
if (g.nodes[n].sn >= 0) sn_nodes_[(size_t)g.nodes[n].sn].push_back(n);
for (std::vector<NodeId>& v : sn_nodes_)
std::sort(v.begin(), v.end(), [&](NodeId a, NodeId b) { return g.start(a) != g.start(b) ? g.start(a) < g.start(b) : a < b; });
for (size_t s = 0; s < NS; ++s) {
std::string c = canon_name(g.sn_names[s]);
auto ins = canon_sn_.insert(std::make_pair(c, (int32_t)s));
if (!ins.second && ins.first->second != (int32_t)s) ins.first->second = -2;
std::string lf = last_field(c);
auto ins2 = last_sn_.insert(std::make_pair(lf, (int32_t)s));
if (!ins2.second && ins2.first->second != (int32_t)s) ins2.first->second = -2;
}
node_partial.assign(N, 0);
std::unordered_map<std::string, uint32_t> contig_id, hap_id;
std::unordered_map<std::string, uint32_t> exc_id;
struct Occ { uint32_t exc, contig; int64_t qs; };
std::vector<Occ> occ;
std::vector<std::pair<uint32_t, uint32_t>> node_rec_pairs; // (alt node, record)
alt_off.push_back(0);
rec_cov_off.push_back(0);
GafReader rd(path, opt.threads);
method = rd.method();
std::string head, key;
std::vector<size_t> fb, fe; // field begin/end offsets in head
std::vector<Handle> hs;
std::vector<RefIv> cov;
Excursion e;
while (rd.next(head)) {
++st.lines;
if (head.empty()) continue;
if (head[0] == '#') { ++st.comments; continue; }
fb.clear();
fe.clear();
size_t q = 0;
while (true) {
size_t t = head.find('\t', q);
fb.push_back(q);
fe.push_back(t == std::string::npos ? head.size() : t);
if (t == std::string::npos) break;
q = t + 1;
}
const uint64_t ln = rd.line_number();
if (fb.size() < 12)
fail(EXIT_INPUT, strf("GAF %s line %llu has %zu tab-separated fields; a GAF line has at least 12", path.c_str(),
(unsigned long long)ln, fb.size()));
const char* path_p = head.data() + fb[5];
const size_t path_n = fe[5] - fb[5];
if (path_n == 1 && path_p[0] == '*') { ++st.unmapped; continue; }
auto field_i64 = [&](int k, const char* what) {
int64_t v = 0;
if (!parse_i64(head.data() + fb[(size_t)k], fe[(size_t)k] - fb[(size_t)k], v))
fail(EXIT_INPUT, strf("GAF %s line %llu: column %d (%s) is not a non-negative integer", path.c_str(),
(unsigned long long)ln, k + 1, what));
return v;
};
const int64_t qlen = field_i64(1, "query length"), qs = field_i64(2, "query start"), qe = field_i64(3, "query end");
const int64_t plen = field_i64(6, "path length"), ps = field_i64(7, "path start"), pe = field_i64(8, "path end");
field_i64(9, "residue matches");
field_i64(10, "block length");
field_i64(11, "mapping quality");
const std::string strand = head.substr(fb[4], fe[4] - fb[4]);
if (strand != "+" && strand != "-" && strand != "*")
fail(EXIT_INPUT, strf("GAF %s line %llu: column 5 (strand) is '%s'", path.c_str(), (unsigned long long)ln, strand.c_str()));
if (qs > qe || qe > qlen || ps > pe || pe > plen)
fail(EXIT_INPUT, strf("GAF %s line %llu: inconsistent query or path interval", path.c_str(), (unsigned long long)ln));
bool secondary = false;
for (size_t k = 12; k < fb.size(); ++k)
if (fe[k] - fb[k] == 6 && head.compare(fb[k], 5, "tp:A:") == 0 && head[fb[k] + 5] == 'S') secondary = true;
if (secondary) { ++st.secondary; continue; }
++st.records;
uint32_t resolved = 0;
bool bare = false;
int r = project_path(path_p, path_n, ps, pe, hs, resolved, bare);
if (r == P_OK && !bare) {
int64_t sum = 0;
for (Handle h : hs) sum += g.len(handle_node(h));
if (sum != plen) r = P_LENGTH;
}
if (r == P_OK) {
for (size_t k = 1; k < hs.size() && r == P_OK; ++k) {
bool linked = false;
for (const Edge& ed : g.out(hs[k - 1]))
if (ed.to == hs[k]) { linked = true; break; }
if (!linked) r = P_NO_LINK;
}
}
if (r != P_OK) {
if (resolved == 0) { ++st.foreign; continue; }
++st.failed;
switch (r) {
case P_NAME: ++st.f_name; break;
case P_MISALIGNED: ++st.f_misaligned; break;
case P_OVERRUN: ++st.f_overrun; break;
case P_GAP: ++st.f_gap; break;
case P_EMPTY: ++st.f_empty; break;
case P_NO_LINK: ++st.f_no_link; break;
default: ++st.f_length; break;
}
if (st.first_failure.empty())
st.first_failure = strf("line %llu (%s): %s", (unsigned long long)ln,
head.substr(fb[0], fe[0] - fb[0]).c_str(), proj_name(r));
touch_path(path_p, path_n, ps, pe);
continue;
}
++st.projected;
// contig and haplotype
std::string cname = canon_name(head.substr(fb[0], fe[0] - fb[0]));
uint32_t cid;
auto ci = contig_id.find(cname);
if (ci != contig_id.end()) cid = ci->second;
else {
cid = (uint32_t)contig.size();
contig_id.emplace(cname, cid);
std::string hn = hap_name(cname);
auto hit = hap_id.find(hn);
uint32_t hid;
if (hit != hap_id.end()) hid = hit->second;
else { hid = (uint32_t)hap.size(); hap_id.emplace(hn, hid); hap.push_back(hn); }
contig.push_back(cname);
contig_hap.push_back(hid);
contig_sn.push_back(g.find_sn(cname));
contig_records.push_back(0);
}
++contig_records[cid];
const uint32_t rec = (uint32_t)rec_contig.size();
rec_contig.push_back(cid);
// reference coverage, alt-node visits, excursions
st.handles += hs.size();
cov.clear();
int64_t last_ref = -1;
for (size_t k = 0; k < hs.size(); ++k) {
NodeId x = handle_node(hs[k]);
if (!g.is_ref(x)) {
++st.alt_handles;
node_rec_pairs.push_back(std::make_pair(x, rec));
continue;
}
cov.push_back(RefIv{g.nodes[x].sn, g.start(x), g.end(x)});
if (last_ref < 0) {
if (k > 0) { // partial walk start: alt handles before the first rank-0 handle
++st.partial_walks;
for (size_t m = 0; m < k; ++m) { node_partial[handle_node(hs[m])] = 1; ++st.partial_handles; }
}
} else if ((int64_t)k > last_ref + 1) {
e.dep = hs[(size_t)last_ref];
e.arr = hs[k];
e.alts.assign(hs.begin() + last_ref + 1, hs.begin() + (std::ptrdiff_t)k);
canonicalize(e);
key.assign((const char*)&e.dep, sizeof(Handle));
key.append((const char*)&e.arr, sizeof(Handle));
key.append((const char*)e.alts.data(), e.alts.size() * sizeof(Handle));
auto ins = exc_id.insert(std::make_pair(key, (uint32_t)dep.size()));
if (ins.second) {
dep.push_back(e.dep);
arr.push_back(e.arr);
alts.insert(alts.end(), e.alts.begin(), e.alts.end());
alt_off.push_back((uint32_t)alts.size());
}
occ.push_back(Occ{ins.first->second, cid, qs});
++st.occurrences;
}
last_ref = (int64_t)k;
}
if (last_ref < 0) {
if (!hs.empty()) {
++st.no_ref_records;
++st.partial_walks;
for (Handle h : hs) { node_partial[handle_node(h)] = 1; ++st.partial_handles; }
}
} else if ((size_t)last_ref + 1 < hs.size()) { // partial walk end
++st.partial_walks;
for (size_t m = (size_t)last_ref + 1; m < hs.size(); ++m) { node_partial[handle_node(hs[m])] = 1; ++st.partial_handles; }
}
merge_ivs(cov);
rec_cov.insert(rec_cov.end(), cov.begin(), cov.end());
rec_cov_off.push_back((uint32_t)rec_cov.size());
}
rd.close();
exc_id.clear();
name_cache_.clear();
// does the GAF belong to this graph?
const uint64_t touching = st.projected + st.failed;
if (st.records > 0 && touching == 0)
fail(EXIT_INPUT, strf("GAF %s: none of its %llu records names a sequence or segment of this graph", path.c_str(),
(unsigned long long)st.records));
if (st.failed > 1 && st.failed * 100 > touching)
fail(EXIT_INPUT, strf("GAF %s: %llu of %llu records that touch this graph cannot be projected onto it (first: %s); "
"the GAF must come from mapping to this (unzipped) graph",
path.c_str(), (unsigned long long)st.failed, (unsigned long long)touching, st.first_failure.c_str()));
if (st.records == 0) ZLOG("warning: GAF %s has no mapped records: no site has observed walks", path.c_str());
// owners (one per contig, smallest query start) and weights (distinct haplotypes)
const size_t E = dep.size();
std::sort(occ.begin(), occ.end(), [](const Occ& a, const Occ& b) {
if (a.exc != b.exc) return a.exc < b.exc;
if (a.contig != b.contig) return a.contig < b.contig;
return a.qs < b.qs;
});
own_off.assign(1, 0);
weight.assign(E, 0);
{
std::vector<uint32_t> haps;
size_t i = 0;
for (uint32_t x = 0; x < (uint32_t)E; ++x) {
haps.clear();
while (i < occ.size() && occ[i].exc == x) {
if (own_contig.size() == own_off.back() || own_contig.back() != occ[i].contig) {
own_contig.push_back(occ[i].contig);
own_qs.push_back(occ[i].qs);
haps.push_back(contig_hap[occ[i].contig]);
}
++i;
}
own_off.push_back((uint32_t)own_contig.size());
std::sort(haps.begin(), haps.end());
weight[x] = (uint32_t)(std::unique(haps.begin(), haps.end()) - haps.begin());
}
}
std::vector<Occ>().swap(occ);
// kinds and windows
kind.assign(E, 0);
wlo.assign(E, 0);
whi.assign(E, 0);
for (uint32_t x = 0; x < (uint32_t)E; ++x) {
if (g.nodes[handle_node(dep[x])].sn != g.nodes[handle_node(arr[x])].sn) { kind[x] = KIND_X; continue; }
Excursion t;
t.dep = dep[x];
t.arr = arr[x];
kind[x] = (uint8_t)classify(g, t, wlo[x], whi[x]);
}
// node -> excursions
node_exc_off.assign(N + 1, 0);
{
std::vector<NodeId> nodes;
std::vector<std::pair<uint32_t, uint32_t>> pairs;
for (uint32_t x = 0; x < (uint32_t)E; ++x) {
nodes.clear();
for (uint32_t k = alt_off[x]; k < alt_off[x + 1]; ++k) nodes.push_back(handle_node(alts[k]));
std::sort(nodes.begin(), nodes.end());
nodes.erase(std::unique(nodes.begin(), nodes.end()), nodes.end());
for (NodeId n : nodes) pairs.push_back(std::make_pair(n, x));
}
std::sort(pairs.begin(), pairs.end());
for (const auto& pr : pairs) node_exc_off[pr.first + 1]++;
for (size_t n = 0; n < N; ++n) node_exc_off[n + 1] += node_exc_off[n];
node_exc.resize(pairs.size());
for (size_t k = 0; k < pairs.size(); ++k) node_exc[k] = pairs[k].second;
}
// node -> records
std::sort(node_rec_pairs.begin(), node_rec_pairs.end());
node_rec_pairs.erase(std::unique(node_rec_pairs.begin(), node_rec_pairs.end()), node_rec_pairs.end());
node_rec_off.assign(N + 1, 0);
for (const auto& pr : node_rec_pairs) node_rec_off[pr.first + 1]++;
for (size_t n = 0; n < N; ++n) node_rec_off[n + 1] += node_rec_off[n];
node_rec.resize(node_rec_pairs.size());
for (size_t k = 0; k < node_rec_pairs.size(); ++k) node_rec[k] = node_rec_pairs[k].second;
std::vector<std::pair<uint32_t, uint32_t>>().swap(node_rec_pairs);
// contig coverage
{
std::vector<std::vector<uint32_t>> recs(contig.size());
for (uint32_t r = 0; r < (uint32_t)rec_contig.size(); ++r) recs[rec_contig[r]].push_back(r);
ctg_cov_off.assign(1, 0);
std::vector<RefIv> v;
for (size_t c = 0; c < contig.size(); ++c) {
v.clear();
for (uint32_t r : recs[c]) v.insert(v.end(), rec_cov.begin() + rec_cov_off[r], rec_cov.begin() + rec_cov_off[r + 1]);
merge_ivs(v);
ctg_cov.insert(ctg_cov.end(), v.begin(), v.end());
ctg_cov_off.push_back((uint32_t)ctg_cov.size());
}
}
sn_contig.assign(NS, NONE);
for (uint32_t c = 0; c < (uint32_t)contig.size(); ++c)
if (contig_sn[c] >= 0) sn_contig[(size_t)contig_sn[c]] = c;
seconds = std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();
long rss1 = self_peak_rss_kb();
ZLOG("GAF %s (read with %s): %llu lines; %llu records: %llu projected, %llu for other graphs, %llu failed "
"(name %llu, misaligned %llu, overrun %llu, gap %llu, empty %llu, no link %llu, length %llu); %llu secondary and "
"%llu unmapped skipped",
path.c_str(), method.c_str(), (unsigned long long)st.lines, (unsigned long long)st.records, (unsigned long long)st.projected,
(unsigned long long)st.foreign, (unsigned long long)st.failed, (unsigned long long)st.f_name, (unsigned long long)st.f_misaligned,
(unsigned long long)st.f_overrun, (unsigned long long)st.f_gap, (unsigned long long)st.f_empty, (unsigned long long)st.f_no_link,
(unsigned long long)st.f_length, (unsigned long long)st.secondary, (unsigned long long)st.unmapped);
if (!st.first_failure.empty()) ZLOG("GAF first unprojectable record: %s", st.first_failure.c_str());
ZLOG("GAF: %zu contigs, %zu haplotypes; %llu excursion occurrences, %zu distinct; %llu partial walk ends (%llu alt handles); "
"%.1f s, peak RSS %.2f -> %.2f GB",
contig.size(), hap.size(), (unsigned long long)st.occurrences, E, (unsigned long long)st.partial_walks,
(unsigned long long)st.partial_handles, seconds, rss0 / 1048576.0, rss1 / 1048576.0);
if (!opt.dump_dir.empty()) write_dumps(opt.dump_dir);
}
GafIndex::~GafIndex() {
// the dumps are committed by main with the other outputs (gaf_dump_writers); uncommitted, the
// writers remove their temporary files
}
std::vector<AtomicWriter*> GafIndex::dump_writers() const {
std::vector<AtomicWriter*> v;
if (dump_exc_) v.push_back(dump_exc_.get());
if (dump_ctg_) v.push_back(dump_ctg_.get());
return v;
}
Excursion GafIndex::make_excursion(uint32_t id) const {
Excursion e;
e.dep = dep[id];
e.arr = arr[id];
e.alts.assign(alts.begin() + alt_off[id], alts.begin() + alt_off[id + 1]);
e.owners.reserve(own_off[id + 1] - own_off[id]);
for (uint32_t k = own_off[id]; k < own_off[id + 1]; ++k) {
uint32_t c = own_contig[k];
Owner o;
o.contig = contig[c];
o.sr = contig_sn[c] >= 0 ? g.sn_rank[(size_t)contig_sn[c]] : -1;
o.so = own_qs[k];
o.first = NONE;
o.run = NONE;
o.src = Src::GAF;
e.owners.push_back(std::move(o));
}
e.weight = weight[id];
e.src = Src::GAF;
return e;
}
void GafIndex::write_dumps(const std::string& dir) {
if (!make_dirs(dir)) fail(EXIT_IO, "cannot create --dump directory " + dir);
std::vector<uint32_t> order(n_exc());
std::iota(order.begin(), order.end(), 0u);
auto key_less = [&](uint32_t a, uint32_t b) {
if (dep[a] != dep[b]) return dep[a] < dep[b];
if (arr[a] != arr[b]) return arr[a] < arr[b];
return std::lexicographical_compare(alts.begin() + alt_off[a], alts.begin() + alt_off[a + 1], alts.begin() + alt_off[b],
alts.begin() + alt_off[b + 1]);
};
std::sort(order.begin(), order.end(), key_less);
dump_exc_.reset(new AtomicWriter(dir + "/gaf_excursions.tsv"));
dump_exc_->write("kind\twlo\twhi\tdep\tarr\talts\tweight\tn_contigs\tcontigs\n");
std::string line;
for (uint32_t x : order) {
line = strf("%s\t%lld\t%lld\t%s\t%s\t", kind[x] == KIND_X ? "X" : kind_name((Kind)kind[x]), (long long)wlo[x], (long long)whi[x],
g.handle_str(dep[x]).c_str(), g.handle_str(arr[x]).c_str());
for (uint32_t k = alt_off[x]; k < alt_off[x + 1]; ++k) {
if (k > alt_off[x]) line.push_back(',');
line += g.handle_str(alts[k]);
}
line += strf("\t%u\t%u\t", weight[x], own_off[x + 1] - own_off[x]);
std::vector<std::string> names;
for (uint32_t k = own_off[x]; k < own_off[x + 1]; ++k) names.push_back(contig[own_contig[k]]);
std::sort(names.begin(), names.end());
for (size_t k = 0; k < names.size(); ++k) {
if (k) line.push_back(',');
line += names[k];
}
line.push_back('\n');
dump_exc_->write(line);
}
dump_exc_->finish();
dump_ctg_.reset(new AtomicWriter(dir + "/gaf_contigs.tsv"));
dump_ctg_->write("contig\thaplotype\trecords\tgraph_sn\n");
std::vector<uint32_t> co(contig.size());
std::iota(co.begin(), co.end(), 0u);
std::sort(co.begin(), co.end(), [&](uint32_t a, uint32_t b) { return contig[a] < contig[b]; });
for (uint32_t c : co)
dump_ctg_->write(strf("%s\t%s\t%u\t%s\n", contig[c].c_str(), hap[contig_hap[c]].c_str(), contig_records[c],
contig_sn[c] >= 0 ? g.sn_names[(size_t)contig_sn[c]].c_str() : "."));
dump_ctg_->finish();
}
std::shared_ptr<const GafIndex> load_gaf(const Graph& g, const std::string& path, const Options& opt) {
return std::shared_ptr<const GafIndex>(new GafIndex(g, path, opt));
}
// ================================================================ GafWalks
namespace {
// observed excursions of a site: through its alt nodes, both anchors on its reference nodes
std::vector<uint32_t> site_observed(const GafIndex& gi, const Site& s) {
std::vector<uint32_t> ids;
for (NodeId n : s.alts)
for (uint32_t k = gi.node_exc_off[n]; k < gi.node_exc_off[n + 1]; ++k) ids.push_back(gi.node_exc[k]);
std::sort(ids.begin(), ids.end());
ids.erase(std::unique(ids.begin(), ids.end()), ids.end());
size_t m = 0;
for (uint32_t id : ids)
if (gi.anchored_in(s, id)) ids[m++] = id;
ids.resize(m);
return ids;
}
struct Counter {
std::atomic<uint64_t> v{0};
void add(uint64_t x) { if (x) v.fetch_add(x, std::memory_order_relaxed); }
unsigned long long get() const { return (unsigned long long)v.load(); }
};
} // namespace
struct GafWalks::Impl {
const Graph& g;
const Runs& runs;
std::shared_ptr<const GafIndex> gi;
CreatorWalks creator;
int64_t big = 5000;
// summary counters (site threads add to them)
Counter sites, observed, creator_matched_exc, runs_total;
Counter al_observed, al_same, al_widened, al_opened, al_narrowed, al_closed, al_partial, al_foreign, al_unobserved;
Counter al_blocked, al_empty, al_ok, al_partial_relax, al_partial_relax_bp;
// creator reconstruction exactness (as the design prototype measured it): all sites / sites with <= 6000 alt nodes (the
// the prototype's --max-alts); exact walk, and anchors only (the spec's 175/199 and 168/191)
Counter cr_cmp, cr_exact, cr_anch, cr_cmp_big, cr_exact_big, cr_anch_big, cr_absent, cr_not_own;
Counter cr6_cmp, cr6_exact, cr6_anch, cr6_cmp_big, cr6_exact_big, cr6_anch_big;
// observed excursions of the site that are not creator excursions, by count and by contigs
// (the prototype's obs-not-in-rf; the spec's 13-16%)
Counter ob_exc, ob_exc_ctg, ob_notin, ob_notin_ctg, ob6_exc, ob6_exc_ctg, ob6_notin, ob6_notin_ctg;
// rule (G): piece checks, records scanned, pieces whose node's records read the target, time
Counter g_checks, g_records, g_hits, g_nanos;
Impl(const Graph& g_, const Runs& r_, std::shared_ptr<const GafIndex> gi_, const Options& opt)
: g(g_), runs(r_), gi(std::move(gi_)), creator(g_, r_), big(opt.b) {}
};
GafWalks::GafWalks(const Graph& g, const Runs& runs, const std::string& path, const Options& opt)
: impl_(new Impl(g, runs, load_gaf(g, path, opt), opt)) {}
GafWalks::GafWalks(const Graph& g, const Runs& runs, std::shared_ptr<const GafIndex> index, const Options& opt)
: impl_(new Impl(g, runs, std::move(index), opt)) {}
GafWalks::~GafWalks() {
if (unwinding() || !impl_) return;
Impl& m = *impl_;
if (m.sites.get() == 0) return;
ZLOG("gaf walks: %llu sites, %llu observed excursions (%llu equal a creator excursion)", m.sites.get(), m.observed.get(),
m.creator_matched_exc.get());
ZLOG("gaf walks: Allowed of %llu alt nodes crossed by observed excursions: ok %llu, empty %llu, blocked %llu; versus strict: "
"%llu same, %llu widened, %llu opened, %llu narrowed, %llu closed; kept strict: %llu (partial walk; %llu of them, %llu bp, "
"would have been widened or opened), %llu (foreign excursion); %llu alt nodes unobserved",
m.al_observed.get(), m.al_ok.get(), m.al_empty.get(), m.al_blocked.get(), m.al_same.get(), m.al_widened.get(),
m.al_opened.get(), m.al_narrowed.get(), m.al_closed.get(), m.al_partial.get(), m.al_partial_relax.get(),
m.al_partial_relax_bp.get(), m.al_foreign.get(), m.al_unobserved.get());
ZLOG("gaf walks: runs whose creator contig walks the run's first node: %llu; the creator excursion equals one of those observed "
"excursions for %llu (anchors equal: %llu); runs >= %lld bp: %llu of %llu (anchors %llu of %llu); in sites with <= 6000 alt "
"nodes: %llu (%llu) of %llu, >= %lld bp: %llu (%llu) of %llu; creator contig absent from the GAF %llu, not on its own node %llu",
m.cr_cmp.get(), m.cr_exact.get(), m.cr_anch.get(), (long long)m.big, m.cr_exact_big.get(), m.cr_cmp_big.get(),
m.cr_anch_big.get(), m.cr_cmp_big.get(), m.cr6_exact.get(), m.cr6_anch.get(), m.cr6_cmp.get(), (long long)m.big,
m.cr6_exact_big.get(), m.cr6_anch_big.get(), m.cr6_cmp_big.get(), m.cr_absent.get(), m.cr_not_own.get());
auto pct = [](unsigned long long a, unsigned long long b) { return b ? 100.0 * (double)a / (double)b : 0.0; };
ZLOG("gaf walks: observed excursions that are not creator excursions: %llu of %llu (%.1f%%), %.1f%% weighted by contigs; in sites "
"with <= 6000 alt nodes %llu of %llu (%.1f%%), %.1f%% by contigs",
m.ob_notin.get(), m.ob_exc.get(), pct(m.ob_notin.get(), m.ob_exc.get()), pct(m.ob_notin_ctg.get(), m.ob_exc_ctg.get()),
m.ob6_notin.get(), m.ob6_exc.get(), pct(m.ob6_notin.get(), m.ob6_exc.get()), pct(m.ob6_notin_ctg.get(), m.ob6_exc_ctg.get()));
ZLOG("gaf walks: rule (G): %llu piece check(s), %llu GAF record(s) scanned, %.3f s; %llu piece(s) whose node a record walks that "
"also reads the target",
m.g_checks.get(), m.g_records.get(), (double)m.g_nanos.get() / 1e9, m.g_hits.get());
}