Ejemplo n.º 1
0
def analyse(ctx, sampleinfo_file, input, config, dry, email, skip_update,
            force_update, untrimmed, uncareful):
    """Sequence analysis, typing and resistance identification"""
    # Run section
    pool = []
    trimmed = not untrimmed
    careful = not uncareful
    set_cli_config(config)
    ctx.obj["config"]["regex"]["mail_recipient"] = email
    ctx.obj["config"]["dry"] = dry
    if not os.path.isdir(input):
        click.echo(
            "ERROR - Sequence data folder {} does not exist.".format(input))
        ctx.abort()
    for subfolder in os.listdir(input):
        if os.path.isdir("{}/{}".format(input, subfolder)):
            pool.append(subfolder)

    run_settings = {
        "input": input,
        "dry": dry,
        "email": email,
        "skip_update": skip_update,
        "trimmed": not untrimmed,
        "careful": not uncareful,
        "pool": pool,
    }

    # Samples section
    sampleinfo = review_sampleinfo(sampleinfo_file)
    run_creator = Job_Creator(
        config=ctx.obj["config"],
        log=ctx.obj["log"],
        sampleinfo=sampleinfo,
        run_settings=run_settings,
    )

    ext_refs = Referencer(config=ctx.obj["config"],
                          log=ctx.obj["log"],
                          sampleinfo=sampleinfo,
                          force=force_update)
    click.echo("INFO - Checking versions of references..")
    try:
        if not skip_update:
            ext_refs.identify_new(project=True)
            ext_refs.update_refs()
            click.echo("INFO - Version check done. Creating sbatch jobs")
        else:
            click.echo("INFO - Skipping version check.")
    except Exception as e:
        click.echo("{}".format(e))
    if len(sampleinfo) > 1:
        run_creator.project_job()
    elif len(sampleinfo) == 1:
        run_creator.project_job(single_sample=True)
    else:
        ctx.abort()

    done()
Ejemplo n.º 2
0
def autobatch(ctx, dry, skip_update, email):
    """Analyses all currently unanalysed projects in the seqdata folder"""
    # Trace exists by some samples having pubMLST_ST filled in. Make trace function later
    ctx.obj["config"]["regex"]["mail_recipient"] = email
    ext_refs = Referencer(config=ctx.obj["config"], log=ctx.obj["log"])
    if not skip_update:
        ext_refs.identify_new(project=True)
        ext_refs.update_refs()

    process = subprocess.Popen(
        'squeue --format="%50j" -h -r'.split(), stdout=subprocess.PIPE
    )
    run_jobs, error = process.communicate()
    run_jobs = run_jobs.splitlines()
    run_jobs = [
        re.search('"(.+)"', str(jobname)).group(1).replace(" ", "")
        for jobname in run_jobs
    ]
    old_jobs = os.listdir(ctx.obj["config"]["folders"]["results"])

    for foldah in os.listdir(ctx.obj["config"]["folders"]["seqdata"]):
        # Project name not found in slurm list
        if len([job for job in run_jobs if foldah in job]) == 0:
            # Project name not found in results directories
            if len([job for job in old_jobs if foldah in job]) == 0:
                if dry:
                    click.echo(
                        "DRY - microSALT analyse {} --skip_update".format(foldah)
                    )
                else:
                    process = subprocess.Popen(
                        "microSALT analyse project {} --skip_update".format(
                            foldah
                        ).split(),
                        stdout=subprocess.PIPE,
                    )
                    output, error = process.communicate()
            elif dry:
                click.echo(
                    "INFO - Skipping {} due to existing analysis in results folder".format(
                        foldah
                    )
                )
        elif dry:
            click.echo("INFO - Skipping {} due to concurrent SLURM run".format(foldah))
    done()
Ejemplo n.º 3
0
def init_references(testdata):
    ref_obj = Referencer(config=preset_config, log=logger, sampleinfo=testdata)
    ref_obj.identify_new(testdata[0].get('CG_ID_project'), project=True)
    ref_obj.update_refs()
Ejemplo n.º 4
0
def finish(ctx, sampleinfo_file, input, track, config, dry, email, skip_update,
           report, output):
    """Sequence analysis, typing and resistance identification"""
    # Run section
    pool = []
    set_cli_config(config)
    ctx.obj["config"]["regex"]["mail_recipient"] = email
    ctx.obj["config"]["dry"] = dry
    if not os.path.isdir(input):
        click.echo(
            "ERROR - Sequence data folder {} does not exist.".format(input))
        ctx.abort()
    if output == "":
        output = input
    for subfolder in os.listdir(input):
        if os.path.isdir("{}/{}".format(input, subfolder)):
            pool.append(subfolder)

    run_settings = {
        "input": input,
        "track": track,
        "dry": dry,
        "email": email,
        "skip_update": skip_update,
    }

    # Samples section
    sampleinfo = review_sampleinfo(sampleinfo_file)
    ext_refs = Referencer(config=ctx.obj["config"],
                          log=ctx.obj["log"],
                          sampleinfo=sampleinfo)
    click.echo("INFO - Checking versions of references..")
    try:
        if not skip_update:
            ext_refs.identify_new(project=True)
            ext_refs.update_refs()
            click.echo("INFO - Version check done. Creating sbatch jobs")
        else:
            click.echo("INFO - Skipping version check.")
    except Exception as e:
        click.echo("{}".format(e))

    res_scraper = Scraper(config=ctx.obj["config"],
                          log=ctx.obj["log"],
                          sampleinfo=sampleinfo,
                          input=input)
    if isinstance(sampleinfo, list) and len(sampleinfo) > 1:
        res_scraper.scrape_project()
        # for subfolder in pool:
        #  res_scraper.scrape_sample()
    else:
        res_scraper.scrape_sample()

    codemonkey = Reporter(
        config=ctx.obj["config"],
        log=ctx.obj["log"],
        sampleinfo=sampleinfo,
        output=output,
        collection=True,
    )
    codemonkey.report(report)
    done()