Ejemplo n.º 1
0
def explore(ctx, name, ids, recalculate=None, **kwargs):
    kwargs.update(ctx.parent.objs)
    engine = kwargs['engine']
    config = kwargs['config']
    mod.reflect(engine)

    try:
        setup.expand_stage_pattern(name, 'recalculate', kwargs)
        setup.expand_stage_pattern(name, 'skip_stage', kwargs)
    except introspect.UnknownStageError as err:
        click.secho("Unknown stage %s" % err.args, err=True, fg='red')
        ctx.exit(1)

    if not ids:
        ids = setup.pdbs(config, kwargs)

    kwargs['exclude'] = kwargs.get('skip_stage')

    dispatcher = Dispatcher(name, config, sessionmaker(engine), **kwargs)
    result = []
    for stage in dispatcher.stages(name):
        recalc = ''
        if recalculate is True or stage.name in recalculate:
            recalc = 'Will Recalculate'
        result.append((stage.name, recalc))
    formatter = click.HelpFormatter(width=90)
    formatter.write_dl(result)
    click.echo(formatter.getvalue(), nl=False)
 def test_can_exclude_stages_in_container(self):
     dispatcher = Dispatcher('motifs.loader', CONFIG, Session,
                             skip_dependencies=True,
                             exclude=['motifs.release'])
     val = [o.name for o in dispatcher.stages('motifs.loader')]
     assert 'motifs.release' not in val
     assert val == [
         'motifs.discrepancies',
         'motifs.info',
         'motifs.assignments',
         'motifs.loop_order',
         'motifs.loop_positions',
     ]
 def setUp(self):
     self.dispatcher = Dispatcher('units.info', CONFIG, Session)
Ejemplo n.º 4
0
def run(ctx, name, ids, config=None, engine=None, **kwargs):
    """Actually run the pipeline. This is the main function which will load and
    run the stages requested. It fetch PDBs to run if needed, reflect the
    models, run stages, and send an email as needed.

    Parameters
    ----------
    name : str
        The name of the stage to run.
    ids : list
        The PDB ids to use.
    config : dict
        The configuration dictionary as produced by pymotifs.config.load.
    engine : Engine
    The SQL Alchemy engine connection.
    **kwargs : dict, optional
        The other keyword arguments which will be passed to dispatcher.
    """

    if kwargs.get('seed', None) is not None:
        random.seed(kwargs['seed'])

    mod.reflect(engine)

    if kwargs.get('redo', False) is True:
        kwargs['recalculate'] = '.'
        kwargs['skip_dependencies'] = True

    try:
        setup.expand_stage_pattern(name, 'recalculate', kwargs)
        setup.expand_stage_pattern(name, 'skip_stage', kwargs)
    except introspect.UnknownStageError as err:
        click.secho("Unknown stage %s" % err.args, err=True, fg='red')
        ctx.exit(1)

    # get desired PDB IDs
    if not ids:
        ids = setup.pdbs(config, kwargs)

    logging.info("There are %d files listed to skip in skip_files.py" %
                 len(SKIP))
    logging.info(
        "There are %d files from skip_files.py that are also current PDB ids" %
        len(SKIP & set(ids)))

    logging.info(
        "The following files in skip_files.py are not current PDB files")
    logging.info(SKIP - set(ids))

    # remove files from skip_files.py from the list of PDB IDs to process
    ids = sorted(set(ids) - SKIP)

    logging.info("Found %d files to process" % len(ids))

    kwargs['exclude'] = kwargs.get('skip_stage')

    logging.info("Running from command %s", ' '.join(sys.argv))
    error = None
    dispatcher = Dispatcher(name, config, sessionmaker(engine), **kwargs)
    mailer = Emailer(config, engine)
    try:
        dispatcher(ids, **kwargs)
    except Exception as error:
        click.secho("Pipeline failed", fg='red', err=True)
        logging.exception(error)
        ctx.exit(1)
    finally:
        if kwargs['email']:
            mailer(name, ids=ids, error=error, **kwargs)