Mercurial > repos > artbio > cherry_pick_fasta
annotate 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 |
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 -*- |
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 Chery pick of fasta sequences satisfying a query string in their header/name |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
5 """ |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
6 |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
7 import argparse |
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 |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
10 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
|
11 the_parser = argparse.ArgumentParser( |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
12 description="Cherry pick fasta sequences") |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
13 the_parser.add_argument('--input', action="store", type=str, |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
14 help="input fasta file") |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
15 the_parser.add_argument('--query-string', dest="query_string", |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
16 action="store", type=str, |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
17 help="header containing the string will be\ |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
18 extracted as well as the corresponding\ |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
19 sequence") |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
20 the_parser.add_argument( |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
21 '--output', action="store", type=str, help="output fasta file") |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
22 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
|
23 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
|
24 |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
25 |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
26 def __main__(): |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
27 """ main function """ |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
28 args = Parser() |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
29 search_term = args.query_string |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
30 CrudeFasta = open(args.input, "r").read() |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
31 Output = open(args.output, "w") |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
32 FastaListe = CrudeFasta.split(">") |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
33 for sequence in FastaListe: |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
34 if search_term in sequence: |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
35 Output.write(">%s\n" % sequence.rstrip()) |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
36 Output.close() |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
37 |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
38 |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
39 if __name__ == "__main__": |
e3aee4ba49c6
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/cherry_pick_fasta commit a5e865d017e0434dae013565929ad5e6e5129fd3
artbio
parents:
diff
changeset
|
40 __main__() |