Mercurial > repos > artbio > cherry_pick_fasta
comparison cherry_pick_fasta.py @ 0:e3aee4ba49c6 draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
author | artbio |
---|---|
date | Sun, 15 Oct 2017 13:26:45 -0400 |
parents | |
children | ea8fde9c6f82 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e3aee4ba49c6 |
---|---|
1 #!/usr/bin/env python | |
2 # -*- coding: utf-8 -*- | |
3 """ | |
4 Chery pick of fasta sequences satisfying a query string in their header/name | |
5 """ | |
6 | |
7 import argparse | |
8 | |
9 | |
10 def Parser(): | |
11 the_parser = argparse.ArgumentParser( | |
12 description="Cherry pick fasta sequences") | |
13 the_parser.add_argument('--input', action="store", type=str, | |
14 help="input fasta file") | |
15 the_parser.add_argument('--query-string', dest="query_string", | |
16 action="store", type=str, | |
17 help="header containing the string will be\ | |
18 extracted as well as the corresponding\ | |
19 sequence") | |
20 the_parser.add_argument( | |
21 '--output', action="store", type=str, help="output fasta file") | |
22 args = the_parser.parse_args() | |
23 return args | |
24 | |
25 | |
26 def __main__(): | |
27 """ main function """ | |
28 args = Parser() | |
29 search_term = args.query_string | |
30 CrudeFasta = open(args.input, "r").read() | |
31 Output = open(args.output, "w") | |
32 FastaListe = CrudeFasta.split(">") | |
33 for sequence in FastaListe: | |
34 if search_term in sequence: | |
35 Output.write(">%s\n" % sequence.rstrip()) | |
36 Output.close() | |
37 | |
38 | |
39 if __name__ == "__main__": | |
40 __main__() |