annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
1 #!/usr/bin/env python3
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
2 # -*- coding: utf-8 -*-
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
3
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
4 """Return a filter fasta file for list of accession"""
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
5
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
6 import argparse
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
7 import sys
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
8
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
9 from Bio import SeqIO
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
10
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
11 desc = "Filter a fasta file based on ."
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
12 command = argparse.ArgumentParser(
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
13 prog="fasta_filter_to_accession",
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
14 description=desc,
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
15 usage="%(prog)s [options] fasta accessions",
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
16 )
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
17 command.add_argument(
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
18 "-o",
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
19 "--output",
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
20 default=sys.stdout,
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
21 type=argparse.FileType("w"),
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
22 nargs="?",
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
23 help="Output result to, default:stdout",
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
24 )
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
25 command.add_argument("fasta", type=argparse.FileType("r"), help="Fasta file to filter")
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
26 command.add_argument(
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
27 "access",
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
28 metavar="accessions",
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
29 type=str,
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
30 nargs="+",
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
31 help="List of accession to extract",
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
32 )
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
33
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
34 if __name__ == "__main__":
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
35 """Performed job on execution script"""
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
36 args = command.parse_args()
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
37 output = args.output
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
38 access = set(args.access)
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
39 for seq in SeqIO.parse(args.fasta, "fasta"):
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
40 if seq.id in access:
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
41 SeqIO.write(seq, output, "fasta")
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
42 access.remove(seq.id)
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
43 if len(access) > 0:
bc23da9d464c planemo upload for repository http://172.20.124.12:3000/bvalot3/PythonScript commit 9676573ee48ce5343600ab45cd3ac1a6adddabe4
bvalot
parents:
diff changeset
44 sys.stderr.write("Accessions not found : " + str(" - ").join(access) + "\n")