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