Mercurial > repos > bgruening > reago
annotate format_reago_input_files.py @ 0:13dd84cab09e draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
author | bgruening |
---|---|
date | Sat, 27 Apr 2024 17:59:57 +0000 |
parents | |
children |
rev | line source |
---|---|
0
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
1 #!/usr/bin/env python |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
3 |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
4 import argparse |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
5 |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
6 |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
7 def add_read_pair_num(input_filepath, output_filepath, read_pair_num): |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
8 to_add = "." + str(read_pair_num) |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
9 with open(input_filepath, "r") as input_file: |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
10 with open(output_filepath, "w") as output_file: |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
11 for line in input_file: |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
12 if line.startswith(">"): |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
13 split_line = line.split() |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
14 seq_id = split_line[0] |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
15 if seq_id.rfind(to_add) != (len(seq_id) - len(to_add)): |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
16 split_line[0] = seq_id + to_add |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
17 output_file.write(" ".join(split_line) + "\n") |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
18 else: |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
19 output_file.write(line) |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
20 |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
21 |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
22 if __name__ == "__main__": |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
23 parser = argparse.ArgumentParser() |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
24 parser.add_argument("--r1_input", required=True) |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
25 parser.add_argument("--r2_input", required=True) |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
26 parser.add_argument("--r1_output", required=True) |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
27 parser.add_argument("--r2_output", required=True) |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
28 args = parser.parse_args() |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
29 |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
30 add_read_pair_num(args.r1_input, args.r1_output, 1) |
13dd84cab09e
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/reago commit f5be73e67192909db96dfab214f4360eb41757a4
bgruening
parents:
diff
changeset
|
31 add_read_pair_num(args.r2_input, args.r2_output, 2) |