Skip to content

Commit

Permalink
modes and minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
acorvelo committed Apr 21, 2017
1 parent 5a4379a commit 7e0ec73
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
47 changes: 28 additions & 19 deletions bin/txM_lca
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
24 changes: 11 additions & 13 deletions bin/txM_report
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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]


Expand Down
6 changes: 3 additions & 3 deletions taxMaps
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand All @@ -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 + ' '

Expand Down

0 comments on commit 7e0ec73

Please sign in to comment.