Created
December 6, 2012 05:08
-
-
Save informationsea/4221948 to your computer and use it in GitHub Desktop.
Extract records from multi-fasta
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 python2.7 | |
""" | |
Extract records from multi-fasta | |
""" | |
__author__ = 'Yasunobu OKAMURA' | |
__copyright__ = 'Copyright (C) 2012 Yasunobu OKAMURA All Rights Reserved.' | |
import argparse | |
import sys | |
import Bio.SeqIO | |
import Bio.Seq | |
import Bio.SeqRecord | |
def _main(): | |
parser = argparse.ArgumentParser(description='Extract records') | |
parser.add_argument('input') | |
parser.add_argument('query') | |
parser.add_argument('output', default=sys.stdout, nargs='?', type=argparse.FileType('w')) | |
options = parser.parse_args() | |
for record in Bio.SeqIO.parse(options.input, "fasta"): | |
if options.query in record.id: | |
Bio.SeqIO.write(record, options.output, 'fasta') | |
print >>sys.stderr, "{} record/s found".format(found_count) | |
if __name__ == '__main__': | |
_main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment