mdshw5 / pyfaidx

Efficient pythonic random access to fasta subsequences
https://pypi.python.org/pypi/pyfaidx
Other
459 stars 75 forks source link

Load an existing .fai? #169

Closed rickbeeloo closed 4 years ago

rickbeeloo commented 4 years ago

I have a huge Fasta file and it takes a while to create the .fai file. So I suppose I don't keep recreating the index and just load the .fai rather than passing the .fasta to Fasta again. However, after reading the documentation I cannot find any function that accepts an existing .fai to extract information from? or is the index automatically loaded when already present?

mdshw5 commented 4 years ago

If there is an existing.fai file then Fasta will read that index and will not create a new one. However, if the modification time of the.fai file is older than the.fasta, we assume that the contents of the .fasta have changed and will rebuild a new index .fai file. The .fai file name is based on the .fasta file name, so there is no need to ever specify its path. Here's the code that actually makes this work:

https://github.com/mdshw5/pyfaidx/blob/master/pyfaidx/__init__.py#L422-L446

Thanks for reaching out and let me know if you encounter any issues related to loading an existing index file!