annotate maf2bed.py @ 0:61add3f58f26 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
author iuc
date Thu, 02 Oct 2025 10:19:44 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
1 #!/usr/bin/env python
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
2
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
3 # adapted from https://github.com/bgruening/galaxytools/blob/f96142ca5acea989b828d6c92940172355b7f125/tools/jbrowse2/maf2bed.py
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
4 # which was "painfully converted from b0rken perl from:"
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
5 # https://unpkg.com/browse/jbrowse-plugin-mafviewer@1.0.6/dist/
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
6
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
7 import argparse
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
8 import sys
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
9
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
10
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
11 def maf2bed(assembly_name, input, output):
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
12 id = 0
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
13 buffer = ''
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
14 start = 0
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
15 end = 0
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
16 score = 0
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
17 chrom = ''
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
18
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
19 db = "%s." % assembly_name
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
20 # Read input from stdin
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
21 for line in input:
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
22 line = line.strip()
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
23 if not line:
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
24 continue
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
25
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
26 line = line.split()
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
27 if line[0] == 's' and line[1].startswith(db):
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
28 chrom = line[1]
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
29 chrom = chrom.replace(db, '')
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
30 start = int(line[2])
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
31 end = int(line[2]) + int(line[3])
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
32 line = line[1:]
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
33 line = ':'.join(line)
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
34 temp = line
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
35 buffer = temp if buffer == '' else f"{buffer},{temp}"
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
36 elif line[0] == 'a':
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
37 score = int(line[1].split('=')[1])
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
38 if id > 0:
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
39 output.write('\t'.join([chrom, '%d' % start, '%d' % end, f"{assembly_name}_{id}", '%d' % score, buffer]) + '\n')
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
40 id += 1
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
41 buffer = ''
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
42 elif line[0] == 's':
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
43 line = line[1:]
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
44 line = ':'.join(line)
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
45 temp = line
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
46 buffer = temp if buffer == '' else f"{buffer},{temp}"
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
47
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
48 output.write('\t'.join([chrom, '%d' % start, '%d' % end, f"{assembly_name}_{id}", '%d' % score, buffer]) + '\n')
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
49
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
50
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
51 if __name__ == "__main__":
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
52 parser = argparse.ArgumentParser(description="", epilog="")
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
53 parser.add_argument("assembly_name", help="Assembly name")
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
54 parser.add_argument('input', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
55 parser.add_argument('output', nargs='?', type=argparse.FileType('w'), default=sys.stdout)
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
56 args = parser.parse_args()
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
57
61add3f58f26 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 4fa86613193c985e0cb9a8fc795c56b8bc7b8532
iuc
parents:
diff changeset
58 maf2bed(args.assembly_name, args.input, args.output)