def run_ne_workflow(global_variables, biotype):

    print "-" * len(list(biotype))
    print biotype
    print "-" * len(list(biotype))
    print

    # gets the config for the workflow
    config = global_variables["config"]["NE"]

    # gets the outpath for the workflow - as we use this a lot
    out_path = os.path.join(global_variables["out_path"], biotype,
                            "ne_workflow")

    for element in config:

        element_name, element_active, element_type, element_subtype, element_path = element

        if check_element_prerequisites(element_active, element_type,
                                       element_subtype, element_path,
                                       global_variables):

            # methods for the core workflow
            if element_name == "ne_sub_directories_core" and element_type == "core":
                core_sub_directories(global_variables, out_path)
            elif element_name == "ne_file_matrix_annotated" and element_type == "core":
                ne_matrix_annotated(global_variables, out_path, biotype)
            elif element_name == "ne_file_matrix_IDs" and element_type == "core":
                ne_matrix_IDs(global_variables, out_path, biotype)
            elif element_name == "ne_file_matrix_symbols" and element_type == "core":
                ne_matrix_symbols(global_variables, out_path, biotype)
            elif element_name == "ne_file_gene_IDs" and element_type == "core":
                ne_gene_IDs(global_variables, out_path, biotype)
            elif element_name == "ne_file_gene_symbols" and element_type == "core":
                ne_gene_symbols(global_variables, out_path, biotype)

            # methods for statistical analysis

            # methods for the plots
            elif element_name == "ne_start_plots" and element_type == "plot_core":
                pr_dictionary = start_plots(global_variables, out_path, "ne",
                                            None)
            elif element_type == "plot":
                add_plot(element_path, pr_dictionary)
            elif element_name == "ne_end_plots" and element_type == "plot_core":
                end_plots(pr_dictionary)
            elif element_name == "ne_run_r" and element_type == "plot_core":
                run_r(pr_dictionary)

            # methods for the report
            elif element_name == "ne_start_report" and element_type == "report_core":
                start_report(global_variables, pr_dictionary, element_path)
            elif element_type == "report_title":
                add_header_section_to_report(element_path, pr_dictionary)
            elif element_type == "report_text":
                add_text_section_to_report(element_path, pr_dictionary,
                                           global_variables)
            elif element_type == "report_plot":
                add_plot_section_to_report(element_path, pr_dictionary,
                                           global_variables)
            elif element_name == "ne_end_report" and element_type == "report_core":
                end_report(pr_dictionary)
            print "done with: " + element_name.replace("_", " ")

    print
def run_mde_workflow(global_variables, biotype):

    print "-" * len(list(biotype))
    print biotype
    print "-" * len(list(biotype))
    print

    # gets the config for the workflow
    config = global_variables["config"]["MDE"]

    # iterates through the des
    parsed_mde_parameters = global_variables["mde_parameters"]
    for mde_dict in parsed_mde_parameters:
        mde_ID = mde_dict["mde_ID"]
        de_IDs = mde_dict["de_IDs"]

        print mde_ID

        # gets the outpath for the workflow - as we use this a lot
        out_path = os.path.join(global_variables["out_path"], biotype,
                                "mde_workflows", mde_ID)

        for element in config:

            element_name, element_active, element_type, element_subtype, element_path = element

            # checks prerequisites have been met:
            if check_element_prerequisites(element_active, element_type,
                                           element_subtype, element_path,
                                           global_variables):

                # methods for the core workflow
                if element_name == "mde_sub_directories_core" and element_type == "core":
                    core_sub_directories(global_variables, out_path)

                elif element_name == "mde_file_all_genes_IDs" and element_type == "core":
                    Mde_IDs(global_variables, out_path, biotype, de_IDs)
                elif element_name == "mde_file_genes_significant_in_any_comparison_IDs" and element_type == "core":
                    Mde_any_significant_IDs(global_variables, out_path,
                                            biotype, de_IDs)
                elif element_name == "mde_file_genes_significant_in_all_comparisons_IDs" and element_type == "core":
                    Mde_all_significant_IDs(global_variables, out_path,
                                            biotype, de_IDs)

                elif element_name == "mde_file_all_genes_symbols" and element_type == "core":
                    Mde_symbols(global_variables, out_path, biotype, de_IDs)
                elif element_name == "mde_file_genes_significant_in_any_comparison_symbols" and element_type == "core":
                    Mde_any_significant_symbols(global_variables, out_path,
                                                biotype, de_IDs)
                elif element_name == "mde_file_genes_significant_in_all_comparisons_symbols" and element_type == "core":
                    Mde_all_significant_symbols(global_variables, out_path,
                                                biotype, de_IDs)

                elif element_name == "mde_file_all_genes_annotated" and element_type == "core":
                    Mde_annotated(global_variables, out_path, biotype, de_IDs)
                elif element_name == "mde_file_genes_significant_in_any_comparison_annotated" and element_type == "core":
                    Mde_any_significant_annotated(global_variables, out_path,
                                                  biotype, de_IDs)
                elif element_name == "mde_file_genes_significant_in_all_comparisons_annotated" and element_type == "core":
                    Mde_all_significant_annotated(global_variables, out_path,
                                                  biotype, de_IDs)

                # methods for statistical analysis
                elif element_name == "mde_analysis_pairwise_overlap" and element_type == "statistical":
                    pairwise_overlap_helper(out_path, de_IDs)
                elif element_name == "mde_differential_expression_signature" and element_type == "statistical":
                    mde_dict = differential_expression_signature_helper(
                        global_variables, out_path, de_IDs, mde_dict)

                # methods for the plots
                elif element_name == "mde_start_plots" and element_type == "plot_core":
                    pr_dictionary = start_plots(global_variables, out_path,
                                                "Mde", mde_dict)
                elif element_type == "plot":
                    add_plot(element_path, pr_dictionary)
                elif element_name == "mde_end_plots" and element_type == "plot_core":
                    end_plots(pr_dictionary)
                elif element_name == "mde_run_r" and element_type == "plot_core":
                    run_r(pr_dictionary)

                # methods for the report
                elif element_name == "mde_start_report" and element_type == "report_core":
                    start_report(global_variables, pr_dictionary, element_path)
                elif element_type == "report_title":
                    add_header_section_to_report(element_path, pr_dictionary)
                elif element_type == "report_text":
                    add_text_section_to_report(element_path, pr_dictionary,
                                               global_variables)
                elif element_type == "report_plot":
                    add_plot_section_to_report(element_path, pr_dictionary,
                                               global_variables)
                elif element_name == "mde_end_report" and element_type == "report_core":
                    end_report(pr_dictionary)

                print "done with: " + element_name.replace("_", " ")

        print
def run_pde_workflow(global_variables, biotype):

    print "-" * len(list(biotype))
    print biotype
    print "-" * len(list(biotype))
    print

    # gets the config for the workflow
    config = global_variables["config"]["PDE"]

    # iterates through the PDEs
    parsed_pde_parameters = global_variables["pde_parameters"]
    for pde_parameter_dict in parsed_pde_parameters:
        pde_ID = pde_parameter_dict["pde_ID"]
        print pde_ID
        pde_ID_no_spaces = pde_ID.replace(" ", "_")

        # gets the outpath for the workflow - as we use this a lot
        out_path = os.path.join(global_variables["out_path"], biotype,
                                "pde_workflows", pde_ID_no_spaces)

        # iterates through the elements in the config
        for element in config:

            element_name, element_active, element_type, element_subtype, element_path = element

            # checks prerequisites have been met:
            if check_element_prerequisites(element_active, element_type,
                                           element_subtype, element_path,
                                           global_variables):

                # methods for the core workflow
                if element_name == "pde_sub_directories_core" and element_type == "core":
                    core_sub_directories(global_variables, out_path)

                elif element_name == "pde_file_gene_IDs" and element_type == "core":
                    gene_IDs(global_variables, out_path, biotype, pde_ID)
                elif element_name == "pde_file_gene_IDs_upregulated" and element_type == "core":
                    gene_IDs_upregulated(global_variables, out_path, biotype,
                                         pde_ID)
                elif element_name == "pde_file_gene_IDs_downregulated" and element_type == "core":
                    gene_IDs_downregulated(global_variables, out_path, biotype,
                                           pde_ID)
                elif element_name == "pde_file_gene_IDs_significant" and element_type == "core":
                    gene_IDs_significant(global_variables, out_path, biotype,
                                         pde_ID)
                elif element_name == "pde_file_gene_IDs_significant_upregulated" and element_type == "core":
                    gene_IDs_significant_upregulated(global_variables,
                                                     out_path, biotype, pde_ID)
                elif element_name == "pde_file_gene_IDs_significant_downregulated" and element_type == "core":
                    gene_IDs_significant_downregulated(global_variables,
                                                       out_path, biotype,
                                                       pde_ID)

                elif element_name == "pde_file_gene_symbols" and element_type == "core":
                    gene_symbols(global_variables, out_path, biotype, pde_ID)
                elif element_name == "pde_file_gene_symbols_upregulated" and element_type == "core":
                    gene_symbols_upregulated(global_variables, out_path,
                                             biotype, pde_ID)
                elif element_name == "pde_file_gene_symbols_downregulated" and element_type == "core":
                    gene_symbols_downregulated(global_variables, out_path,
                                               biotype, pde_ID)
                elif element_name == "pde_file_gene_symbols_significant" and element_type == "core":
                    gene_symbols_significant(global_variables, out_path,
                                             biotype, pde_ID)
                elif element_name == "pde_file_gene_symbols_significant_upregulated" and element_type == "core":
                    gene_symbols_significant_upregulated(
                        global_variables, out_path, biotype, pde_ID)
                elif element_name == "pde_file_gene_symbols_significant_downregulated" and element_type == "core":
                    gene_symbols_significant_downregulated(
                        global_variables, out_path, biotype, pde_ID)

                elif element_name == "pde_file_annotated" and element_type == "core":
                    PDE_annotated(global_variables, out_path, biotype, pde_ID)
                elif element_name == "pde_file_annotated_upregulated" and element_type == "core":
                    PDE_annotated_upregulated(global_variables, out_path,
                                              biotype, pde_ID)
                elif element_name == "pde_file_annotated_downregulated" and element_type == "core":
                    PDE_annotated_downregulated(global_variables, out_path,
                                                biotype, pde_ID)
                elif element_name == "pde_file_annotated_significant" and element_type == "core":
                    PDE_annotated_significant(global_variables, out_path,
                                              biotype, pde_ID)
                elif element_name == "pde_file_annotated_significant_upregulated" and element_type == "core":
                    PDE_annotated_significant_upregulated(
                        global_variables, out_path, biotype, pde_ID)
                elif element_name == "pde_file_annotated_significant_downregulated" and element_type == "core":
                    PDE_annotated_significant_downregulated(
                        global_variables, out_path, biotype, pde_ID)

                # methods for statistical analysis
                elif element_name == "pde_analysis_spatial" and element_type == "statistical":
                    spatial_enrichment_helper(global_variables, out_path,
                                              pde_parameter_dict)
                elif element_name == "pde_analysis_hypergeometric_gene_sets" and element_type == "statistical":
                    hypergeometric_gene_set_helper(out_path, global_variables)
                elif element_name == "pde_analysis_ipa_upstream_regulators" and element_type == "statistical":
                    ipa_ureg_helper(out_path, global_variables)

                # methods for the plots
                elif element_name == "pde_start_plots" and element_type == "plot_core":
                    pr_dictionary = start_plots(global_variables, out_path,
                                                "PDE", pde_parameter_dict)
                elif element_type == "plot":
                    add_plot(element_path, pr_dictionary)
                elif element_name == "pde_end_plots" and element_type == "plot_core":
                    end_plots(pr_dictionary)
                elif element_name == "pde_run_r" and element_type == "plot_core":
                    run_r(pr_dictionary)

                # methods for the report
                elif element_name == "pde_start_report" and element_type == "report_core":
                    start_report(global_variables, pr_dictionary, element_path)
                elif element_type == "report_title":
                    add_header_section_to_report(element_path, pr_dictionary)
                elif element_type == "report_text":
                    add_text_section_to_report(element_path, pr_dictionary,
                                               global_variables)
                elif element_type == "report_plot":
                    add_plot_section_to_report(element_path, pr_dictionary,
                                               global_variables)
                elif element_name == "pde_end_report" and element_type == "report_core":
                    end_report(pr_dictionary)

                print "done with: " + element_name.replace("_", " ")

        print