Mercurial > repos > fubar > jbrowse2
diff 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 |
line wrap: on
line diff
--- a/maf2bed.py Sun Dec 15 23:47:40 2024 +0000 +++ b/maf2bed.py Thu Oct 02 10:20:29 2025 +0000 @@ -1,44 +1,58 @@ #!/usr/bin/env python -# painfully converted from b0rken perl from + +# adapted from https://github.com/bgruening/galaxytools/blob/f96142ca5acea989b828d6c92940172355b7f125/tools/jbrowse2/maf2bed.py +# which was "painfully converted from b0rken perl from:" # https://unpkg.com/browse/jbrowse-plugin-mafviewer@1.0.6/dist/ -# license is Apache2_license.txt included here +import argparse import sys -id = 0 -buffer = '' -start = 0 -end = 0 -score = 0 -chrom = '' -db = "%s." % sys.argv[1] -# Read input from stdin -for line in sys.stdin: - line = line.strip() - if not line: - continue +def maf2bed(assembly_name, input, output): + id = 0 + buffer = '' + start = 0 + end = 0 + score = 0 + chrom = '' + + db = "%s." % assembly_name + # Read input from stdin + for line in input: + line = line.strip() + if not line: + continue - line = line.split() - if line[0] == 's' and line[1].startswith(db): - chrom = line[1] - chrom = chrom.replace(db, '') - start = int(line[2]) - end = int(line[2]) + int(line[3]) - line = line[1:] - line = ':'.join(line) - temp = line - buffer = temp if buffer == '' else f"{buffer},{temp}" - elif line[0] == 'a': - score = int(line[1].split('=')[1]) - if id > 0: - sys.stdout.write('\t'.join([chrom, '%d' % start, '%d' % end, f"{sys.argv[1]}_{id}", '%d' % score, buffer]) + '\n') - id += 1 - buffer = '' - elif line[0] == 's': - line = line[1:] - line = ':'.join(line) - temp = line - buffer = temp if buffer == '' else f"{buffer},{temp}" + line = line.split() + if line[0] == 's' and line[1].startswith(db): + chrom = line[1] + chrom = chrom.replace(db, '') + start = int(line[2]) + end = int(line[2]) + int(line[3]) + line = line[1:] + line = ':'.join(line) + temp = line + buffer = temp if buffer == '' else f"{buffer},{temp}" + elif line[0] == 'a': + score = int(line[1].split('=')[1]) + if id > 0: + output.write('\t'.join([chrom, '%d' % start, '%d' % end, f"{assembly_name}_{id}", '%d' % score, buffer]) + '\n') + id += 1 + buffer = '' + elif line[0] == 's': + line = line[1:] + line = ':'.join(line) + temp = line + buffer = temp if buffer == '' else f"{buffer},{temp}" -sys.stdout.write('\t'.join([chrom, '%d' % start, '%d' % end, f"{sys.argv[1]}_{id}", '%d' % score, buffer]) + '\n') + output.write('\t'.join([chrom, '%d' % start, '%d' % end, f"{assembly_name}_{id}", '%d' % score, buffer]) + '\n') + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="", epilog="") + parser.add_argument("assembly_name", help="Assembly name") + parser.add_argument('input', nargs='?', type=argparse.FileType('r'), default=sys.stdin) + parser.add_argument('output', nargs='?', type=argparse.FileType('w'), default=sys.stdout) + args = parser.parse_args() + + maf2bed(args.assembly_name, args.input, args.output)