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
//! Native reader and writer for odgi's binary graph format (`.og`).
//!
//! The layout mirrors odgi's `graph_t::serialize` (libhandlegraph `Serializable`
//! with odgi's `node_t` records and DYNAMIC's `hacked_vector`). All integers are
//! little-endian except the leading magic number:
//!
//! ```text
//! u32 BE magic (1988148666)
//! u64 ×7 max_node_id, min_node_id, node_count, edge_count, path_count,
//! path_handle_next, id_increment
//! node_count × node record (node rank r has id r + 1 + id_increment):
//! u64 sequence length, sequence bytes, u64 id (0 marks a deleted node)
//! packed edges (other node id, other_rev | on_rev << 1 | to_curr << 2) pairs
//! packed decoding deltas to neighbor ids (0 = this node, odd = higher, even = lower)
//! packed steps (path, rev | start << 1 | end << 2 | del << 3,
//! prev, prev rank, next, next rank) where prev/next index decoding
//! path_count × path: u64 length, first step (u64 handle, u64 rank),
//! last step (u64 handle, u64 rank), u64 name length, name bytes
//! packed = u64 word count, words, u64 mask, u64 length, u8 width, u8 values per word
//! ```
//!
//! Edges are stored on both of their nodes (`to_curr` on the right one, self loops
//! once). A path is a linked list of steps; a step is named by its node handle
//! (`rank << 1 | is_reverse`) and its rank among the steps stored on that node.
//!
//! `docs/odgi_format.md` describes every field in detail, with a worked example
//! decoded from `odgi build` output; `utils/dump_odgi.py` prints a file's fields.
//!
//! Code map: `encoding` (little-endian integers and packed vectors, both
//! directions), `reader` (`records`: node records, `paths`: walking the step
//! lists) and `writer` (`numbering`: odgi ids, `edges` and `steps`: per-node
//! indexes of the records to write).
use crateNodeId;
use crateCoreGraphDTO;
use cratePanResult;
use crate;
use ;
/// Codec for odgi's binary graph format.
///
/// Node ids are written as odgi ids: numeric node names are kept when they are
/// distinct positive integers that fit a dense id range (as `odgi build` keeps
/// GFA segment ids), otherwise nodes are numbered `1..=n`. Parsed nodes are named
/// by their odgi id. Overlaps are not part of the format and are dropped.
;
/// libhandlegraph magic number of odgi's `graph_t`.
pub const ODGI_MAGIC: u32 = 1_988_148_666;
/// Values per edge record and per step record in a node.
pub const EDGE_RECORD_LEN: usize = 2;
pub const STEP_RECORD_LEN: usize = 6;
/// Bits of a packed edge.
pub const EDGE_OTHER_REV: u64 = 1;
pub const EDGE_ON_REV: u64 = 1 << 1;
pub const EDGE_TO_CURR: u64 = 1 << 2;
/// Bits of a step type.
pub const STEP_REV: u64 = 1;
pub const STEP_START: u64 = 1 << 1;
pub const STEP_END: u64 = 1 << 2;
/// Largest rank of a step on its node that is read or written (the
/// reader packs ranks into 31 bits).
pub const MAX_STEP_RANK: u32 = u32MAX >> 1;
/// Marks a deleted node rank.
pub const VACANT: NodeId = MAX;