comparison maf2bed.py @ 136:93fdd696c281 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:20:29 +0000
parents b1260bca5fdc
children
comparison
equal deleted inserted replaced
135:21bb464c1d53 136:93fdd696c281
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # painfully converted from b0rken perl from 2
3 # adapted from https://github.com/bgruening/galaxytools/blob/f96142ca5acea989b828d6c92940172355b7f125/tools/jbrowse2/maf2bed.py
4 # which was "painfully converted from b0rken perl from:"
3 # https://unpkg.com/browse/jbrowse-plugin-mafviewer@1.0.6/dist/ 5 # https://unpkg.com/browse/jbrowse-plugin-mafviewer@1.0.6/dist/
4 # license is Apache2_license.txt included here
5 6
7 import argparse
6 import sys 8 import sys
7 9
8 id = 0
9 buffer = ''
10 start = 0
11 end = 0
12 score = 0
13 chrom = ''
14 10
15 db = "%s." % sys.argv[1] 11 def maf2bed(assembly_name, input, output):
16 # Read input from stdin 12 id = 0
17 for line in sys.stdin: 13 buffer = ''
18 line = line.strip() 14 start = 0
19 if not line: 15 end = 0
20 continue 16 score = 0
17 chrom = ''
21 18
22 line = line.split() 19 db = "%s." % assembly_name
23 if line[0] == 's' and line[1].startswith(db): 20 # Read input from stdin
24 chrom = line[1] 21 for line in input:
25 chrom = chrom.replace(db, '') 22 line = line.strip()
26 start = int(line[2]) 23 if not line:
27 end = int(line[2]) + int(line[3]) 24 continue
28 line = line[1:]
29 line = ':'.join(line)
30 temp = line
31 buffer = temp if buffer == '' else f"{buffer},{temp}"
32 elif line[0] == 'a':
33 score = int(line[1].split('=')[1])
34 if id > 0:
35 sys.stdout.write('\t'.join([chrom, '%d' % start, '%d' % end, f"{sys.argv[1]}_{id}", '%d' % score, buffer]) + '\n')
36 id += 1
37 buffer = ''
38 elif line[0] == 's':
39 line = line[1:]
40 line = ':'.join(line)
41 temp = line
42 buffer = temp if buffer == '' else f"{buffer},{temp}"
43 25
44 sys.stdout.write('\t'.join([chrom, '%d' % start, '%d' % end, f"{sys.argv[1]}_{id}", '%d' % score, buffer]) + '\n') 26 line = line.split()
27 if line[0] == 's' and line[1].startswith(db):
28 chrom = line[1]
29 chrom = chrom.replace(db, '')
30 start = int(line[2])
31 end = int(line[2]) + int(line[3])
32 line = line[1:]
33 line = ':'.join(line)
34 temp = line
35 buffer = temp if buffer == '' else f"{buffer},{temp}"
36 elif line[0] == 'a':
37 score = int(line[1].split('=')[1])
38 if id > 0:
39 output.write('\t'.join([chrom, '%d' % start, '%d' % end, f"{assembly_name}_{id}", '%d' % score, buffer]) + '\n')
40 id += 1
41 buffer = ''
42 elif line[0] == 's':
43 line = line[1:]
44 line = ':'.join(line)
45 temp = line
46 buffer = temp if buffer == '' else f"{buffer},{temp}"
47
48 output.write('\t'.join([chrom, '%d' % start, '%d' % end, f"{assembly_name}_{id}", '%d' % score, buffer]) + '\n')
49
50
51 if __name__ == "__main__":
52 parser = argparse.ArgumentParser(description="", epilog="")
53 parser.add_argument("assembly_name", help="Assembly name")
54 parser.add_argument('input', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
55 parser.add_argument('output', nargs='?', type=argparse.FileType('w'), default=sys.stdout)
56 args = parser.parse_args()
57
58 maf2bed(args.assembly_name, args.input, args.output)