1

I'm translating a Perl code to a Python code using BioPython.

I got something like:

my $db = Bio::DB::Fasta->new($path,$options)

and I'm looking for a similar function in Biopython. Is there anything like this?

xbello
  • 7,223
  • 3
  • 28
  • 41
  • There is no Fasta support in the standard libraries, and [SO] isn't a good resource for recommending anything outside the standard libraries. Having said that, it looks like https://pypi.python.org/pypi/pyfaidx exists and is recently maintained. Good luck! – Robᵩ Sep 08 '16 at 19:39

1 Answers1

1

You can find the IO for FASTA files at http://biopython.org/DIST/docs/api/Bio.SeqIO-module.html

About the indexing, I think Biopython doesn't handle '.fai' files like Bio::DB:Fasta. You can have a dictionary (like a perl hash) using the SeqIO.index() method. This is a quick example as shown in the docs:

from Bio import SeqIO
record_dict = SeqIO.index("fasta_file.fas", "fasta")

print(record_dict["ID of the fasta sequence"])

SeqIO.index creates a dict in memory to allow random access to each sequence. Read the docs to view the limitations of that dict: http://biopython.org/DIST/docs/api/Bio.File._IndexedSeqFileDict-class.html

xbello
  • 7,223
  • 3
  • 28
  • 41