Example #1
0
def format_our_single(db_cursor, output):

    header = ["our_name",
              "ecocyc_id",
              "type",
              "our_start",
              "our_end",
              "result",
              "their_name",
              "their_start",
              "their_end",
              "their_strand",
              "distance",
              "interactions",
              "odds_ratio"]

    fl = open(output, "wb")

    fl.write("%s\n" % "\t".join(header))

    # keep going over the results until done
    row = db_cursor.fetchone()

    if row is not None:
        print row.keys()

    names_to_data = {}

    while row is not None:

        values_list = []

        if row["match_first"]:
            values = [row["rna1_name"],
                      row["rna1_ecocyc_id"],
                      row["first_type"],
                      row["our.start_1"],
                      row["our.end_1"],
                      "true",
                      row["name"],
                      row["start_1"],
                      row["end_1"],
                      row["strand_1"],
                      row["distance_1"],
                      row["interactions"],
                      row["odds_ratio"]]
            values_list.append(values)

        if row["match_second"]:
            values = [row["rna2_name"],
                      row["rna2_ecocyc_id"],
                      row["second_type"],
                      row["start_2"],
                      row["end_2"],
                      "true",
                      row["name"],
                      row["start_1"],
                      row["end_1"],
                      row["strand_2"],
                      row["distance_2"],
                      row["interactions"],
                      row["odds_ratio"]]
            values_list.append(values)

        if not row["match_first"] and not row["match_second"]:
            if row["closest_1"] < row["closest_2"]:
                values = [row["rna1_name"],
                          row["rna1_ecocyc_id"],
                          row["first_type"],
                          row["our.start_1"],
                          row["our.end_1"],
                          "false",
                          row["name"],
                          row["start_1"],
                          row["end_1"],
                          row["strand_1"],
                          row["closest_1"],
                          row["interactions"],
                          row["odds_ratio"]]
            else:
                values = [row["rna2_name"],
                          row["rna2_ecocyc_id"],
                          row["second_type"],
                          row["start_2"],
                          row["end_2"],
                          "false",
                          row["name"],
                          row["start_1"],
                          row["end_1"],
                          row["strand_2"],
                          row["closest_2"],
                          row["interactions"],
                          row["odds_ratio"]]

            values_list.append(values)

        for curr_values in values_list:
            TableFormatter._add_names_to_data(names_to_data, curr_values)
            fl.write("%s\n" % "\t".join(str(val) for val in curr_values))
        # print values

        row = db_cursor.fetchone()

    fl.close()

    TableFormatter._sort_names_to_data(names_to_data)

    fl = open("%s.sorted" % output, "wb")

    fl.write("%s\n" % "\t".join(header))

    for curr in TableFormatter._sort_names_to_data(names_to_data):
        fl.write("%s\n" % "\t".join(str(val) for val in curr))

    fl.close()
Example #2
0
def format_our_single(db_cursor, output):

    header = [
        "our_name", "ecocyc_id", "type", "our_start", "our_end", "result",
        "their_name", "their_start", "their_end", "their_strand", "distance",
        "interactions", "odds_ratio"
    ]

    fl = open(output, "wb")

    fl.write("%s\n" % "\t".join(header))

    # keep going over the results until done
    row = db_cursor.fetchone()

    if row is not None:
        print row.keys()

    names_to_data = {}

    while row is not None:

        values_list = []

        if row["match_first"]:
            values = [
                row["rna1_name"], row["rna1_ecocyc_id"], row["first_type"],
                row["our.start_1"], row["our.end_1"], "true", row["name"],
                row["start_1"], row["end_1"], row["strand_1"],
                row["distance_1"], row["interactions"], row["odds_ratio"]
            ]
            values_list.append(values)

        if row["match_second"]:
            values = [
                row["rna2_name"], row["rna2_ecocyc_id"], row["second_type"],
                row["start_2"], row["end_2"], "true", row["name"],
                row["start_1"], row["end_1"], row["strand_2"],
                row["distance_2"], row["interactions"], row["odds_ratio"]
            ]
            values_list.append(values)

        if not row["match_first"] and not row["match_second"]:
            if row["closest_1"] < row["closest_2"]:
                values = [
                    row["rna1_name"], row["rna1_ecocyc_id"], row["first_type"],
                    row["our.start_1"], row["our.end_1"], "false", row["name"],
                    row["start_1"], row["end_1"], row["strand_1"],
                    row["closest_1"], row["interactions"], row["odds_ratio"]
                ]
            else:
                values = [
                    row["rna2_name"], row["rna2_ecocyc_id"],
                    row["second_type"], row["start_2"], row["end_2"], "false",
                    row["name"], row["start_1"], row["end_1"], row["strand_2"],
                    row["closest_2"], row["interactions"], row["odds_ratio"]
                ]

            values_list.append(values)

        for curr_values in values_list:
            TableFormatter._add_names_to_data(names_to_data, curr_values)
            fl.write("%s\n" % "\t".join(str(val) for val in curr_values))
        # print values

        row = db_cursor.fetchone()

    fl.close()

    TableFormatter._sort_names_to_data(names_to_data)

    fl = open("%s.sorted" % output, "wb")

    fl.write("%s\n" % "\t".join(header))

    for curr in TableFormatter._sort_names_to_data(names_to_data):
        fl.write("%s\n" % "\t".join(str(val) for val in curr))

    fl.close()