comparison trim_reference.py @ 0:554aa2a63f04 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/read-it-and-keep commit 4b41e2742ba5f9c957e13a188ca49e60e16ae13b"
author iuc
date Fri, 28 Jan 2022 18:47:34 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:554aa2a63f04
1 #!/usr/bin/env python
2
3 from __future__ import print_function
4
5 import argparse
6 import sys
7
8 if __name__ == '__main__':
9 parser = argparse.ArgumentParser()
10 parser.add_argument('input_file', type=argparse.FileType())
11 parser.add_argument('output_file', type=argparse.FileType('w'), nargs='?', default=sys.stdout)
12 args = parser.parse_args()
13 lines = args.input_file.readlines()
14 i = len(lines) - 1
15 trimmed = False
16 # step backwards through the lines, removing all As until we find a non-A nucleotide
17 while not trimmed:
18 line = lines[i].upper().rstrip()
19 for j in range(len(line) - 1, -1, -1):
20 # walk backwards through the line, checking for a non-A (and non-space) character
21 if line[j] not in ['A', ' ']:
22 lines[i] = line[:j + 1] + '\n'
23 trimmed = True
24 break
25 else:
26 # we processed the whole line - all As - so we don't include this line in the output
27 i -= 1
28 args.output_file.write(''.join(lines[:i + 1]))