Esempio n. 1
0
    def get_dynamic_elements_ena(self, args):
        """
        function generates dynamic stages for ENA based on the study type
        :param args:
        :return:
        """

        args = args.split(",")
        # args: stub_ref

        stub_ref = args[0]

        study_type = self.get_batch_attributes()["study_type"][0]
        if not study_type:
            return list()

        study_type = study_type['study_type']

        # get protocols
        protocols = ISAHelpers().get_protocols_parameter_values(study_type)

        # get study assay schema
        schema_fields = getattr(DataSchemas("COPO").get_ui_template_as_obj().copo, study_type).fields

        # generate dynamic stages from protocols
        dynamic_stages = list()

        # get message dictionary
        message_dict = d_utils.json_to_pytype(lkup.MESSAGES_LKUPS["datafile_wizard"])["properties"]

        for pr in protocols:
            if len(pr.get("parameterValues", list())) > 0:

                title = pr.get("name", str()).title()
                ref = pr.get("name", str()).replace(" ", "_")
                message = message_dict.get(ref + "_message", dict()).get("text", str())

                stage_dict = dict(title=title,
                                  ref=ref,
                                  message=message,
                                  content=str("get_stage_html"),
                                  dependent_on=str("study_type"),
                                  stub_ref=stub_ref,
                                  items=list()
                                  )

                for f in schema_fields:
                    if f.ref in pr.get("parameterValues", list()):
                        if f.show_in_form:
                            elem = htags.get_element_by_id(f.id)
                            elem["id"] = elem['id'].strip(".").rsplit(".", 1)[1]
                            del elem['ref']
                            stage_dict.get("items").append(elem)
                dynamic_stages.append(stage_dict)

        return dynamic_stages
Esempio n. 2
0
def get_dynamic_elements_ena(datafile_id):
    # function mainly based on ena assays specification, reflective of the study type

    study_type = get_stage_data(datafile_id, "study_type")
    if not study_type:
        return []

    study_type = study_type["study_type"]
    normalised_ranked_list = EnaCollection().get_normalised_ranked_list(
        [], DataSchemas("ENA").get_ui_template()["ena"]["studies"]["study"]["assays"]["assaysTable"][study_type]
    )

    modified_ranked_list = EnaCollection().get_modified_ranked_list(normalised_ranked_list)

    # retrieve protocol nodes with sub items
    dynamic_elements = [
        elem for elem in modified_ranked_list if elem["name"] == "Protocol REF" and len(elem["items"]) > 0
    ]

    # make dynamic_elements wizard compliant, and remove redundant fields
    df_wizard_dict = copy.deepcopy(lkup.DF_WIZARD)

    if dynamic_elements:
        current_list = dynamic_elements
        for dye in dynamic_elements:
            indx = current_list.index(dye)
            current_list[indx]["title"] = (dye["value"]).title()
            try:
                current_list[indx]["message"] = df_wizard_dict[current_list[indx]["ref"] + "_message"]["text"]
            except:
                current_list[indx]["message"] = ""
            current_list[indx]["content"] = "get_stage_html"
            current_list[indx]["deposition_context"] = "ena"
            del current_list[indx]["value"]  # remove redundant field
            del current_list[indx]["name"]

            # sort out items
            items_dict = []
            for its in current_list[indx]["items"]:
                elem = htags.get_element_by_id(its["id"])
                elem["id"] = elem["id"].strip(".").rsplit(".", 1)[1]
                del elem["ref"]
                items_dict.append(elem)

            current_list[indx]["items"] = items_dict

        dynamic_elements = current_list

    return dynamic_elements