Created
May 30, 2013 08:20
-
-
Save informationsea/5676463 to your computer and use it in GitHub Desktop.
Split FASTA file to individual entries
This file contains hidden or 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 Bio.SeqIO | |
import argparse | |
import re | |
import os.path | |
def cleanup_text(name): | |
""" | |
Arguments: | |
- `name`: | |
""" | |
return re.sub(r'[^0-9a-zA-Z\s\-]', '_', name) | |
def _main(): | |
parser = argparse.ArgumentParser(description='Split') | |
parser.add_argument('input', help='input fasta') | |
parser.add_argument('output', help='Output directory') | |
options = parser.parse_args() | |
for record in Bio.SeqIO.parse(options.input, 'fasta'): | |
with file(os.path.join(options.output, record.id+'.fa'), 'w') as f: | |
Bio.SeqIO.write([record], f, 'fasta') | |
if __name__ == '__main__': | |
_main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment