idx: Don't create broken .tbi or .csi when file unsorted (VCF/BCF/BAM)
Sanitised the setting of fd->empty_container into one place. This also
fixes the samtools bug #146.

https://github.com/samtools/samtools/issues/146
Fix forgotten s/razip/bgzip/

Since 9ec7860705a613c659992c437379a2f1374c71ac, fai_build() can read
BGZF-compressed files but no longer RAZF-compressed files.
Remove RAZF source code

Samtools no longer uses RAZF files, and the code has been unmaintained
in htslib so it is not really useful to have it here.  RAZF source code
remains available in older samtools releases and on the samtools
repository's `standalone` branch.

(This answers #74 regarding razf.o being omitted from $(LIBHTS_OBJS),
whence it was incidentally removed by 65617469ffb8e790280448d2d8d61a984135e39b.)
Check CIGAR string has fewer than 2^16 operators

This limit may be raised in the BAM format and htslib in the future,
but for now ensure there is a relevant message when you exceed the
current limit.  Fixes issue samtools/samtools#39 for htslib-based code.
Add a comment to deobfuscate bam_cigar_type

(Closes #96 by cherry-picking ba16f86.)
Fix "unrecognized CIGAR operator" diagnostic

Initialise the rest of the table to -1, not 0 ("M").
Removed bogus "Unable to find ref name"* errors when converting a SAM
file UR:local/path/name syntax and without finding an MD5 reference to
use. The code previously went on to work fine as a subsequent refs2id
call worked.

This is avoided in Staden io_lib by the use of a scram_set_refs()
function which is called on the result of a scram_get_refs() call on a
SAM/BAM file, returning NULL and then resetting fd->refs to NULL.

We have no such call in HTSlib, but can resolve it by a smarter
implementation of cram_load_reference().
Add functions for idxstats

Add functions to access inside hts_idx_t and retrieve stats.

Signed-off-by: Martin O. Pollard <mp15@sanger.ac.uk>
Improve hts_idx_get_stat to work for more file types

Add META_BIN macro to get meta bin rather than putting idx->n_bins + 1 everywhere.
Alter hts_idx_get_stat to use META_BIN rather than constant and work for BAI, CSI and tabix.

Signed-off-by: Martin O. Pollard <mp15@sanger.ac.uk>
Return 0/-1 rather than bool; parenthesise C macro

Returning -1 for failure is the existing htslib convention.
Merge API functions for index statistics (PR #83)
sam_hdr_write() now calls cram_load_reference if
hts_set_fai_filename() has been called.  Also refs_load_fai() now
copes with being given foo.fa or foo.fa.fai and does the right thing.

https://github.com/samtools/samtools/issues/144
Check index file magic numbers and I/O

Reading a BAI, CSI, or tabix index file should fail if the magic number
is incorrect, the file is truncated (or reading otherwise fails), or
memory allocation fails.  There is probably further consistency checking
that could be done too.  Fixes samtools/samtools#47.