Example #1
0
    def generate_stage_items(self):

        sample_types = list()

        for s_t in d_utils.get_sample_type_options():
            sample_types.append(s_t["value"])

        wizard_stages = dict()

        # get start stages
        start = d_utils.json_to_pytype(lkup.WIZARD_FILES["sample_start"])['properties']
        wizard_stages['start'] = start

        # if required, resolve data source for select-type controls,
        # i.e., if a callback is defined on the 'option_values' field
        for stage in wizard_stages['start']:
            if "items" in stage:
                for st in stage['items']:
                    if "option_values" in st:
                        st["option_values"] = htags.get_control_options(st)

        # get sample types
        for s_t in sample_types:
            s_stages = d_utils.json_to_pytype(lkup.WIZARD_FILES["sample_attributes"])['properties']

            form_schema = list()

            for f in self.schema:
                # get relevant attributes based on sample type
                if f.get("show_in_form", True) and s_t in f.get("specifications", sample_types):
                    # if required, resolve data source for select-type controls,
                    # i.e., if a callback is defined on the 'option_values' field
                    if "option_values" in f:
                        f["option_values"] = htags.get_control_options(f)

                    # change sample-source control to wizard-compliant version
                    if f.get("control", str()) == "copo-sample-source":
                        f["control"] = "copo-sample-source-2"

                    # get short-form id
                    f["id"] = f["id"].split(".")[-1]

                    # might not need to include name
                    if f["id"] == "name":
                        continue

                    form_schema.append(f)

                for p in s_stages:
                    if p["ref"] == "sample_attributes":
                        p["items"] = form_schema

            wizard_stages[s_t] = s_stages

        return wizard_stages
Example #2
0
def generate_attributes(component, target_id):
    da_object = DAComponent(component=component)

    if component in da_dict:
        da_object = da_dict[component]()

    # get and filter schema elements based on displayable columns
    schema = [x for x in da_object.get_schema().get("schema_dict") if x.get("show_as_attribute", False)]

    # build db column projection
    projection = [(x["id"].split(".")[-1], 1) for x in schema]

    # account for description metadata in datafiles
    if component == "datafile":
        projection.append(('description', 1))

    filter_by = dict(_id=ObjectId(target_id))
    record = da_object.get_all_records_columns(projection=dict(projection), filter_by=filter_by)

    result = dict()

    if len(record):
        record = record[0]

        if component == "sample":  # filter based on sample type
            sample_types = [s_t['value'] for s_t in d_utils.get_sample_type_options()]
            sample_type = record.get("sample_type", str())
            schema = [x for x in schema if sample_type in x.get("specifications", sample_types)]

        for x in schema:
            x['id'] = x["id"].split(".")[-1]

        if component == "datafile":
            key_split = "___0___"
            attributes = record.get("description", dict()).get("attributes", dict())
            stages = record.get("description", dict()).get("stages", list())

            datafile_attributes = dict()
            datafile_items = list()

            for st in stages:
                for item in st.get("items", list()):
                    if str(item.get("hidden", False)).lower() == "false":
                        atrib_val = attributes.get(st["ref"], dict()).get(item["id"], str())
                        item["id"] = st["ref"] + key_split + item["id"]
                        datafile_attributes[item["id"]] = atrib_val
                        datafile_items.append(item)

            record.update(datafile_attributes)
            schema = schema + datafile_items

        result = resolve_display_data(schema, record)

    return result
Example #3
0
def filter_sample_type(form_value, elem):
    # filters UI elements based on sample type

    allowable = True
    default_type = "biosample"
    sample_types = list()

    for s_t in d_utils.get_sample_type_options():
        sample_types.append(s_t["value"])

    if "sample_type" in form_value:
        default_type = form_value["sample_type"]

    if default_type not in elem.get("specifications", sample_types):
        allowable = False

    return allowable
Example #4
0
def filter_sample_type(form_value, elem):
    # filters UI elements based on sample type

    allowable = True
    default_type = "biosample"
    sample_types = list()

    for s_t in d_utils.get_sample_type_options():
        sample_types.append(s_t["value"])

    if "sample_type" in form_value:
        default_type = form_value["sample_type"]

    if default_type not in elem.get("specifications", sample_types):
        allowable = False

    return allowable
Example #5
0
    def generate_attributes(self, target_id):

        sample_attributes = dict()
        record = Sample().get_record(target_id)
        sample_attributes["record"] = record
        table_schema = list()

        sample_types = list()

        for s_t in d_utils.get_sample_type_options():
            sample_types.append(s_t["value"])

        sample_type = str()

        if "sample_type" in record:
            sample_type = record["sample_type"]

        for f in self.schema:
            # get relevant attributes based on sample type
            if f.get("show_in_sub_table", False) and sample_type in f.get("specifications", sample_types):
                # if required, resolve data source for select-type controls,
                # i.e., if a callback is defined on the 'option_values' field
                if "option_values" in f:
                    f["option_values"] = htags.get_control_options(f)

                # change sample-source control to wizard-compliant version
                if f.get("control", str()) == "copo-sample-source":
                    f["control"] = "copo-sample-source-2"

                # get short-form id
                f["id"] = f["id"].split(".")[-1]

                # might not need to include name
                if f["id"] == "name":
                    continue

                table_schema.append(f)

        sample_attributes["schema"] = table_schema

        return sample_attributes