annotate maf2bed.py @ 0:53c2be00bb6f draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
author bgruening
date Wed, 05 Jun 2024 08:15:49 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
1 #!/usr/bin/env python
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
2 # painfully converted from b0rken perl from
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
3 # https://unpkg.com/browse/jbrowse-plugin-mafviewer@1.0.6/dist/
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
4 # license is Apache2_license.txt included here
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
5
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
6 import sys
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
7
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
8 id = 0
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
9 buffer = ''
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
10 start = 0
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
11 end = 0
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
12 score = 0
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
13 chrom = ''
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
14
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
15 db = "%s." % sys.argv[1]
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
16 # Read input from stdin
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
17 for line in sys.stdin:
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
18 line = line.strip()
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
19 if not line:
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
20 continue
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
21
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
22 line = line.split()
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
23 if line[0] == 's' and line[1].startswith(db):
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
24 chrom = line[1]
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
25 chrom = chrom.replace(db, '')
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
26 start = int(line[2])
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
27 end = int(line[2]) + int(line[3])
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
28 line = line[1:]
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
29 line = ':'.join(line)
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
30 temp = line
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
31 buffer = temp if buffer == '' else f"{buffer},{temp}"
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
32 elif line[0] == 'a':
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
33 score = int(line[1].split('=')[1])
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
34 if id > 0:
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
35 sys.stdout.write('\t'.join([chrom, '%d' % start, '%d' % end, f"{sys.argv[1]}_{id}", '%d' % score, buffer]) + '\n')
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
36 id += 1
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
37 buffer = ''
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
38 elif line[0] == 's':
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
39 line = line[1:]
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
40 line = ':'.join(line)
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
41 temp = line
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
42 buffer = temp if buffer == '' else f"{buffer},{temp}"
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
43
53c2be00bb6f planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 0a86c88a95b0d1cc49d84544136de6556b95320f
bgruening
parents:
diff changeset
44 sys.stdout.write('\t'.join([chrom, '%d' % start, '%d' % end, f"{sys.argv[1]}_{id}", '%d' % score, buffer]) + '\n')