Skip to content

Commit

Permalink
--from-taxid and --from-taxtable are now --from-id and --from-table
Browse files Browse the repository at this point in the history
  • Loading branch information
crosenth committed Sep 21, 2016
1 parent 7ba03ec commit 7fdc05d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions taxtastic/subcommands/taxtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def build_parser(parser):
help='Name of the sqlite database file')

parser.add_argument(
'--from-taxtable',
'--from-table',
metavar='CSV',
help=('taxtable to derive new taxtable from'))
parser.add_argument(
'--full',
action='store_true',
help='Show all ranks in output file.')
help='Include rank columns not in final lineages.')

input_group = parser.add_argument_group('input options')

Expand Down Expand Up @@ -96,7 +96,7 @@ def build_parser(parser):
field "tax_id" """)

input_group.add_argument(
'--from-taxid',
'--from-id',
help=('taxid to branch from'))

output_group = parser.add_argument_group(
Expand All @@ -119,9 +119,9 @@ def action(args):
ranks = pandas.read_sql_table('ranks', engine, index_col='index')
ranks = ranks['rank'].tolist()

if args.from_taxtable:
log.info('using taxtable ' + args.from_taxtable)
taxtable = pandas.read_csv(args.from_taxtable, dtype=str).set_index('tax_id')
if args.from_table:
log.info('using taxtable ' + args.from_table)
taxtable = pandas.read_csv(args.from_table, dtype=str).set_index('tax_id')
else:
log.info('building taxtable from ' + args.database_file)
nodes = pandas.read_sql_table('nodes', engine, index_col='tax_id')
Expand All @@ -132,13 +132,13 @@ def action(args):
nodes = nodes.join(names['tax_name'])
taxtable = build_taxtable(nodes, ranks)

if args.from_taxid:
from_taxon = taxtable.loc[args.from_taxid]
if args.from_id:
from_taxon = taxtable.loc[args.from_id]

# select all rows where rank column == args.from_taxid
from_table = taxtable[taxtable[from_taxon['rank']] == args.from_taxid]
# select all rows where rank column == args.from_id
from_table = taxtable[taxtable[from_taxon['rank']] == args.from_id]

# build taxtable up to root from args.from_taxid
# build taxtable up to root from args.from_id
while from_taxon.name != '1': # root
parent = taxtable.loc[from_taxon['parent_id']]
from_table = pandas.concat([pandas.DataFrame(parent).T, from_table])
Expand Down Expand Up @@ -252,6 +252,6 @@ def build_taxtable(df, ranks):
how='inner')
lineages = lineages.append(at_rank)

sys.stderr.write('built {} of {} rank lineages\r'.format(i, rank_count))
sys.stderr.write('{} of {} rank lineages completed\r'.format(i, rank_count))

return lineages.drop('rank_parent', axis=1).set_index(df_index_name)
8 changes: 4 additions & 4 deletions tests/test_subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ class _Args(object):
verbosity = 0
out_file = h
full = False
from_taxtable = None
from_taxid = None
from_table = None
from_id = None
self.assertNotEqual(taxtable.action(_Args()), 0)

def test_seqinfo(self):
Expand All @@ -290,8 +290,8 @@ class _Args(object):
out_file = tf
verbosity = 0
full = False
from_taxtable = None
from_taxid = None
from_table = None
from_id = None
self.assertIsNone(taxtable.action(_Args()))
# No output check at present
self.assertTrue(tf.tell() > 0)
Expand Down

0 comments on commit 7fdc05d

Please sign in to comment.