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.
Fix endianness problems outwith CRAM code

In swap_data(), for 'B' we must copy the count into  n  when it is in
host format.  In test/sam.c, the same count is in host format while we
are checking it.  Hat tip @azlicic, cf #99; partial fix for #98.
Set NM/MD creation to be on by default.

Also amended the test harness to ignore NM and MD changes.  This isn't
ideal, but as we have no explicit tests for the validity of NM or MD
at the moment then it is sufficient.
synced_reader: Removed unused code
vcf: Change of bcf_hdr_add_sample() usage.

To increase performance with thousands of samples, bcf_hdr_sync() is called
only when explicitly requested by passing NULL.
Add sam_open_mode() API function

Aids in parsing options like -Ocram.  Requires documentation, but we'll
add that when we're sure the API is stable (in particular, having the
caller pre-supply the "w" is perhaps not ideal).
Remove val_unused -- use HTS_UNUSED instead

This macro is in the HTS namespace, so less collision-prone.
bcf_write: Error message instead of assert + propagate the error up
vcf_parse: Detect incorrect number of columns
vcf: Fix BCF syncing when only partially unpacked
vcf: Fixes in bcf_translate
bgzf: Do not end prematurely on non-critical Z_BUF_ERROR zlib error
vcf: Fix bcf_hdr_id2hrec, col_type parameter is needed as well
bcf_trim_als: Propagate error instead of assert