annotate trim_reference.py @ 1:c271346bad2c draft default tip

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