From 7e0ec734a33749a9e0b2e772245201918876fbc4 Mon Sep 17 00:00:00 2001 From: Andre Corvelo Date: Fri, 21 Apr 2017 15:32:46 -0400 Subject: [PATCH] modes and minor fix --- bin/txM_lca | 47 ++++++++++++++++++++++++++++------------------- bin/txM_report | 24 +++++++++++------------- taxMaps | 6 +++--- 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/bin/txM_lca b/bin/txM_lca index 5f562ce..efcf5c9 100755 --- a/bin/txM_lca +++ b/bin/txM_lca @@ -81,19 +81,28 @@ def p_pair(pl1, pl2, tax_d): tag_l[1] = tag_d[tax_2] tag = ''.join(tag_l) - if tax_1 == '-': - p_tax = tax_2 - elif tax_1 == '0': - p_tax = tax_1 - if tax_2 != '-' and tax_2 != '0': + if opt.d_mode == 'p': + if tax_1 == '-': p_tax = tax_2 - else: - p_tax = tax_1 - if tax_2 != '-' and tax_2 != '0' and tax_2 != tax_1: - if tax_2 in tax_d[tax_1][3].split(':'): - pass - elif tax_1 in tax_d[tax_2][3].split(':'): + elif tax_1 == '0': + p_tax = tax_1 + if tax_2 != '-' and tax_2 != '0': p_tax = tax_2 + else: + p_tax = tax_1 + if tax_2 != '-' and tax_2 != '0' and tax_2 != tax_1: + if tax_2 in tax_d[tax_1][3].split(':'): + pass + elif tax_1 in tax_d[tax_2][3].split(':'): + p_tax = tax_2 + else: + p_tax = lca(sorted([tax_d[tax_1][3], tax_d[tax_2][3]])) + elif opt.d_mode == 'P': + if tax_1 == '-' or tax_2 == '-': + p_tax = '-' + else: + if tax_1 == '0' or tax_2 == '0': + p_tax = '0' else: p_tax = lca(sorted([tax_d[tax_1][3], tax_d[tax_2][3]])) tax_str = '\t'.join([tag] + tax_d[p_tax][:3]) @@ -128,12 +137,12 @@ parser.add_option( ) parser.add_option( - "-p", - metavar = "FLAG", - dest = "paired", - action = 'store_true', - default = False, - help = "Paired LCA determination (only for interleaved input; default = False)" + "-m", + metavar = "STR", + type = "string", + dest = "d_mode", + default = 's', + help = "Taxa determination mode ('s' single-end; 'p' paired-end; 'P' paired-end strict; default = 's')" ) parser.add_option( @@ -188,11 +197,11 @@ if __name__ == '__main__': map_file = open(opt.map_file, 'r') else: map_file = stdin - if not opt.paired: + if opt.d_mode == 's': for l in map_file: stdout.write(p_rec(l.strip(), tax_d, excluded) + '\n') stderr.write(p_rec(l.strip(), tax_d, excluded) + '\n') - elif opt.paired: + elif opt.d_mode == 'p' or opt.d_mode == 'P': while 1: l1 = map_file.readline() if not l1: diff --git a/bin/txM_report b/bin/txM_report index 4171463..20baef5 100755 --- a/bin/txM_report +++ b/bin/txM_report @@ -72,12 +72,12 @@ parser.add_option( ) parser.add_option( - "-m", - metavar = "STR", - type = "string", - dest = "d_mode", - default = 's', - help = "Taxa determination mode ('s' single-end; 'p' paired-end; 'P' paired-end strict; default = 's')" + "-p", + metavar = "FLAG", + dest = "paired", + action = 'store_true', + default = False, + help = "Paired LCA determination (only for interleaved input; default = False)" ) parser.add_option( @@ -91,7 +91,7 @@ parser.add_option( (opt, args) = parser.parse_args() -if opt.tax_file == None or opt.d_mode not in ['s', 'p', 'P'] or opt.out_prefix == None: +if opt.tax_file == None or opt.out_prefix == None: parser.print_help() exit(-1) @@ -135,12 +135,10 @@ if __name__ == '__main__': la = l.strip().split('\t') tax_id = la[0] path = tax_d[tax_id][3] - if opt.d_mode == 's': - counts = int(la[4]) - elif opt.d_mode == 'p': + if opt.paired: counts = int(la[7]) + int(la[8]) - elif opt.d_mode == 'P': - counts = int(la[7]) + else: + counts = int(la[4]) tax_d[tax_id][4] = counts for node in path: tax_d[node][5] += counts @@ -158,7 +156,7 @@ if __name__ == '__main__': for tax_id in tax_d: tax_d[tax_id][6] -= tax_d[tax_id][4] path = tax_d[tax_id][3] - if tax_d[tax_id][5] > min_c and len(path) > 1 : + if tax_d[tax_id][5] >= min_c and len(path) > 1 : tax_d[path[-2]][6] -= tax_d[tax_id][5] diff --git a/taxMaps b/taxMaps index e86d00d..c6d16f4 100755 --- a/taxMaps +++ b/taxMaps @@ -639,8 +639,7 @@ if __name__ == '__main__': tax_command += ' 2> /dev/null \\\n\t| ' tax_command += 'txM_lca ' tax_command += '-t ' + rp(tax_lnk, run_dir) + ' ' - if det_mode == 'p' or det_mode == 'P': - tax_command += '-p ' + tax_command += '-m ' + det_mode + ' ' tax_command += '2> ' + rp(map_dir + '/' + prefix + '.merged.map.lca', run_dir) tax_command += ' \\\n\t| ' tax_command += 'txM_summary ' @@ -657,7 +656,8 @@ if __name__ == '__main__': rep_command = 'cat ' + rp(out_dir + '/' + prefix + '.merged.map.lca.summary', out_dir) + ' \\\n\t| ' rep_command += 'txM_report ' rep_command += '-t ' + rp(tax_lnk, out_dir) + ' ' - rep_command += '-m ' + det_mode + ' ' + if det_mode == 'p' or det_mode == 'P': + rep_command += '-p ' rep_command += '-c ' + rep_cutoff + ' ' rep_command += '-o ' + prefix + ' '