Mercurial > repos > drosofff > cherry_pick_fasta
comparison cherry_pick_fasta.py @ 0:726b1e233a08 draft
planemo upload for repository https://bitbucket.org/drosofff/gedtools/
author | drosofff |
---|---|
date | Mon, 08 Jun 2015 18:55:07 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:726b1e233a08 |
---|---|
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 def Parser(): | |
10 the_parser = argparse.ArgumentParser( | |
11 description="Cherry pick fasta sequences") | |
12 the_parser.add_argument( | |
13 '--input', action="store", type=str, help="input fasta file") | |
14 the_parser.add_argument( | |
15 '--query-string', dest="query_string", action="store", type=str, | |
16 help="header containing the string will be extracted as well as the corresponding sequence") | |
17 the_parser.add_argument( | |
18 '--output', action="store", type=str, help="output fasta file") | |
19 args = the_parser.parse_args() | |
20 return args | |
21 | |
22 def __main__(): | |
23 """ main function """ | |
24 args = Parser() | |
25 search_term = args.query_string | |
26 CrudeFasta = open (args.input, "r").read() | |
27 Output = open (args.output, "w") | |
28 FastaListe = CrudeFasta.split(">") | |
29 for sequence in FastaListe: | |
30 if search_term in sequence: | |
31 print >> Output, ">%s" % sequence.rstrip() | |
32 Output.close() | |
33 | |
34 | |
35 if __name__ == "__main__": | |
36 __main__() |