Example #1
0
def action(args):
    if args.clobber and os.path.isdir(args.package_name):
        try:
            shutil.rmtree(args.package_name)
        except:
            print >> sys.stderr, "Failed: Could not delete %s" % args.package_name
            return 1
    elif args.clobber and os.path.exists(args.package_name):
        try:
            os.unlink(args.package_name)
        except:
            print >> sys.stderr, "Failed: Could not delete %s" % args.package_name
            return 1
    elif not args.clobber and os.path.exists(args.package_name):
        print >> sys.stderr, 'Failed: {0} exists.'.format(args.package_name)
        return 1

    r = refpkg.Refpkg(args.package_name, create=True)
    r.start_transaction()
    r.update_metadata('locus', args.locus)  # Locus is required
    if args.description:
        r.update_metadata('description', args.description)
    if args.author:
        r.update_metadata('author', args.author)
    if args.package_version:
        r.update_metadata('package_version', args.package_version)
    if args.tree_stats:
        r.update_phylo_model(args.stats_type,
                             args.tree_stats,
                             frequency_type=args.frequency_type)

    for file_name in [
            'aln_fasta', 'aln_sto', 'mask', 'profile', 'seq_info', 'taxonomy',
            'tree', 'tree_stats', 'readme'
    ]:
        path = getattr(args, file_name)
        if path:
            r.update_file(file_name, path)
    r._log('Loaded initial files into empty refpkg')
    r.commit_transaction()
    r.strip()

    reroot_prereqs = args.reroot and args.taxonomy and args.seq_info and args.tree
    if utils.has_rppr(args.rppr) and reroot_prereqs:
        r.start_transaction()
        logging.info('%s found. Rerooting.', args.rppr)
        r.reroot(rppr=args.rppr)
        r._log('Rerooted')
        r.commit_transaction()
    elif reroot_prereqs:
        log.warn('"%s" not found. Skipping rerooting', args.rppr)

    return 0
Example #2
0
def action(args):
    if args.clobber and os.path.isdir(args.package_name):
        try:
            shutil.rmtree(args.package_name)
        except:
            print >>sys.stderr, "Failed: Could not delete %s" % args.package_name
            return 1
    elif args.clobber and os.path.exists(args.package_name):
        try:
            os.unlink(args.package_name)
        except:
            print >>sys.stderr, "Failed: Could not delete %s" % args.package_name
            return 1
    elif not args.clobber and os.path.exists(args.package_name):
        print >> sys.stderr, 'Failed: {0} exists.'.format(args.package_name)
        return 1

    r = refpkg.Refpkg(args.package_name, create=True)
    r.start_transaction()
    r.update_metadata('locus', args.locus)  # Locus is required
    if args.description:
        r.update_metadata('description', args.description)
    if args.author:
        r.update_metadata('author', args.author)
    if args.package_version:
        r.update_metadata('package_version', args.package_version)
    if args.tree_stats:
        r.update_phylo_model(args.stats_type, args.tree_stats,
                             frequency_type=args.frequency_type)

    for file_name in ['aln_fasta', 'aln_sto', 'mask',
                      'profile', 'seq_info', 'taxonomy', 'tree', 'tree_stats',
                      'readme']:
        path = getattr(args, file_name)
        if path:
            r.update_file(file_name, path)
    r._log('Loaded initial files into empty refpkg')
    r.commit_transaction()
    r.strip()

    reroot_prereqs = args.reroot and args.taxonomy and args.seq_info and args.tree
    if utils.has_rppr(args.rppr) and reroot_prereqs:
        r.start_transaction()
        logging.info('%s found. Rerooting.', args.rppr)
        r.reroot(rppr=args.rppr)
        r._log('Rerooted')
        r.commit_transaction()
    elif reroot_prereqs:
        log.warn('"%s" not found. Skipping rerooting', args.rppr)

    return 0
Example #3
0
import unittest
import tempfile
import shutil
import json
import copy
import os
import os.path

from taxtastic import refpkg, utils
from . import config

HAS_RPPR = utils.has_rppr()


class TestRefpkg(unittest.TestCase):
    maxDiff = None

    def test_fails_on_file_exists(self):
        # Trying to attach to a normal file as a Refpkg should fail.
        with tempfile.NamedTemporaryFile() as tf:
            self.assertRaises(ValueError, refpkg.Refpkg, tf.name, create=False)

    def test_fails_on_dir_without_manifest(self):
        # Trying to attach to a non-Refpkg directory should fail.
        with config.tempdir() as td:
            self.assertRaises(ValueError, refpkg.Refpkg, td, create=False)

    def test_create(self):
        # Attaching to an empty directory should create a new, empty Refpkg.
        scratch = tempfile.mkdtemp()
        try:
Example #4
0
import unittest
import tempfile
import shutil
import json
import copy
import os
import os.path

from taxtastic import refpkg, utils
from . import config

HAS_RPPR = utils.has_rppr()


class TestReadStockholm(unittest.TestCase):
    def setUp(self):
        self.fname = os.path.join(config.data_path('lactobacillus2-0.2.refpkg'),
                                  'lactobacillus2.sto')

    def test01(self):
        with open(self.fname, 'r') as fobj:
            names = utils.parse_stockholm(fobj)
        self.assertEqual(len(names), 46)
        self.assertEqual(names[0], '123f3-34')
        self.assertEqual(names[-1], 'S000727873')

    def test02(self):
        with open(self.fname, 'r') as fobj:
            lines = [line for line in fobj][:-1]
            self.assertRaises(ValueError, utils.parse_stockholm, lines)