Mercurial > repos > artbio > cherry_pick_fasta
annotate cherry_pick_fasta.py @ 4:ba6c4aeb22ea draft
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit 3e1f8bb17e712d70e64ebb541775e9555acc038f"
author | artbio |
---|---|
date | Fri, 21 May 2021 11:48:59 +0000 |
parents | c282a8a47dd9 |
children | d8fa616a228a |
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) |
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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
88 |
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
|
89 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
|
90 ''' 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 |
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 |
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 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
|
107 __main__() |