Created
July 10, 2019 04:31
-
-
Save dceoy/7e6cf50e805fdc9df3840a56c0cacd69 to your computer and use it in GitHub Desktop.
[Python] Read a FASTA file using Biopython
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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