Last active
September 28, 2021 07:08
-
-
Save Rajan-sust/bf251be9a9782ed71bb629ccabaf2440 to your computer and use it in GitHub Desktop.
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
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