Graph File format

Extension: .ctx
Version in use: 6

*******************************
Binary File Format Version 6:

version+ | datatype | no. elements | Notes
--------------------------------------------------------------------------------
 Header start:
--------------------------------------------------------------------------------
4 | uint8_t  |    6   | the string "CORTEX" (Note: not null-terminated)
--------------------------------------------------------------------------------
 Header:
--------------------------------------------------------------------------------
4 | uint32_t |    1   | version number
4 | uint32_t |    1   | kmer size (<kmer_size>)
4 | uint32_t |    1   | number of uint64_t (64 bit words) encoding a kmer (<W>)
4 | uint32_t |    1   | number of colours (<cols>)
4 | uint32_t | <cols> | mean read length for each colour
4 | uint64_t | <cols> | total sequence loaded into each colour
--------------------------------------------------------------------------------
 Sample names (repeated <col> times):
--------------------------------------------------------------------------------
6 | uint32_t |   1   | length of sample name of i-th colour (<len>)
6 | uint8_t  | <len> | sample name for colour i (Note: not null-terminated)
--------------------------------------------------------------------------------
 Sequencing error rate:
--------------------------------------------------------------------------------
6 | long double | <cols> | estimated sequencing error rate for each colour
--------------------------------------------------------------------------------
 Sample cleaning (repeated <col> times):
--------------------------------------------------------------------------------
6 | uint8_t  |   1   | was there top clipping (0x1=yes | 0x0=no)
6 | uint8_t  |   1   | was --remove_low_covg_supernodes used (0x1=yes | 0x0=no)
6 | uint8_t  |   1   | was --remove_low_covg_kmers used (0x1=yes | 0x0=no)
6 | uint8_t  |   1   | was this colour cleaned against a graph (0x1=yes | 0x0=no)
6 | uint32_t |   1   | threshold for --remove_low_coverage_supernodes (0 if not used)
6 | uint32_t |   1   | threshold for --remove_low_coverage_kmer (0 if not used)
6 | uint32_t |   1   | length of name of graph against which this colour was cleaned (<len>)
6 | uint8_t  | <len> | name of graph against which this colour was cleaned
--------------------------------------------------------------------------------
 Header end:
--------------------------------------------------------------------------------
4 | uint8_t  |   6   | the string "CORTEX" (Note: not null-terminated)
--------------------------------------------------------------------------------
 Kmers (repeated <kmers> times -- there may be zero or more of these entries):
--------------------------------------------------------------------------------
4 | uint64_t |  <W>  | binary kmer
4 | uint32_t | <col> | array of coverage values for colours 0..<col-1>
4 | uint8_t  | <col> | array of 'Edge' chars (see Notes) for colours 0..<col-1>
--------------------------------------------------------------------------------

======
Notes:
======

* All string are NOT null-terminated.

* <W> is set in the header, and is defined as the minimum number of 64 bit words
  required to store a kmer of length <kmer_size> bases (2 bits needed per base):

    W*32 >= kmer_size > (W-1)*32

  64 bit words are also known as uint64_t

* An 'Edge' char is an 8 bit bytes.  Each kmer has one of them for each colour
  (i.e. <col> of them).  The top 4 most significant bits represent edges to the
  left of the kmer and the 4 least significant bits represent edges to the right
  of the kmer.  

  Example: Kmer ACCGT has edge char 10100100 (i.e. 164 in decimal, or 0xA4 in hex)
        
    10100100
    | |  |
    tgcaACGT  (lowercase means before kmer, uppercase means after)
    t c  C  

  so this kmer if preceeded by a T or C and followed by a C: [TC]ACCGT[C]



*******************************
Binary File Format Version 5:
Identical for v4, except coverage is written as uint32_t.



*******************************
Binary File format Version 4:

Header: 6 chars (the word "CORTEX")
        1 int (version number)
        1 int (kmer size)
        1 int (number of long longs encoding the kmer)
        1 int (number of colours = num_cols)
        num_cols ints (mean read length for each colour)
        num_cols long longs (total sequence loaded into each colour)
        6 chars (the word "CORTEX")
Followed by consecutive nodes. Each node consists of:
        1 BinaryKmer (defined in include/basic/binary_kmer.h
        1 int (coverage)
        1 char (typedefed to Edges)
