annotate cherry_pick_fasta.py @ 6:d8fa616a228a draft

"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 8384f1bb5378232bbe78319e06a3522674c7c1fe"
author artbio
date Fri, 08 Apr 2022 16:56:42 +0000
parents ba6c4aeb22ea
children 6c0aefd9fee3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
1 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
2
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
3
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
4 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
5 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
6 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
7 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
8 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
9 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
10 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
11 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
12 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
13 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
14 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='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
16 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
17 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
18 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
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 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
21 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
22 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
23 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
24 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
25 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
26 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
27 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
28
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
29
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
30 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
31 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
32 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
33 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
34 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
35 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
36 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
37 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
38 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
39 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
40 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
41 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
42 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
43 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
44 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
45 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
46 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
47 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
48
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
49
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
50 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
51 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
52 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
53 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
54 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
55 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
56
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
57
ea8fde9c6f82 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit f527add7e7bace30b8bc67524ff1da1bf920ec29"
artbio
parents: 0
diff changeset
58 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
59 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
60 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
61 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
62 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
63
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
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
65 def buid_fasta_dict(fasta):
6
d8fa616a228a "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 8384f1bb5378232bbe78319e06a3522674c7c1fe"
artbio
parents: 4
diff changeset
66 seq_dict = dict()
d8fa616a228a "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 8384f1bb5378232bbe78319e06a3522674c7c1fe"
artbio
parents: 4
diff changeset
67 f = open(fasta, 'r')
d8fa616a228a "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 8384f1bb5378232bbe78319e06a3522674c7c1fe"
artbio
parents: 4
diff changeset
68 content = f.read()
d8fa616a228a "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 8384f1bb5378232bbe78319e06a3522674c7c1fe"
artbio
parents: 4
diff changeset
69 segmented_content = content.split('>')
d8fa616a228a "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 8384f1bb5378232bbe78319e06a3522674c7c1fe"
artbio
parents: 4
diff changeset
70 segmented_content = segmented_content[1:]
d8fa616a228a "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 8384f1bb5378232bbe78319e06a3522674c7c1fe"
artbio
parents: 4
diff changeset
71 for seq in segmented_content:
d8fa616a228a "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 8384f1bb5378232bbe78319e06a3522674c7c1fe"
artbio
parents: 4
diff changeset
72 sliced_seq = seq.split('\n')
d8fa616a228a "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 8384f1bb5378232bbe78319e06a3522674c7c1fe"
artbio
parents: 4
diff changeset
73 header = sliced_seq[0]
d8fa616a228a "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 8384f1bb5378232bbe78319e06a3522674c7c1fe"
artbio
parents: 4
diff changeset
74 sliced_seq = sliced_seq[1:]
d8fa616a228a "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 8384f1bb5378232bbe78319e06a3522674c7c1fe"
artbio
parents: 4
diff changeset
75 sequence = ''.join(sliced_seq)
d8fa616a228a "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 8384f1bb5378232bbe78319e06a3522674c7c1fe"
artbio
parents: 4
diff changeset
76 seq_dict[header] = sequence
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
77 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
78
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
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 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
81 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
82 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
83 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
84 f.write('>%s\n' % header)
4
ba6c4aeb22ea "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 3e1f8bb17e712d70e64ebb541775e9555acc038f"
artbio
parents: 3
diff changeset
85 if len(fasta_dict[header]) <= line_length:
ba6c4aeb22ea "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 3e1f8bb17e712d70e64ebb541775e9555acc038f"
artbio
parents: 3
diff changeset
86 f.write('%s\n' % fasta_dict[header])
ba6c4aeb22ea "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 3e1f8bb17e712d70e64ebb541775e9555acc038f"
artbio
parents: 3
diff changeset
87 else:
ba6c4aeb22ea "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 3e1f8bb17e712d70e64ebb541775e9555acc038f"
artbio
parents: 3
diff changeset
88 for i in range(line_length, len(fasta_dict[header]),
ba6c4aeb22ea "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 3e1f8bb17e712d70e64ebb541775e9555acc038f"
artbio
parents: 3
diff changeset
89 line_length):
ba6c4aeb22ea "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 3e1f8bb17e712d70e64ebb541775e9555acc038f"
artbio
parents: 3
diff changeset
90 f.write('%s\n' % fasta_dict[header][i-line_length:i])
ba6c4aeb22ea "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 3e1f8bb17e712d70e64ebb541775e9555acc038f"
artbio
parents: 3
diff changeset
91 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
92
e3aee4ba49c6 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff changeset
93
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
94 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
95 ''' 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
96 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
97 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
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105 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
106 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
107 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
108 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
109
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
110
c282a8a47dd9 "planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit d637de6c1090314bd34bdffc2fdf979cb55b870b"
artbio
parents: 2
diff changeset
111 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
112 __main__()