From 95c0705b3ce8086e8752c8e24573e2ccda987ed7 Mon Sep 17 00:00:00 2001 From: mnshgl0110 Date: Mon, 4 Mar 2024 11:51:19 +0100 Subject: [PATCH] Updated mapbp to have a separate cli parser --- hometools/hometools.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/hometools/hometools.py b/hometools/hometools.py index 3d71bba..0a1ffce 100644 --- a/hometools/hometools.py +++ b/hometools/hometools.py @@ -2149,7 +2149,7 @@ def reg_str_to_list(regstr): # END -def mapbp(args): +def mapbp(sfin, mapfin, d, pos): """ Outputs mapping positions for the given reference genome coordinate """ @@ -2162,13 +2162,9 @@ def getsyripos(sout, pos): :param: pos = reference genome coordinate in (chrom, start, end) format """ return [b.split('\t') for b in sout.fetch(*pos)] - # END - - sfin = args.anno.name if args.anno is not None else None # input syri.out file - mapfin = args.map.name - d = args.d - pos = reg_str_to_list(args.pos) + # END + outd = deque() # if syri output is provided, select alignments selected by syri if sfin is not None: #TODO: Validate that this works correctly when syri output file is also provided @@ -2204,12 +2200,22 @@ def getsyripos(sout, pos): out = f"{al.query_name}:{p}-{p}" if d: out = out + '\t+' if al.is_forward else out + '\t-' - print(out) + outd.append(out) + return outd +# END + + +def mapbp_cli(args): + sfin = args.anno.name if args.anno is not None else None # input syri.out file + mapfin = args.map.name + d = args.d + pos = reg_str_to_list(args.pos) + outd = mapbp(sfin, mapfin, d, pos) + print('\n'.join(outd)) logger.info('Finished') return # END - def fachrid(args): fa = args.fa.name out = args.out.name @@ -2804,9 +2810,8 @@ def main(cmd): parser_plotal.add_argument("-D", help='DPI', type=int, default=300) - # mapbp - parser_mapbp.set_defaults(func=mapbp) + parser_mapbp.set_defaults(func=mapbp_cli) parser_mapbp.add_argument("pos", help='Genome position in \'chr:start-end\' format.', type=str) parser_mapbp.add_argument("map", help='Alignment file in BAM/PAF format.', type=argparse.FileType('r')) parser_mapbp.add_argument("--anno", help='Syri annotation file. Only alignments present in the syri output would be selected. Need syri.out to be sorted and indexed with tabix. Use: hometools syridx.', type=argparse.FileType('r'))