Mercurial > repos > iuc > read_it_and_keep
annotate trim_reference.py @ 2:fa7086274673 draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/read-it-and-keep commit 044b7c1696bf6fef1c8ebf5143c0a841831e92fa
author | iuc |
---|---|
date | Fri, 15 Mar 2024 16:14:58 +0000 |
parents | 554aa2a63f04 |
children |
rev | line source |
---|---|
0
554aa2a63f04
"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 |
554aa2a63f04
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/read-it-and-keep commit 4b41e2742ba5f9c957e13a188ca49e60e16ae13b"
iuc
parents:
diff
changeset
|
2 |
554aa2a63f04
"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 |
554aa2a63f04
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/read-it-and-keep commit 4b41e2742ba5f9c957e13a188ca49e60e16ae13b"
iuc
parents:
diff
changeset
|
4 |
554aa2a63f04
"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 |
554aa2a63f04
"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 |
554aa2a63f04
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/read-it-and-keep commit 4b41e2742ba5f9c957e13a188ca49e60e16ae13b"
iuc
parents:
diff
changeset
|
7 |
554aa2a63f04
"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__': |
554aa2a63f04
"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() |
554aa2a63f04
"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()) |
554aa2a63f04
"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) |
554aa2a63f04
"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() |
554aa2a63f04
"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() |
554aa2a63f04
"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 |
554aa2a63f04
"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 |
554aa2a63f04
"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 |
554aa2a63f04
"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: |
554aa2a63f04
"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() |
554aa2a63f04
"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): |
554aa2a63f04
"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 |
554aa2a63f04
"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', ' ']: |
554aa2a63f04
"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' |
554aa2a63f04
"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 |
554aa2a63f04
"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 |
554aa2a63f04
"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: |
554aa2a63f04
"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 |
554aa2a63f04
"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 |
554aa2a63f04
"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])) |