Mercurial > repos > iuc > jbrowse2
comparison 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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:61add3f58f26 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 # adapted from https://github.com/bgruening/galaxytools/blob/f96142ca5acea989b828d6c92940172355b7f125/tools/jbrowse2/maf2bed.py | |
| 4 # which was "painfully converted from b0rken perl from:" | |
| 5 # https://unpkg.com/browse/jbrowse-plugin-mafviewer@1.0.6/dist/ | |
| 6 | |
| 7 import argparse | |
| 8 import sys | |
| 9 | |
| 10 | |
| 11 def maf2bed(assembly_name, input, output): | |
| 12 id = 0 | |
| 13 buffer = '' | |
| 14 start = 0 | |
| 15 end = 0 | |
| 16 score = 0 | |
| 17 chrom = '' | |
| 18 | |
| 19 db = "%s." % assembly_name | |
| 20 # Read input from stdin | |
| 21 for line in input: | |
| 22 line = line.strip() | |
| 23 if not line: | |
| 24 continue | |
| 25 | |
| 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) |
