Skip to content

Instantly share code, notes, and snippets.

@konrad
Last active October 19, 2016 07:50
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 konrad/a06de1ba63356cb524e2 to your computer and use it in GitHub Desktop.
Save konrad/a06de1ba63356cb524e2 to your computer and use it in GitHub Desktop.
Split a multi entry fasta file into several files with on entry
import argparse
from Bio import SeqIO
parser = argparse.ArgumentParser(
description="Split a multi entry fasta file into several files "
"with one entry")
parser.add_argument("input_file")
parser.add_argument("output_prefix")
args = parser.parse_args()
for seq_record in SeqIO.parse(args.input_file, "fasta"):
with open(args.output_prefix + seq_record.id + ".fa", "w") as output_fh:
output_fh.write(">{}\n{}\n".format(
seq_record.id, str(seq_record.seq)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment