Skip to content

Instantly share code, notes, and snippets.

@dceoy
Created July 10, 2019 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dceoy/7e6cf50e805fdc9df3840a56c0cacd69 to your computer and use it in GitHub Desktop.
Save dceoy/7e6cf50e805fdc9df3840a56c0cacd69 to your computer and use it in GitHub Desktop.
[Python] Read a FASTA file using Biopython
#!/usr/bin/env python
import bz2
import gzip
from Bio import SeqIO
def read_fasta(path):
if path.endswith('.gz'):
f = gzip.open(path, 'rt')
elif path.endswith('.bz2'):
f = bz2.open(path, 'rt')
else:
f = open(path, 'r')
records = SeqIO.to_dict(SeqIO.parse(f, 'fasta'))
f.close()
return records
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment