<p>I have a series of BWA index files ( *.amb *.ann *.bwt, etc) but the original reference fasta sequences are not available. Assuming that it&#39;s a complete burrows-wheeler index, the complete reference should be encoded in those indices.</p>

<p>Does anyone know if/how the fasta can be re-extracted from them?</p>

This is an interesting question. It definitely should be possible, so I guess the question may be how to do it with existing tools and the least amount of pain.

I looked into it, and it seems that from the [original bwtsw code][1] (that bwa relies on, particularly for the indexing steps), the "packed" fasta file (`pac`) is the key file to use. This is supported by looking at the order of the indexing substeps of `fa2pac`, `pac2bwt`, and finally `bwt2sa`.

So as an informed guess I searched for "pac2fasta", and (surprisingly to me) found an existing utility in the [TMAP package][2]. I believe, based on some quick tests, that the binary format for their `pac` file is the same as bwa uses (and bwtsw), aside from some embedded version numbers. The only catch is that TMAP has a binary annotation file (`$ref.tmap.anno`) that stores the chromosome names and lengths, whereas bwa uses a plaintext annotation file (`$ref.ann`). So if this is really what you want to do, it looks like you'll have to hardcode things (that's what I did to test with a small single chromosome reference) or write some code to make a TMAP annotation file from a bam header or bwa `.ann` file (by working through `tmap_refseq_write_header` in [tmap_refseq.c][3]).

 [1]: https://github.com/mruffalo/bwt-sw
 [2]: https://github.com/iontorrent/TMAP/
 [3]: https://github.com/iontorrent/TMAP/blob/master/src/index/tmap_refseq.c