Exemple #1
0
def main():

    p = argparse.ArgumentParser(
        description='{} ({})'.format(__description__, __version__))
    p.add_argument('-d',
                   help="set type of search database",
                   required=True,
                   choices=['basic', 'enum', 'bit'])
    p.add_argument('-e',
                   help="set type of search problem (see config.json)",
                   required=True)
    p.add_argument('-p',
                   help="print the CVC code and return",
                   action='store_true')
    args = p.parse_args()

    path = './tmp/'
    f = path + '{}-{}-{}.csv'.format(args.d, args.e, utils.timestamp())

    if args.d == 'basic':
        import src.search.basic as search
        cmds = cmd.basic
    elif args.d == 'enum':
        import src.search.enum as search
        cmds = cmd.enum
    elif args.d == 'bit':
        import src.search.bit as search
        cmds = cmd.bit
    """ check if stp and solver are in PATH or node/bin """
    stp = utils.which('stp')
    solver = utils.which(cmds[args.e][0])
    if stp == None:
        print "stp not found in PATH or in node/bin"
        return 1
    if solver == None:
        print "solver {} not found in PATH or in node/bin".format(
            cmds[args.e][0])
        return 1

    if not args.p:
        """ start search """
        solutions = search.do(*cmds[args.e])
        if solutions != None:
            utils.to_csv(solutions, f)
            print "Solution(s) written to {}".format(f)
    else:
        """ print CVC code """
        print search.cvc(*cmds[args.e])
Exemple #2
0
def do( stdin = '', flags = SFLAGS ):
    path = which(NAME)
    try:
        popen = subprocess.Popen( [ path ] + flags, stdout = subprocess.PIPE, stdin = subprocess.PIPE )
        return popen.communicate()[0]
    except AttributeError as e:
        raise e
Exemple #3
0
def _check_system_tools():
    to_exit = False
    if not which('java'):
        err('\n* Warning: Java not found. You may want to run "module load java", '
            'or better ". /group/ngs/bin/bcbio-prod.sh"\n')
        to_exit = True

    if not which('perl'):
        err('\n* Warning: Perl not found. You may want to run "module load perl", '
            'or better ". /group/ngs/bin/bcbio-prod.sh"\n')

    # print ''
    # print 'In Waltham, run this as well:'
    # print '   export PATH=$PATH:/group/ngs/src/snpEff/snpEff3.5/scripts'
    # print '   export PERL5LIB=$PERL5LIB:/opt/az/local/bcbio-nextgen/'
    #       'stable/0.7.6/tooldir/lib/perl5/site_perl'
    if to_exit:
        exit()
Exemple #4
0
def main():

    p = argparse.ArgumentParser(description='{} ({})'.format(__description__,__version__))
    p.add_argument('-d',help="set type of search database",required=True,choices=['basic','enum','bit'])
    p.add_argument('-e',help="set type of search problem (see config.json)",required=True)
    p.add_argument('-p',help="print the CVC code and return",action='store_true')
    args = p.parse_args()

    path = './tmp/'
    f = path + '{}-{}-{}.csv'.format(args.d,args.e,utils.timestamp())

    if args.d == 'basic':
        import src.search.basic as search
        cmds = cmd.basic
    elif args.d == 'enum':
        import src.search.enum as search
        cmds = cmd.enum
    elif args.d == 'bit':
        import src.search.bit as search
        cmds = cmd.bit

    """ check if stp and solver are in PATH or node/bin """
    stp = utils.which('stp')
    solver = utils.which(cmds[args.e][0])
    if stp == None:
        print "stp not found in PATH or in node/bin"
        return 1
    if solver == None:
        print "solver {} not found in PATH or in node/bin".format(cmds[args.e][0])
        return 1

    if not args.p:
        """ start search """
        solutions = search.do(*cmds[args.e])
        if solutions != None:
            utils.to_csv( solutions, f )
            print "Solution(s) written to {}".format(f)
    else:
        """ print CVC code """
        print search.cvc(*cmds[args.e])
 def run_binary(self, binary, args):
     try:
         binary = which(binary)
     except:
         print(f'Unable to find {binary}... Exiting...')
         sys.exit(-1)
     # Wake up and do nothing on SIGUSR1
     signal.signal(signal.SIGUSR1, lambda x, y: None)
     # Reap zombies
     signal.signal(signal.SIGCHLD, self.handle_sigchld)
     pid = os.fork()
     # Setup traced process
     if pid == 0:
         signal.pause()
         os.execvp(binary, args)
     # Return pid of traced process
     return pid
Exemple #6
0
def get_script_cmdline_template(cnf, executable, script_name):
    if not which(executable):
        exit(executable + ' executable required, maybe you need '
             'to run "module load ' + executable + '"?')
    if 'resources' not in cnf:
        critical(cnf['log'], 'System config yaml must contain resources section with '
                 + script_name + ' path.')
    if script_name not in cnf['resources']:
        critical(cnf['log'], 'System config resources section must contain '
                 + script_name + ' info (with a path to the tool).')
    tool_config = cnf['resources'][script_name]
    if 'path' not in tool_config:
        critical(script_name + ' section in the system config must contain a path to the tool.')
    tool_path = tool_config['path']
    if not verify_file(tool_path, script_name):
        exit(1)
    return executable + ' %s ' + tool_path
Exemple #7
0
def get_tool_cmdline(sys_cnf, tool_name, extra_warn=''):
    tool_path = which(tool_name) or None

    if not 'resources' in sys_cnf \
            or tool_name not in sys_cnf['resources'] \
            or 'path' not in sys_cnf['resources'][tool_name]:
        if tool_path:
            return tool_path
        else:
            err(tool_name + ' executable was not found. '
                'You can either specify path in the system config, or load into your '
                'PATH environment variable.')
            if extra_warn:
                err(extra_warn)
            return None

    tool_path = sys_cnf['resources'][tool_name]['path']
    if verify_file(tool_path, tool_name):
        return tool_path
    else:
        err(tool_path + ' for ' + tool_name + ' does not exist or is not a file.')
        return None
Exemple #8
0
def _extract_fields(cnf, vcf_fpath, work_dir, sample_name=None):
    step_greetings(cnf, 'Extracting fields')

    name, _ = splitext_plus(basename(vcf_fpath))
    tsv_fpath = join(work_dir, name + '.tsv')

    if cnf.get('reuse_intermediate'):
        if file_exists(tsv_fpath):
            info(cnf['log'], tsv_fpath + ' exists, reusing')
            return tsv_fpath

    all_format_fields = set()

    # Split FORMAT field and sample fields
    def proc_line(l):
        if l.startswith('#'):
            return l
        vals = l.strip().split('\t')
        if len(vals) <= 9:
            return l
        info_field = vals[7]
        format_fields = vals[8].split(':')
        sample_fields = vals[9].split(':')
        for f, s in zip(format_fields, sample_fields):
            if f not in ['DP', 'MQ']:
                if f == 'GT':
                    s = '"' + s + '"'
                f = 'gt_' + f
                info_field += ';' + f + '=' + s
                all_format_fields.add(f)
        l = '\t'.join(vals[:7] + [info_field])
        return l
    split_format_fields_vcf = iterate_file(cnf, vcf_fpath, proc_line, work_dir,
        'split_format_fields', keep_original_if_not_keep_intermediate=True)

    manual_tsv_fields = cnf.get('tsv_fields')
    if manual_tsv_fields:
        fields = [rec.keys()[0] for rec in manual_tsv_fields]
    # else:
        # first_line = next(l.strip()[1:].split() for l in open(vcf_fpath)
        #   if l.strip().startswith('#CHROM'))
        # basic_fields = [f for f in first_line[:9] if f != 'INFO'
        #   and f != 'FORMAT' and f != sample_name]
        # manual_annots = filter(lambda f: f and f != 'ID', all_fields)
        # fields = (basic_fields + all_format_fields + manual_annots +
        #    self.run_cnf.get('additional_tsv_fields', []))
    else:
        return None

    anno_line = ' '.join(fields)
    snpsift_cmline = get_java_tool_cmdline(cnf, 'snpsift')

    if not which('perl'):
        exit('Perl executable required, maybe you need to run "module load perl"?')
    src_fpath = join(dirname(realpath(__file__)))
    vcfoneperline_cmline = 'perl ' + join(src_fpath, 'vcfOnePerLine.pl')
    cmdline = vcfoneperline_cmline + ' | ' + snpsift_cmline + ' extractFields - ' + anno_line

    with file_transaction(tsv_fpath) as tx_tsv_fpath:
        info(cnf['log'], cmdline + ' < ' + (split_format_fields_vcf
                                            or vcf_fpath) + ' > ' + tx_tsv_fpath)
        res = subprocess.call(cmdline,
                              stdin=open(split_format_fields_vcf or vcf_fpath),
                              stdout=open(tx_tsv_fpath, 'w'), shell=True)

    if split_format_fields_vcf:
        os.remove(split_format_fields_vcf)

    info(cnf['log'], '')
    if res != 0:
        critical(cnf['log'], 'Command returned status ' + str(res) +
                 ('. Log in ' + cnf['log'] if 'log' in cnf else '.'))
    return tsv_fpath
def check_oc_command(context):
    """Check if 'oc' command is available for the current user."""
    assert which("oc"), "The 'oc' command is not found. " +\
        "Have you installed the OpenShift Console tool?"
Exemple #10
0
from os.path import join, isfile

from src.config import Config
from src.docker_controller import DEFAULT_IMAGE_NAME
from src.docker_controller import DockerController
from src.genesis import Genesis
from src.node import Node
from src.node import TEST_TEMP_DIR
from src.utils import which, remove_dir_tree, create_dir
from src.wallet import Wallet
from tests.common import check_file_creation
from tests.data import *

SCORUMD_BIN_PATH = which('scorumd')


def pytest_addoption(parser):
    parser.addoption('--target', action='store', default=SCORUMD_BIN_PATH, help='specify path to scorumd')
    parser.addoption('--image', action='store', default=DEFAULT_IMAGE_NAME, help='specify image for tests run')
    parser.addoption('--use-local-image', action='store_false', help='dont rebuild image')
    parser.addoption(
        '--long-term', action='store_true',
        help='Include long-term tests. Could take significantly long time.'
    )


@pytest.fixture(autouse=True)
def skip_long_term(request):
    if request.node.get_marker("skip_long_term"):
        if not request.config.getoption("--long-term"):
            pytest.skip("Long term tests are skipped. Use '--long-term' to enable it.")