Skip to content

Instantly share code, notes, and snippets.

@Rajan-sust
Last active September 28, 2021 07:08
Show Gist options
  • Save Rajan-sust/bf251be9a9782ed71bb629ccabaf2440 to your computer and use it in GitHub Desktop.
Save Rajan-sust/bf251be9a9782ed71bb629ccabaf2440 to your computer and use it in GitHub Desktop.
import argparse
from Bio import SeqIO
from Bio.SeqRecord import SeqRecord
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--id_file', required=True,
help='file path of ids in text format')
parser.add_argument('--input', required=True,
help='path of fasta sequence')
parser.add_argument('--output', required=True,
help='path of selected fasta sequence')
args = parser.parse_args()
with open(args.id_file, mode='r', encoding='utf-8') as file:
ids = set(file.read().splitlines())
records = [SeqRecord(record.seq, id=record.id, description='', name='') for record in SeqIO.parse(args.input, 'fasta')
if record.id in ids]
SeqIO.write(records, args.output, "fasta")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment