Raise error if give @HD SO:coordinate to 'samtools fixmate'

The (minimal) documentation does tell you 'samtools fixmate' requires query name
sorted reads (in fact grouped by query name is enough), but doesn't actually raise
an error if given coordinate sorted reads (it just silently fails to fix them).

This change raises an explicit error is the @HD line contains SO:coordinate
Catch overflow in n_cigar and give an explicit error.

Due to the use of an unsigned 16bit integer, BAM
files can only hold reads with up to 65535 CIGAR
operators. SAM does not have this limit, but the
samtools implementation (reasonably) also has the
same 16bit limit.

Prior to this fix a very long CIGAR read would
give a confusing 'unmatched CIGAR operation'
warning and then abort with a core dump.
Don't set text-is-cached flag if reading headers encountered EOF

Only set is_first (i.e., some SAM record text has already been read
in) if a column of the following SAM record has actually been pre-read.
This will not be the case if there are no records at all, only headers.

Fixes #113 (hattip @kmsquire).
Merge pull request #20, fixmate aborts on SO:coordinate
Fix buffer overflow
Reenable idxstats and convert to htslib

Reenable idxstats code by using new functions added to htslib.
Convert API for index and idxstats to htslib.

Signed-off-by: Martin O. Pollard <mp15@sanger.ac.uk>
Remove double fclose()

This fixes issue #47 for the legacy non-HTSlib code branch.
Silence -Wstrict-prototypes warnings in main header files

Fixes issue #45 for the legacy non-HTSlib code branch.
mpileup: Long options

[Add long options as per eb2b30907ada8dc77b2d373dcf36ea6b8b9d64d2, but
without removing existing -a/-D/-M/-S/-V/--ff/--rf options or creating
new -1/-2 short options --- @jmarshall]
Create a print_usage() function for usage printing

The source code text is unchanged, modulo whitespace and s/./->/g.
Reformat usage to (mostly) fit in 80 columns

This uses the typical GNU-style spacing (e.g., two leading spaces on
option lines) and removes brackets around <FILE> etc, as the capitals
used distinguishes them without using up characters.
Minor rewording of usage to fit in 80 columns
Deprecate `-S`, `-D`, `-V` in favour of `-t DP,DV,SP`

- Deprecate `-S`, `-D`, `-V` by hiding in short help.
- Options still exist, but warning to stderr is printed when used.
- Updated man for (just) these options.
Fix long option has_arg inconsistencies
some progress for mpileup documentation

- add missing options to the command line summary
- add missing and long options to the man page (#127)
- option `-a` removed as it implemented the default and was hidden anyway (#127)
- change to pileup output description in response to (#134)
- pileup command long since deprecated in favour of mpileup
- still needs work
Use getopt.h's descriptive constants in long options array

Also fix --illumina1.3+ short option equivalent.
Remove mpileup -M option, which has never been implemented

(Fixes #132.)
mpileup: Per-sample rather than cumulative QS. (experimental)

Allele frequency estimate (QS) is calculated per-sample rather
than summed over all samples. This should make the calling more
robust to uneven read depths across samples.
Ruthlessly tidied up the examples directory.

The Makefile and C programs are gone. They didn't build and mostly
were redundant anyway. Arguably chk_indel.c and bam2bed.c could still
have a use, but as toy examples they would belong in an htslib rather
than here anyway.

The README file was updated to use more modern command alternatives
(view vs import, mpileup vs pileup), but does not yet contain any
references to CRAM.  This can be added once -T is working.
Revert to ex1.sam.gz; fix mpileup command lines

At present there doesn't seem to be any way to get mpileup to read
@SQ-headerless SAM files, so use the BAM files in the example instead.