Ejemplo n.º 1
0
def fillin(context, sample_id):
    """Fill in defaults for a LIMS sample."""
    lims_api = api.connect(context.obj)
    lims_sample = lims_api.sample(sample_id)
    click.echo("filling in defaults...")
    set_defaults(lims_sample)
    lims_sample.put()
    click.echo("saved new defaults")
Ejemplo n.º 2
0
def get(context, condense, project, external, minimal, raw_identifier, field,
        all_samples):
    """Get information from LIMS: either sample or family samples."""
    if '--' in raw_identifier:
        identifier, ext = raw_identifier.split('--', 1)
    else:
        identifier, ext = raw_identifier, None

    lims = api.connect(context.obj)
    if project:
        lims_samples = lims.get_samples(projectlimsid=identifier)
    elif identifier.startswith('cust'):
        # look up samples in a case
        lims_samples = lims.case(*identifier.split('-', 1))
    elif external:
        lims_samples = lims.get_samples(name=identifier)
    else:
        # look up a single sample
        is_cgid = True if identifier[0].isdigit() else False
        lims_samples = [lims.sample(identifier, is_cgid=is_cgid)]

    if len(lims_samples) > 1 and not all_samples:
        # filter out tumor and cancelled samples
        lims_samples = relevant_samples(lims_samples)

    for lims_sample in lims_samples:
        sample_obj = ClinicalSample(lims_sample)
        data = sample_obj.to_dict(minimal=minimal)
        data['sample_id'] = "{}--{}".format(data['sample_id'],
                                            ext) if ext else data['sample_id']
        data['case_id'] = "{}--{}".format(data['case_id'],
                                          ext) if ext else data['case_id']

        if field:
            if field not in data:
                log.error("can't find UDF on sample: %s", field)
                context.abort()
            elif isinstance(data[field], list):
                for item in data[field]:
                    click.echo(item)
            else:
                click.echo(data[field])
        else:
            if condense:
                dump = jsonify(data)
            else:
                raw_dump = yaml.safe_dump(data,
                                          default_flow_style=False,
                                          allow_unicode=True)
                dump = fix_dump(raw_dump)
                click.echo(click.style('>>> Sample: ', fg='red'), nl=False)
                click.echo(click.style(data['id'], bold=True, fg='red'))
                if data.get('cancelled') == 'yes':
                    click.echo(click.style('CANCELLED', bold=True,
                                           fg='yellow'))
            click.echo(dump)
Ejemplo n.º 3
0
def sample(context, delivered, lims_id):
    """Fetch information about a sample."""
    lims_api = api.connect(context.obj)
    if delivered:
        delivery_date = lims_api.is_delivered(lims_id)
        if delivery_date:
            click.echo(delivery_date)
        else:
            log.error("sample not yet delivered")
            context.abort()
Ejemplo n.º 4
0
def update(context, lims_id, field_key, new_value):
    """Update a UDF for a sample."""
    lims = api.connect(context.obj)
    lims_sample = lims.sample(lims_id)
    old_value = lims_sample.udf.get(field_key, 'N/A').encode('utf-8')
    click.echo("about to update sample: {}".format(lims_sample.id))
    message_tmlt = "are you sure you want to change '{}': '{}' -> '{}'"
    if click.confirm(message_tmlt.format(field_key, old_value, new_value)):
        lims_sample.udf[field_key] = new_value
        lims_sample.put()
Ejemplo n.º 5
0
def samples(context, source, apptags, lims_id):
    """Fetch projects from the database."""
    lims = api.connect(context.obj)
    if source == 'process':
        lims_process = Process(lims, id=lims_id)
        lims_samples = process_samples(lims_process)
    elif source == 'project':
        lims_samples = ({'sample': sample} for sample in
                        lims.get_samples(projectlimsid=lims_id))
    for lims_sample in lims_samples:
        click.echo(lims_sample.id)
Ejemplo n.º 6
0
def export(context, customer_or_case, family_id):
    """Parse out interesting data about a case."""
    lims = api.connect(context.obj)
    if family_id:
        customer = customer_or_case
    else:
        customer, family_id = customer_or_case.split('-', 1)
    lims_samples = lims.case(customer, family_id)
    case_data = export_case(lims, lims_samples)

    raw_dump = yaml.safe_dump(case_data,
                              default_flow_style=False,
                              allow_unicode=True)
    click.echo(raw_dump)
Ejemplo n.º 7
0
def check(context, update, version, force, source, lims_id):
    """Check LIMS sample or all samples in a process."""
    lims = api.connect(context.obj)
    if source == 'sample':
        lims_samples = [{'sample': lims.sample(lims_id)}]
    elif source == 'process':
        lims_process = Process(lims, id=lims_id)
        lims_samples = process_samples(lims_process)
    elif source == 'project':
        lims_samples = ({'sample': sample} for sample in
                        lims.get_samples(projectlimsid=lims_id))

    for sample in lims_samples:
        check_sample(lims, sample['sample'], lims_artifact=sample.get('artifact'),
                     update=update, version=version, force=force)
Ejemplo n.º 8
0
def pedigree(context, gene_panel, family_id, samples, customer_family):
    """DEPRECATED: Create pedigree from LIMS."""
    lims_api = api.connect(context.obj)
    if customer_family:
        lims_samples = lims_api.case(*customer_family)
    elif samples:
        lims_samples = [lims_api.sample(sample_id) for sample_id in samples]
    else:
        click.echo("you need to provide customer+family or samples")
        context.abort()
    content = make_pedigree(lims_api,
                            lims_samples,
                            family_id=family_id,
                            gene_panel=gene_panel)
    click.echo(content)
Ejemplo n.º 9
0
def config(context, gene_panel, family_id, samples, capture_kit, force,
           raw_case_id):
    """Create pedigree YAML file from LIMS data."""
    if '--' in raw_case_id:
        case_id, ext = raw_case_id.split('--', 1)
    else:
        case_id, ext = raw_case_id, None
    customer, family = case_id.split('-', 1)

    lims_api = api.connect(context.obj)
    gene_panels = [gene_panel] if gene_panel else None

    if samples:
        lims_samples = [lims_api.sample(sample_id) for sample_id in samples]
    else:
        lims_samples = lims_api.case(customer, family)

    included_samples = relevant_samples(lims_samples)
    data = make_config(lims_api,
                       included_samples,
                       family_id=family_id,
                       gene_panels=gene_panels,
                       capture_kit=capture_kit,
                       force=force)

    if ext:
        # handle cases with e.g. downsampled data
        data['family'] = '--'.join([data['family'], ext])
        for sample in data['samples']:
            sample['sample_id'] = '--'.join([sample['sample_id'], ext])

    # handle single sample cases with 'unknown' phenotype
    if len(data['samples']) == 1:
        if data['samples'][0]['phenotype'] == 'unknown':
            log.info("setting 'unknown' phenotype to 'unaffected'")
            data['samples'][0]['phenotype'] = 'unaffected'

    dump = yaml.safe_dump(data, default_flow_style=False, allow_unicode=True)
    click.echo(fix_dump(dump))