Mercurial > repos > petr-novak > re_utils
comparison fasta_affixer.py @ 0:a4cd8608ef6b draft
Uploaded
author | petr-novak |
---|---|
date | Mon, 01 Apr 2019 07:56:36 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a4cd8608ef6b |
---|---|
1 #!/usr/bin/env python3 | |
2 ''' fasta affixer - adding prefixes and suffixes to fasta sequence names''' | |
3 import argparse | |
4 | |
5 parser = argparse.ArgumentParser() | |
6 parser.add_argument("-f", "--fasta", type=str, help="fasta file") | |
7 parser.add_argument("-o", "--output", type=str, help="output fasta file") | |
8 parser.add_argument( | |
9 "-p", "--prefix", | |
10 type=str, help="prefix to be added to names") | |
11 parser.add_argument( | |
12 "-s", "--suffix", | |
13 type=str, help="suffix to be added", | |
14 default='') | |
15 parser.add_argument("-n", | |
16 "--nspace", | |
17 type=int, | |
18 help="number of spaces to ignore", | |
19 default='0') | |
20 | |
21 args = parser.parse_args() | |
22 | |
23 with open(args.fasta, "r") as f, open(args.output, "w") as out: | |
24 for oneline in f: | |
25 if oneline == "": | |
26 continue | |
27 if not oneline: | |
28 break | |
29 if oneline[0] == ">": | |
30 header = " ".join(oneline.split()[:1 + args.nspace]) | |
31 header_out = header[0] + args.prefix + header[1:] + args.suffix + "\n" | |
32 out.write(header_out) | |
33 else: | |
34 out.write(oneline) | |
35 |