def ne_matrix_symbols(global_variables, out_path, biotype):


    out_file = open(os.path.join(out_path, "data", "ne_matrix_symbols.csv"), "w")

    master_gene_table = global_variables["master_gene_table"]

    # gets the header
    header_list = ["symbol"]
    header_list += get_gene_ne_header(global_variables)
    out_file.write("\t".join(header_list) + "\n")

    # gets the gene expression
    for gene_ID in master_gene_table:
        gene_dictionary = master_gene_table[gene_ID]
        gene_symbol = gene_dictionary["SYMBOL"]

        # tests for a valid gene:
        valid_gene = False
        if gene_dictionary["ne_flag"]:
            if global_variables["GENE_BIOTYPE_FLAG"] and (gene_dictionary["BIOTYPE"] == biotype or biotype == "all_genes"):
                valid_gene = True
            if global_variables["GENE_BIOTYPE_FLAG"] == False:
                valid_gene = True

        if valid_gene:
            gene_out_list = [gene_symbol]
            gene_out_list += get_gene_ne(global_variables, gene_dictionary)
            out_file.write("\t".join(str(x) for x in gene_out_list) + "\n")
Example #2
0
def Mde_any_significant_annotated(global_variables, out_path, biotype, de_IDs):

    out_file = open(
        os.path.join(out_path, "data",
                     "genes_significant_in_any_des_annotated.csv"), "w")

    master_gene_table = global_variables["master_gene_table"]

    # gets the header
    header_list = ["ID"]
    header_list += get_gene_background_header(global_variables)
    header_list += get_gene_mde_header(de_IDs)
    header_list += get_gene_ne_header(global_variables)
    header_list += get_gene_ne_stats_header(global_variables)
    header_list += get_gene_annotations_header(global_variables)
    out_file.write("\t".join(header_list) + "\n")

    # gets the genes
    for gene_ID in master_gene_table:
        gene_dictionary = master_gene_table[gene_ID]

        # tests for a valid gene:
        valid_gene = False
        present_in_any_de = False

        if gene_dictionary["ne_flag"]:

            if (global_variables["GENE_BIOTYPE_FLAG"] and
                (gene_dictionary["BIOTYPE"] == biotype
                 or biotype == "all_genes")
                ) or global_variables["GENE_BIOTYPE_FLAG"] == False:
                valid_gene = True

                for de_ID in de_IDs:
                    if de_ID not in gene_dictionary:
                        valid_gene = False
                    else:
                        de_Dict = gene_dictionary[de_ID]
                        if not de_Dict["in_gl"]:
                            valid_gene = False
                        if de_Dict["sig"]:
                            present_in_any_de = True

        if valid_gene and present_in_any_de:
            gene_out_list = [gene_ID]
            gene_out_list += get_gene_background(global_variables,
                                                 gene_dictionary)
            gene_out_list += get_gene_mde(global_variables, gene_dictionary,
                                          de_IDs)
            gene_out_list += get_gene_ne(global_variables, gene_dictionary)
            gene_out_list += get_gene_ne_stats(global_variables,
                                               gene_dictionary)
            gene_out_list += get_gene_annotations(global_variables,
                                                  gene_dictionary)
            out_file.write("\t".join(str(x) for x in gene_out_list) + "\n")
def de_annotated_significant_downregulated(global_variables, out_path, biotype,
                                           de_ID):

    out_file = open(
        os.path.join(out_path, "data",
                     "de_annotated_significant_downregulated.csv"), "w")

    master_gene_table = global_variables["master_gene_table"]

    # gets the header
    header_list = ["ID"]
    header_list += get_gene_background_header(global_variables)
    header_list += get_gene_de_header(global_variables)
    header_list += get_gene_ne_header(global_variables)
    header_list += get_gene_ne_stats_header(global_variables)
    header_list += get_gene_annotations_header(global_variables)
    out_file.write("\t".join(header_list) + "\n")

    # gets the genes
    for gene_ID in master_gene_table:
        gene_dictionary = master_gene_table[gene_ID]

        # tests for a valid gene:
        valid_gene = False
        if gene_dictionary["ne_flag"] and de_ID in gene_dictionary:
            de_Dict = gene_dictionary[de_ID]
            if de_Dict["in_gl"] and de_Dict["sig"] and de_Dict["log2fold"] < 0:
                if global_variables["GENE_BIOTYPE_FLAG"] and (
                        gene_dictionary["BIOTYPE"] == biotype
                        or biotype == "all_genes"):
                    valid_gene = True
                if global_variables["GENE_BIOTYPE_FLAG"] == False:
                    valid_gene = True

        if valid_gene:
            gene_out_list = [gene_ID]
            gene_out_list += get_gene_background(global_variables,
                                                 gene_dictionary)
            gene_out_list += get_gene_de(global_variables, de_Dict)
            gene_out_list += get_gene_ne(global_variables, gene_dictionary)
            gene_out_list += get_gene_ne_stats(global_variables,
                                               gene_dictionary)
            gene_out_list += get_gene_annotations(global_variables,
                                                  gene_dictionary)
            out_file.write("\t".join(str(x) for x in gene_out_list) + "\n")