def test_new_nodes01(self): source_name = 'some_source' # add some nodes and names args = ['add_nodes', self.dbname, data_path('new_nodes_ok_nosource.yml'), '--source-name', source_name] main(args) args = ['extract_nodes', self.dbname, source_name, '-o', self.outfile] main(args)
def test05(self): args = ['update_taxids', self.infile, self.db, '-o', self.outfile, '--unknown-action', 'drop'] main(args) expected = [ ('tax_id', 'tax_name', 'comment'), ('1280', '', 'ok'), ('1287', 'Staphylococcus staphylolyticus', 'merged with 1287'), ] self.assertEqual(expected, self.get_rows(self.outfile))
def test06(self): args = [ 'update_taxids', self.infile, self.db, '-o', self.outfile, '--unknown-action', 'ignore', '--unknowns', self.unknowns ] main(args) unknowns = [ ('tax_id', 'tax_name', 'comment'), ('', 'who knows?', 'blank'), ('foo', 'unknown', 'completely unknown'), ] self.assertEqual(unknowns, self.get_rows(self.unknowns))
def test06(self): args = ['update_taxids', self.infile, self.db, '-o', self.outfile, '--unknown-action', 'ignore', '--unknowns', self.unknowns] main(args) unknowns = [ ('tax_id', 'tax_name', 'comment'), ('', 'who knows?', 'blank'), ('foo', 'unknown', 'completely unknown'), ] self.assertEqual(unknowns, self.get_rows(self.unknowns))
def test04(self): args = ['update_taxids', self.infile, self.db, '-o', self.outfile, '--unknown-action', 'ignore'] main(args) expected = [ ('tax_id', 'tax_name', 'comment'), ('1280', '', 'ok'), ('1287', 'Staphylococcus staphylolyticus', 'merged with 1287'), ('', 'who knows?', 'blank'), ('foo', 'unknown', 'completely unknown'), ] self.assertEqual(expected, self.get_rows(self.outfile))
def test_lineage_table(self): outfile = os.path.join(self.outdir, 'taxonomy.txt') args = ['lineage_table', self.taxtable, self.seq_info, '--taxonomy-table', outfile] main(args) with open(outfile) as f: output = list(csv.reader(f, delimiter='\t')) self.assertEqual( [row[0] for row in output], [row[0] for row in self.info[1:]] ) for expected, actual in zip(self.info[1:], output): self.assertTrue(actual[1].endswith(actual[-1]))
def test_new_nodes02(self): # fails without --source-name args = [ 'add_nodes', self.dbname, data_path('new_nodes_ok_nosource.yml') ] self.assertNonZeroExitStatus(main(args))
def test_new_nodes03(self): args = [ 'add_nodes', self.dbname, data_path('new_nodes_ok_nosource.yml'), '--source-name', 'some_source' ] self.assertZeroExitStatus(main(args))
def setUp(self): self.outdir = self.mkoutdir() self.taxtable = os.path.join(self.outdir, 'taxtable.csv') self.seq_info = os.path.join(self.outdir, 'seq_info.csv') self.info = [ ('seqname', 'tax_id', 'species', 'mothur'), ('s1', '1280', 'Staphylococcus aureus', 's__Staphylococcus_aureus;'), ('s2', '246432', 'Staphylococcus equorum', 's__Staphylococcus_equorum;'), ('s3', '29383', 'Staphylococcus equorum', 's__Staphylococcus_equorum;'), ('s4', '1279', '', 'g__Staphylococcus;') ] with open(self.seq_info, 'w') as f: csv.writer(f).writerows(self.info) main(['taxtable', config.ncbi_master_db, '-i', self.seq_info, '-o', self.taxtable])
def test_csv_table(self): outfile = os.path.join(self.outdir, 'lineages.csv') args = ['lineage_table', self.taxtable, self.seq_info, '--csv-table', outfile] main(args) with open(outfile) as f: output = list(csv.DictReader(f)) self.assertEqual( [row['seqname'] for row in output], [row[0] for row in self.info[1:]] ) self.assertEqual( [row['species'] for row in output], [row[-2] for row in self.info[1:]] )
def wrap_cmd(self, cmd): cmd = cmd % self try: retval = main(cmd.split()) except SystemExit as err: return None, err else: return retval, None
def test_seqinfo(self): args = [ 'add_to_taxtable', data_path('minimal_taxonomy.csv'), data_path('minimal_add_taxonomy.csv'), '-o', os.path.join(self.mkoutdir(), 'taxonomy.csv') ] self.assertIsNone(main(args))
def wrap_cmd(self, cmd): cmd = cmd % self try: retval = main(cmd.split()) except SystemExit as err: return None, err else: return retval, None
def test_seqinfo(self): outdir = self.mkoutdir() args = [ 'taxtable', config.ncbi_master_db, '--seq-info', data_path('simple_seqinfo.csv'), '-o', os.path.join(outdir, 'taxonomy.csv') ] self.assertIsNone(main(args))
def test_new_nodes05(self): args = ['add_nodes', self.dbname, data_path('staph_species_group2.yml')] self.assertZeroExitStatus(main(args)) tax = Taxonomy(sqlalchemy.create_engine('sqlite:///' + self.dbname)) with tax.engine.connect() as con: result = con.execute( 'select * from nodes where parent_id = ?', ('stapha_sg',)) keys = list(result.keys()) nodes = [dict(list(zip(keys, row))) for row in result.fetchall()] self.assertEqual(len(nodes), 5) self.assertEqual([row['source_id'] for row in nodes], [2] * len(nodes))
def test_seqinfo(self): outdir = self.mkoutdir() args = ['taxtable', config.ncbi_master_db, '--seq-info', data_path('simple_seqinfo.csv'), '-o', os.path.join(outdir, 'taxonomy.csv')] self.assertIsNone(main(args))
def test_new_nodes01(self): args = ['add_nodes', self.dbname, data_path('new_nodes_ok.yml')] self.assertZeroExitStatus(main(args))
def test_new_nodes02(self): # fails without --source-name args = ['add_nodes', self.dbname, data_path('new_nodes_ok_nosource.yml')] self.assertNonZeroExitStatus(main(args))
def test_new_nodes01(self): args = ['add_nodes', self.dbname, data_path('new_nodes_ok.yml')] self.assertZeroExitStatus(main(args))
def test_new_nodes03(self): args = ['add_nodes', self.dbname, data_path('new_nodes_ok_nosource.yml'), '--source-name', 'some_source'] self.assertZeroExitStatus(main(args))
def main(self, arguments): taxit.main(['update_taxids'] + [str(a) for a in arguments])
#!/usr/bin/env python # This file is part of taxtastic. # # taxtastic is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # taxtastic is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with taxtastic. If not, see <http://www.gnu.org/licenses/>. import sys from taxtastic.scripts.taxit import main if __name__ == '__main__': sys.exit(main(sys.argv[1:]))
def test_seqinfo(self): args = ['add_to_taxtable', data_path('minimal_taxonomy.csv'), data_path('minimal_add_taxonomy.csv'), '-o', os.path.join(self.mkoutdir(), 'taxonomy.csv')] self.assertIsNone(main(args))