Mercurial > repos > bvalot > fasta_filter_0_1
diff fasta_filter_to_accession.py @ 0:bc23da9d464c draft default tip
planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
author | bvalot |
---|---|
date | Tue, 14 Jun 2022 08:15:55 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fasta_filter_to_accession.py Tue Jun 14 08:15:55 2022 +0000 @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +"""Return a filter fasta file for list of accession""" + +import argparse +import sys + +from Bio import SeqIO + +desc = "Filter a fasta file based on ." +command = argparse.ArgumentParser( + prog="fasta_filter_to_accession", + description=desc, + usage="%(prog)s [options] fasta accessions", +) +command.add_argument( + "-o", + "--output", + default=sys.stdout, + type=argparse.FileType("w"), + nargs="?", + help="Output result to, default:stdout", +) +command.add_argument("fasta", type=argparse.FileType("r"), help="Fasta file to filter") +command.add_argument( + "access", + metavar="accessions", + type=str, + nargs="+", + help="List of accession to extract", +) + +if __name__ == "__main__": + """Performed job on execution script""" + args = command.parse_args() + output = args.output + access = set(args.access) + for seq in SeqIO.parse(args.fasta, "fasta"): + if seq.id in access: + SeqIO.write(seq, output, "fasta") + access.remove(seq.id) + if len(access) > 0: + sys.stderr.write("Accessions not found : " + str(" - ").join(access) + "\n")