def sample_status_per_plate(session):
    """This function queries the lims database for sample information and aggregate at the plate name level"""
    match = json.loads(request.args.get('match', '{}'))
    project_name = match.get('project_id')
    all_plates = defaultdict(Container)
    sample_to_container = {}
    for result in get_sample_info(session, project_name, udfs=['Prep Workflow', 'Species']):
        (pjct_name, sample_name, container, wellx, welly, udf_name, udf_value) = result
        all_plates[container].name = container
        all_plates[container].project_id = pjct_name
        if udf_name == 'Prep Workflow':
            all_plates[container].samples[sanitize_user_id(sample_name)].planned_library = udf_value
        if udf_name == 'Species':
            all_plates[container].samples[sanitize_user_id(sample_name)].species = udf_value
        sample_to_container[sample_name] = container

    for result in get_samples_and_processes(
            session,
            project_name,
            workstatus='COMPLETE',
            list_process=list(status_cfg.step_completed_to_status) \
                       + list(status_cfg.additional_step_completed) \
                       + list(status_cfg.library_type_step_completed)
    ):
        (pjct_name, sample_name, process_name, process_status, date_run) = result
        container = sample_to_container.get(sample_name)
        all_plates[container].samples[sanitize_user_id(sample_name)].add_completed_process(process_name, date_run)

    for result in non_QC_queues(session, project_name, list_process=status_cfg.step_queued_to_status):
        pjct_name, sample_name, process_name, queued_date = result
        container = sample_to_container.get(sample_name)
        all_plates[container].samples[sanitize_user_id(sample_name)].add_queue_location(process_name, queued_date)

    return [p.to_json() for p in all_plates.values()]
def sample_status_per_project(session):
    """This function queries the lims database for sample information and aggregate at the project name level"""
    match = json.loads(request.args.get('match', '{}'))
    project_name = match.get('project_id')
    all_projects = defaultdict(Project)
    for project_info in get_project_info(session, project_name, udfs=['Number of Quoted Samples']):
        pjct_name, open_date, firstname, lastname, udf_name , nb_quoted_samples = project_info
        all_projects[pjct_name].name = pjct_name
        all_projects[pjct_name].open_date = open_date.isoformat() + 'Z'
        all_projects[pjct_name].researcher_name = '%s %s' % (firstname, lastname)
        all_projects[pjct_name].nb_quoted_samples = nb_quoted_samples

    for result in get_samples_and_processes(
            session,
            project_name,
            workstatus='COMPLETE',
            list_process=list(status_cfg.step_completed_to_status) \
                       + list(status_cfg.additional_step_completed) \
                       + list(status_cfg.library_type_step_completed)
    ):
        (pjct_name, sample_name, process_name, process_status, date_run) = result
        all_projects[pjct_name].samples[sanitize_user_id(sample_name)].add_completed_process(process_name, date_run)

    for result in non_QC_queues(session, project_name, list_process=status_cfg.step_queued_to_status):
        pjct_name, sample_name, process_name, queued_date = result
        all_projects[pjct_name].samples[sanitize_user_id(sample_name)].add_queue_location(process_name, queued_date)

    for result in get_sample_info(session, project_name, udfs=['Prep Workflow', 'Species']):
        (pjct_name, sample_name, container, wellx, welly, udf_name, udf_value) = result
        if udf_name == 'Prep Workflow':
            all_projects[pjct_name].samples[sanitize_user_id(sample_name)].planned_library = udf_value
        if udf_name == 'Species':
            all_projects[pjct_name].samples[sanitize_user_id(sample_name)].species = udf_value

    return [p.to_json() for p in all_projects.values()]
示例#3
0
def _create_samples_info(session, match):
    """Query the LIMS database for sample information and create SampleInfo objects"""
    all_samples = defaultdict(data_models.SampleInfo)
    project_id = match.get('project_id')
    project_status = match.get('project_status', 'open')
    sample_id = match.get('sample_id')
    time_since = match.get('createddate')

    for result in queries.get_sample_info(session,
                                          project_id,
                                          sample_id,
                                          time_since=time_since,
                                          udfs='all',
                                          project_status=project_status):
        (pjct_name, sample_name, container, wellx, welly, udf_name,
         udf_value) = result
        s = all_samples[sanitize_user_id(sample_name)]
        s.sample_name = sanitize_user_id(sample_name)
        s.project_name = pjct_name
        s.plate_name = container
        s.original_name = sample_name
        s.udfs[udf_name] = udf_value

    return all_samples.values()
示例#4
0
def _create_samples(session, match):
    """Query the LIMS database for sample information and create Sample objects"""
    all_samples = defaultdict(data_models.Sample)
    project_id = match.get('project_id')
    project_status = match.get('project_status', 'open')
    sample_id = match.get('sample_id')
    sample_time_since = match.get('createddate')
    process_limit_date = match.get('process_limit_date')
    detailed = request.args.get('detailed') in ['true', 'True', True]
    if detailed:
        list_process_complete = None
        list_process_queued = None
    else:
        list_process_complete = list(status_cfg.step_completed_to_status) \
                       + list(status_cfg.additional_step_completed) \
                       + list(status_cfg.library_type_step_completed) \
                       + status_cfg.started_steps
        list_process_queued = status_cfg.step_queued_to_status
    udfs_to_fields = {
        'Prep Workflow': 'planned_library',
        'Species': 'species',
        'Required Yield (Gb)': 'required_yield',
        'Coverage (X)': 'coverage'
    }
    for result in queries.get_sample_info(session,
                                          project_id,
                                          sample_id,
                                          project_status=project_status,
                                          time_since=sample_time_since,
                                          udfs=list(udfs_to_fields)):
        (pjct_name, sample_name, container, wellx, welly, udf_name,
         udf_value) = result
        s = all_samples[sanitize_user_id(sample_name)]
        s.sample_name = sanitize_user_id(sample_name)
        s.project_name = pjct_name
        s.plate_name = container
        s.original_name = sample_name
        if udf_name in udfs_to_fields:
            setattr(all_samples[sanitize_user_id(sample_name)],
                    udfs_to_fields[udf_name], udf_value)

    for result in queries.get_samples_and_processes(
            session,
            project_id,
            sample_id,
            project_status=project_status,
            workstatus='COMPLETE',
            list_process=list_process_complete,
            time_since=sample_time_since,
            process_limit_date=process_limit_date):
        (pjct_name, sample_name, process_name, process_status, date_run,
         process_id) = result
        all_samples[sanitize_user_id(sample_name)].add_completed_process(
            process_name, date_run, process_id)

    for result in queries.get_sample_in_queues_or_progress(
            session,
            project_id,
            sample_id,
            list_process=list_process_queued,
            time_since=sample_time_since,
            project_status=project_status,
            process_limit_date=process_limit_date):
        pjct_name, sample_name, process_name, queued_date, queue_id, process_id, process_date = result
        if not process_id:
            all_samples[sanitize_user_id(sample_name)].add_queue_location(
                process_name, queued_date, queue_id)
        else:
            all_samples[sanitize_user_id(sample_name)].add_inprogress(
                process_name, process_date, process_id)

    return all_samples.values()