1 \documentclass[10pt]{article}
3 \definecolor{gray}{rgb}{0.7,0.7,0.7}
5 \setlength{\topmargin}{0.0cm}
6 \setlength{\textheight}{21.5cm}
7 \setlength{\oddsidemargin}{0cm}
8 \setlength{\textwidth}{16.5cm}
9 \setlength{\columnsep}{0.6cm}
13 \title{The Tabix index file format}
20 \begin{tabular}{|l|l|l|l|l|l|l|}
22 \multicolumn{4}{|c|}{\bf Field} & \multicolumn{1}{c|}{\bf Descrption} & \multicolumn{1}{c|}{\bf Type} & \multicolumn{1}{c|}{\bf Value} \\
24 \multicolumn{4}{|l|}{\tt magic} & Magic string & {\tt char[4]} & TBI$\backslash$1 \\
26 \multicolumn{4}{|l|}{\tt n\_ref} & \# sequences & {\tt int32\_t} & \\
28 \multicolumn{4}{|l|}{\tt format} & Format (0: generic; 1: SAM; 2: VCF) & {\tt int32\_t} & \\
30 \multicolumn{4}{|l|}{\tt col\_seq} & Column for the sequence name & {\tt int32\_t} & \\
32 \multicolumn{4}{|l|}{\tt col\_beg} & Column for the start of a region & {\tt int32\_t} & \\
34 \multicolumn{4}{|l|}{\tt col\_end} & Column for the end of a region & {\tt int32\_t} & \\
36 \multicolumn{4}{|l|}{\tt meta} & Leading character for comment lines & {\tt int32\_t} & \\
38 \multicolumn{4}{|l|}{\tt skip} & \# lines to skip at the beginning & {\tt int32\_t} & \\
40 \multicolumn{4}{|l|}{\tt l\_nm} & Length of concatenated sequence names & {\tt int32\_t} & \\
42 \multicolumn{4}{|l|}{\tt names} & Concatenated names, each zero terminated & {\tt char[l\_nm]} & \\
44 \multicolumn{7}{|c|}{\textcolor{gray}{\it List of indices (n=n\_ref)}}\\
46 \hspace{0.1cm} & \multicolumn{3}{l|}{\tt n\_bin} & \# distinct bins (for the binning index) & {\tt int32\_t} & \\
48 & \multicolumn{6}{c|}{\textcolor{gray}{\it List of distinct bins (n=n\_bin)}} \\
50 & \hspace{0.1cm} & \multicolumn{2}{l|}{\tt bin} & Distinct bin number & {\tt uint32\_t} & \\
52 & & \multicolumn{2}{l|}{\tt n\_chunk} & \# chunks & {\tt int32\_t} & \\
54 & & \multicolumn{5}{c|}{\textcolor{gray}{\it List of chunks (n=n\_chunk)}} \\
56 & & \hspace{0.1cm} & {\tt cnk\_beg} & Virtual file offset of the start of the chunk & {\tt uint64\_t} & \\
58 & & & {\tt cnk\_end} & Virtual file offset of the end of the chunk & {\tt uint64\_t} & \\
60 & \multicolumn{3}{l|}{\tt n\_intv} & \# 16kb intervals (for the linear index) & {\tt int32\_t} & \\
62 & \multicolumn{6}{c|}{\textcolor{gray}{\it List of distinct intervals (n=n\_intv)}} \\
64 & & \multicolumn{2}{l|}{\tt ioff} & File offset of the first record in the interval & {\tt uint64\_t} & \\
72 \item The index file is BGZF compressed.
73 \item All integers are little-endian.
74 \item When {\tt (format\&0x10000)} is true, the coordinate follows the
75 {\tt BED} rule (i.e. half-closed-half-open and zero based); otherwise,
76 the coordinate follows the {\tt GFF} rule (closed and one based).
77 \item For the SAM format, the end of a region equals {\tt POS} plus the
78 reference length in the alignment, inferred from {\tt CIGAR}. For the
79 VCF format, the end of a region equals {\tt POS} plus the size of the
81 \item Field {\tt col\_beg} may equal {\tt col\_end}, and in this case,
82 the end of a region is {\tt end}={\tt beg+1}.
83 \item Example. For {\tt GFF}, {\tt format}=0, {\tt col\_seq}=1, {\tt
84 col\_beg}=4, {\tt col\_end}=5, {\tt meta}=`{\tt \#}' and {\tt
85 skip}=0. For {\tt BED}, {\tt format}=0x10000, {\tt col\_seq}=1, {\tt
86 col\_beg}=2, {\tt col\_end}=3, {\tt meta}=`{\tt \#}' and {\tt
88 \item Given a zero-based, half-closed and half-open region {\tt
89 [beg,end)}, the {\tt bin} number is calculated with the following C
92 int reg2bin(int beg, int end) {
94 if (beg>>14 == end>>14) return ((1<<15)-1)/7 + (beg>>14);
95 if (beg>>17 == end>>17) return ((1<<12)-1)/7 + (beg>>17);
96 if (beg>>20 == end>>20) return ((1<<9)-1)/7 + (beg>>20);
97 if (beg>>23 == end>>23) return ((1<<6)-1)/7 + (beg>>23);
98 if (beg>>26 == end>>26) return ((1<<3)-1)/7 + (beg>>26);
102 \item The list of bins that may overlap a region {\tt [beg,end)} can be
103 obtained with the following C function.
105 #define MAX_BIN (((1<<18)-1)/7)
106 int reg2bins(int rbeg, int rend, uint16_t list[MAX_BIN])
111 for (k = 1 + (rbeg>>26); k <= 1 + (rend>>26); ++k) list[i++] = k;
112 for (k = 9 + (rbeg>>23); k <= 9 + (rend>>23); ++k) list[i++] = k;
113 for (k = 73 + (rbeg>>20); k <= 73 + (rend>>20); ++k) list[i++] = k;
114 for (k = 585 + (rbeg>>17); k <= 585 + (rend>>17); ++k) list[i++] = k;
115 for (k = 4681 + (rbeg>>14); k <= 4681 + (rend>>14); ++k) list[i++] = k;
116 return i; // #elements in list[]