annotate cherry_pick_fasta.py @ 3:c282a8a47dd9 draft

"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
author artbio
date Fri, 21 May 2021 09:34:14 +0000
parents 321cad0eb507
children ba6c4aeb22ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
1 #!/usr/bin/env python
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
2 # -*- coding: utf-8 -*-
3
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
3 # Chery pick of fasta sequences satisfying a query string in their header/name
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
4 import argparse
0
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
5
3
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
6 from Bio import SeqIO
0
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
7
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
8
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
9 def Parser():
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
10 the_parser = argparse.ArgumentParser(
3
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
11 description='Cherry pick fasta sequences')
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
12 the_parser.add_argument('--input', action='store', type=str,
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
13 help='input fasta file')
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
14 the_parser.add_argument('--searchfor', action='store', type=str,
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
15 help='with, without, or withlist, withoutlist')
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
16 the_parser.add_argument('--mode', action='store', type=str,
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
17 default='includes', help='exact or includes')
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
18 the_parser.add_argument('--query-string', dest='query_string',
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
19 action='store', type=str,
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
20 help='headers containing the string will be \
1
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
21 extracted or excluded as well as the \
3
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
22 corresponding sequence')
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
23 the_parser.add_argument('--query-file', dest='query_file',
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
24 action='store', type=str,
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
25 help='headers containing any of the strings \
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
26 provided in the text file (1 string per \
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
27 line) will be extracted or excluded as well \
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
28 as the corresponding sequence')
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
29 the_parser.add_argument('--output', action='store', type=str,
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
30 help='output fasta file')
0
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
31 args = the_parser.parse_args()
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
32 return args
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
33
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
34
3
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
35 def parse_fasta_dict(query, fasta_dict, mode):
1
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
36 if not isinstance(query, list):
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
37 query = [query]
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
38 accumulator = []
3
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
39 if mode == 'includes':
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
40 for seq_id in fasta_dict:
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
41 for string in query:
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
42 if string in seq_id:
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
43 accumulator.append(seq_id)
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
44 continue
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
45 elif mode == 'exact':
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
46 for seq_id in fasta_dict:
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
47 for string in query:
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
48 if string == seq_id:
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
49 accumulator.append(seq_id)
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
50 continue
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
51 res_dict = {k: fasta_dict[k] for k in fasta_dict if k in accumulator}
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
52 return res_dict
1
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
53
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
54
3
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
55 def complement_fasta_dict(fasta_dict, subfasta_dict):
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
56 fasta_ids = list(fasta_dict.keys())
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
57 subfasta_ids = list(subfasta_dict.keys())
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
58 complement_ids = list(set(fasta_ids) - set(subfasta_ids))
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
59 sub_dict = {k: fasta_dict[k] for k in fasta_dict if k in complement_ids}
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
60 return sub_dict
1
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
61
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
62
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
63 def getquerylist(file):
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
64 querylist = []
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
65 for line in open(file, 'r'):
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
66 querylist.append(line.rstrip())
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
67 return querylist
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
68
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
69
3
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
70 def buid_fasta_dict(fasta):
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
71 seq_dict = {rec.id: rec.seq for rec in SeqIO.parse(fasta, "fasta")}
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
72 return seq_dict
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
73
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
74
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
75 def write_fasta_result(fasta_dict, file):
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
76 line_length = 60
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
77 with open(file, 'w') as f:
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
78 for header in sorted(fasta_dict):
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
79 f.write('>%s\n' % header)
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
80 for i in range(line_length, len(fasta_dict[header]), line_length):
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
81 f.write('%s\n' % fasta_dict[header][i-line_length:i])
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
82 f.write('%s\n' % fasta_dict[header][i:])
0
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
83
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
84
3
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
85 def __main__():
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
86 ''' main function '''
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
87 args = Parser()
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
88 fasta_dict = buid_fasta_dict(args.input)
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
89 if args.query_string:
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
90 query = args.query_string
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
91 elif args.query_file:
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
92 query = getquerylist(args.query_file)
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
93 if args.searchfor == 'with':
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
94 fasta_result_dict = parse_fasta_dict(query, fasta_dict, args.mode)
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
95 elif args.searchfor == 'without':
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
96 fasta_result_dict = complement_fasta_dict(fasta_dict, parse_fasta_dict(
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
97 query, fasta_dict,
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
98 args.mode))
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
99 write_fasta_result(fasta_result_dict, args.output)
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
100
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
101
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
102 if __name__ == '__main__':
0
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
103 __main__()