def test_coverage_comparison_first(self):
     first = True
     cover_sets = {"high": -1, "low": -1}
     poss = {"high": -1, "low": -1}
     cover = {"coverage": 100, "pos": 50}
     cover_detect.coverage_comparison(cover, cover_sets, poss, first, "+")
     self.assertDictEqual(cover_sets, {"high": 100, "low": 100})
     self.assertDictEqual(poss, {"high": 50, "low": 50})
示例#2
0
 def test_coverage_comparison_first(self):
     first = True
     cover_sets = {"high": -1, "low": -1}
     poss = {"high": -1, "low": -1}
     cover = 100
     cover_detect.coverage_comparison(cover, cover_sets, poss, first, "+", 50)
     self.assertDictEqual(cover_sets, {"high": 100, "low": 100})
     self.assertDictEqual(poss, {"high": 50, "low": 50})
示例#3
0
 def test_coverage_comparison_forward(self):
     first = False
     cover_sets = {"high": 50, "low": 20}
     poss = {"high": 10, "low": 30}
     cover = 100
     cover_detect.coverage_comparison(cover, cover_sets, poss, first, "+", 50)
     self.assertDictEqual(cover_sets, {"high": 100, "low": 100})
     self.assertDictEqual(poss, {"high": 50, "low": 50})
     cover = 30
     cover_detect.coverage_comparison(cover, cover_sets, poss, first, "+", 51)
     self.assertDictEqual(cover_sets, {"high": 100, "low": 30})
     self.assertDictEqual(poss, {"high": 50, "low": 51})
示例#4
0
 def test_coverage_comparison_reverse(self):
     first = False
     cover_sets = {"high": 50, "low": 20}
     poss = {"high": 30, "low": 10}
     cover = 100
     cover_detect.coverage_comparison(cover, cover_sets, poss, first, "-", 50)
     self.assertDictEqual(cover_sets, {"high": 100, "low": 100})
     self.assertDictEqual(poss, {"high": 50, "low": 50})
     cover = 30
     cover_detect.coverage_comparison(cover, cover_sets, poss, first, "-", 49)
     self.assertDictEqual(cover_sets, {"high": 100, "low": 30})
     self.assertDictEqual(poss, {"high": 50, "low": 49})
 def test_coverage_comparison_reverse(self):
     first = False
     cover_sets = {"high": 50, "low": 20}
     poss = {"high": 30, "low": 10}
     cover = {"coverage": 100, "pos": 50}
     cover_detect.coverage_comparison(cover, cover_sets, poss, first, "-")
     self.assertDictEqual(cover_sets, {"high": 100, "low": 100})
     self.assertDictEqual(poss, {"high": 50, "low": 50})
     cover = {"coverage": 30, "pos": 49}
     cover_detect.coverage_comparison(cover, cover_sets, poss, first, "-")
     self.assertDictEqual(cover_sets, {"high": 100, "low": 30})
     self.assertDictEqual(poss, {"high": 50, "low": 49})
 def test_coverage_comparison_forward(self):
     first = False
     cover_sets = {"high": 50, "low": 20}
     poss = {"high": 10, "low": 30}
     cover = 100
     cover_detect.coverage_comparison(
         cover, cover_sets, poss, first, "+", 50)
     self.assertDictEqual(cover_sets, {"high": 100, "low": 100})
     self.assertDictEqual(poss, {"high": 50, "low": 50})
     cover = 30
     cover_detect.coverage_comparison(
         cover, cover_sets, poss, first, "+", 51)
     self.assertDictEqual(cover_sets, {"high": 100, "low": 30})
     self.assertDictEqual(poss, {"high": 50, "low": 51})
示例#7
0
def coverage2term(covers, term, hl_covers, hl_poss, strand, term_covers, track,
                  args_term):
    first = True
    for cover in covers:
        if (term["start"] <= cover["pos"] + args_term.fuzzy) and (
                term["end"] >= cover["pos"] - args_term.fuzzy):
            first = coverage_comparison(cover, hl_covers, hl_poss, first,
                                        strand)
        else:
            if (strand
                    == "+") and (cover["pos"] > term["end"] + args_term.fuzzy):
                break
            elif (strand
                  == "-") and (cover["pos"] < term["start"] - args_term.fuzzy):
                break
        if (first is not True) and (hl_covers["high"] > 0):
            if ((hl_covers["low"] / hl_covers["high"]) <
                    args_term.decrease) and (hl_covers["low"] > -1):
                term_covers.append({
                    "track":
                    track,
                    "high":
                    hl_covers["high"],
                    "low":
                    hl_covers["low"],
                    "detect":
                    "True",
                    "diff": (hl_covers["high"] - hl_covers["low"]),
                    "type":
                    cover["type"]
                })
                break
def coverage2term(covers, term, hl_covers, hl_poss, strand,
                  term_covers, track, args_term):
    first = True
    for cover in covers:
        if (term["start"] <= cover["pos"] + args_term.fuzzy) and (
                term["end"] >= cover["pos"] - args_term.fuzzy):
            first = coverage_comparison(cover, hl_covers, hl_poss,
                                        first, strand)
        else:
            if (strand == "+") and (
                    cover["pos"] > term["end"] + args_term.fuzzy):
                break
            elif (strand == "-") and (
                    cover["pos"] < term["start"] - args_term.fuzzy):
                break
        if (first is not True) and (hl_covers["high"] > 0):
            if ((hl_covers["low"] / hl_covers["high"]) <
                    args_term.decrease) and (
                    hl_covers["low"] > -1):
                term_covers.append({
                    "track": track, "high": hl_covers["high"],
                    "low": hl_covers["low"], "detect": "True",
                    "diff": (hl_covers["high"] - hl_covers["low"]),
                    "type": cover["type"]})
                break
def coverage2term(covers, term, hl_covers, hl_poss, strand, term_covers,
                  track, args_term, start_plus, end_minus, lib_type):
    '''It is for get the highest and lowest coverage'''
    first = True
    pos = 0
    for cover in covers:
        if strand == "+":
            cover_pos = start_plus + pos
        else:
            cover_pos = end_minus - pos
        if (term["start"] <= cover_pos + args_term.fuzzy) and (
                term["end"] >= cover_pos - args_term.fuzzy):
            first = coverage_comparison(cover, hl_covers, hl_poss,
                                        first, strand, cover_pos)
        else:
            if (strand == "+") and (
                    cover_pos > term["end"] + args_term.fuzzy):
                break
            elif (strand == "-") and (
                    cover_pos < term["start"] - args_term.fuzzy):
                break
        if (first is not True) and (hl_covers["high"] > 0):
            if ((hl_covers["low"] / hl_covers["high"]) <
                    args_term.decrease) and (
                    hl_covers["low"] > -1):
                term_covers.append({
                    "track": track, "high": hl_covers["high"],
                    "low": hl_covers["low"], "detect": "True",
                    "diff": (hl_covers["high"] - hl_covers["low"]),
                    "type": lib_type})
                break
        pos += 1
示例#10
0
def get_coverage(wigs, srna):
    cover_sets = {"high": -1, "low": -1, "total": 0, "diff": 0}
    poss = {"high": 0, "low": 0, "pos": 0}
    srna_covers = {}
    for wig_strain, conds in wigs.items():
        if wig_strain == srna.seq_id:
            for cond, tracks in conds.items():
                srna_covers[cond] = []
                for lib_name, covers in tracks.items():
                    track = lib_name.split("|")[-3]
                    lib_strand = lib_name.split("|")[-2]
                    lib_type = lib_name.split("|")[-1]
                    cover_sets["total"] = 0
                    cover_sets["diff"] = 0
                    first = True
                    c_start, c_end = check_start_and_end(
                        srna.start, srna.end, covers)
                    covers = covers[c_start:c_end]
                    if srna.strand == "-":
                        covers = covers[::-1]
                    pos = 0
                    for cover in covers:
                        if (lib_strand == srna.strand):
                            if srna.strand == "+":
                                cover_pos = c_start + pos
                            else:
                                cover_pos = c_end - pos
                            if (srna.start <= cover_pos) and (srna.end >=
                                                              cover_pos):
                                cover_sets["total"] = (cover_sets["total"] +
                                                       cover)
                                first = coverage_comparison(
                                    cover, cover_sets, poss, first,
                                    srna.strand, cover_pos)
                            else:
                                if (srna.strand
                                        == "+") and (cover_pos > srna.end):
                                    cover_sets_pos = cover_pos
                                    break
                                elif (srna.strand
                                      == "-") and (cover_pos < srna.start):
                                    cover_sets["pos"] = cover_pos
                                    break
                        pos += 1
                    avg = cover_sets["total"] / float(srna.end - srna.start +
                                                      1)
                    srna_covers[cond].append({
                        "track": track,
                        "high": cover_sets["high"],
                        "low": cover_sets["low"],
                        "avg": avg,
                        "pos": poss["pos"],
                        "type": lib_type,
                        "final_start": srna.start,
                        "final_end": srna.end
                    })
    return srna_covers
示例#11
0
def check_coverage_pos(start, end, cover, cutoff_coverage, tmps, cover_sets,
                       checks, poss, strand, tolerance):
    go_out = False
    if (start <= cover["pos"]) and (
            end >= cover["pos"]):
        if cover["coverage"] > cutoff_coverage:
            tmps["pos"] = cover["pos"]
            tmps["toler"] = 0
            cover_sets["total"] = cover_sets["total"] + cover["coverage"]
            if tmps["total"] != 0:
                cover_sets["total"] = cover_sets["total"] + tmps["total"]
            tmps["total"] = 0
            tmps["toler"] = 0
            checks["first"] = coverage_comparison(
                              cover, cover_sets, poss,
                              checks["first"], strand)
        else:
            if tmps["toler"] <= tolerance:
                tmps["toler"] += 1
                tmps["total"] = cover_sets["total"] + cover["coverage"]
                checks["first"] = coverage_comparison(
                                  cover, cover_sets, poss,
                                  checks["first"], strand)
            else:
                if tmps["pos"] != 0:
                    poss["stop_point"] = tmps["pos"]
                    go_out = True
                tmps["total"] = 0
                tmps["toler"] = 0
    else:
        if (strand == "+") and (cover["pos"] > end):
            poss["stop_point"] = cover["pos"]
            tmps["total"] = 0
            tmps["toler"] = 0
            go_out = True
        elif (strand == "-") and (cover["pos"] < start):
            poss["stop_point"] = cover["pos"]
            tmps["total"] = 0
            tmps["toler"] = 0
            go_out = True
    return go_out, tmps
示例#12
0
def detect_cover_utr_srna(cover_results, pos, inter, cond, track, args_srna):
    datas = {
        "num": 0,
        "cover_tmp": {
            "5utr": 0,
            "total": 0,
            "ori_total": 0
        },
        "checks": {
            "first": True,
            "detect_decrease": False,
            "srna": False,
            "utr": False
        },
        "final_poss": {
            "start": pos["start"],
            "end": pos["end"]
        }
    }
    for cover in cover_results["covers"]:
        datas["checks"]["srna"] = False
        datas["checks"]["utr"] = False
        check_pos(cover, cover_results["check_point"], datas["checks"])
        if datas["checks"]["utr"]:
            datas["cover_tmp"]["ori_total"] = \
                datas["cover_tmp"]["ori_total"] + cover["coverage"]
        if datas["checks"]["srna"]:
            datas["cover_tmp"]["total"] = \
                datas["cover_tmp"]["total"] + cover["coverage"]
            datas["checks"]["first"] = coverage_comparison(
                cover, cover_results["cover_sets"], cover_results["pos"],
                datas["checks"]["first"], inter["strand"])
            if (datas["checks"]["first"]
                    is not True) and (cover_results["cover_sets"]["high"] > 0):
                if (cover_results["type"]
                        == "5utr") or (cover_results["type"] == "3utr") or (
                            (cover_results["type"] == "interCDS") and
                            (cover_results["intercds"] == "TSS")):
                    if ((cover_results["cover_sets"]["low"] /
                         cover_results["cover_sets"]["high"]) <
                            args_srna.decrease_utr) and (
                                cover_results["cover_sets"]["low"] > -1):
                        datas["checks"]["detect_decrease"] = True
                        datas["cover_tmp"]["5utr"] = cover["coverage"]
            if datas["checks"]["detect_decrease"]:
                go_out = get_cover_5utr(datas, cover_results["cover_sets"],
                                        cover, inter, args_srna)
                if go_out is True:
                    break
    if (datas["checks"]["first"]
            is not True) and (cover_results["cover_sets"]["high"] > 0):
        check_import_srna_covers(datas, cover_results, inter, cond, track,
                                 cover, pos, args_srna)
示例#13
0
def check_coverage_pos(start, end, cover, cutoff_coverage, cover_sets, checks,
                       poss, strand, cover_pos):
    go_out = False
    if (start <= cover_pos) and (end >= cover_pos):
        if cover > cutoff_coverage:
            cover_sets["total"] = cover_sets["total"] + cover
            checks["first"] = coverage_comparison(cover, cover_sets, poss,
                                                  checks["first"], strand,
                                                  cover_pos)
        else:
            cover_sets["total"] = cover_sets["total"] + cover
            checks["first"] = coverage_comparison(cover, cover_sets, poss,
                                                  checks["first"], strand,
                                                  cover_pos)
    else:
        if (strand == "+") and (cover_pos > end):
            poss["stop_point"] = cover_pos
            go_out = True
        elif (strand == "-") and (cover_pos < start):
            poss["stop_point"] = cover_pos
            go_out = True
    return go_out
示例#14
0
def check_coverage_pos(start, end, cover, cutoff_coverage, tmps, cover_sets,
                       checks, poss, strand, tolerance):
    go_out = False
    if (start <= cover["pos"]) and (end >= cover["pos"]):
        if cover["coverage"] > cutoff_coverage:
            tmps["pos"] = cover["pos"]
            tmps["toler"] = 0
            cover_sets["total"] = cover_sets["total"] + cover["coverage"]
            if tmps["total"] != 0:
                cover_sets["total"] = cover_sets["total"] + tmps["total"]
            tmps["total"] = 0
            tmps["toler"] = 0
            checks["first"] = coverage_comparison(cover, cover_sets, poss,
                                                  checks["first"], strand)
        else:
            if tmps["toler"] <= tolerance:
                tmps["toler"] += 1
                tmps["total"] = cover_sets["total"] + cover["coverage"]
                checks["first"] = coverage_comparison(cover, cover_sets, poss,
                                                      checks["first"], strand)
            else:
                if tmps["pos"] != 0:
                    poss["stop_point"] = tmps["pos"]
                    go_out = True
                tmps["total"] = 0
                tmps["toler"] = 0
    else:
        if (strand == "+") and (cover["pos"] > end):
            poss["stop_point"] = cover["pos"]
            tmps["total"] = 0
            tmps["toler"] = 0
            go_out = True
        elif (strand == "-") and (cover["pos"] < start):
            poss["stop_point"] = cover["pos"]
            tmps["total"] = 0
            tmps["toler"] = 0
            go_out = True
    return go_out, tmps
示例#15
0
def check_coverage_pos(start, end, cover, cutoff_coverage, cover_sets,
                       checks, poss, strand, cover_pos):
    go_out = False
    if (start <= cover_pos) and (
            end >= cover_pos):
        if cover > cutoff_coverage:
            cover_sets["total"] = cover_sets["total"] + cover
            checks["first"] = coverage_comparison(
                              cover, cover_sets, poss,
                              checks["first"], strand, cover_pos)
        else:
            cover_sets["total"] = cover_sets["total"] + cover
            checks["first"] = coverage_comparison(
                                cover, cover_sets, poss,
                                checks["first"], strand, cover_pos)
    else:
        if (strand == "+") and (cover_pos > end):
            poss["stop_point"] = cover_pos
            go_out = True
        elif (strand == "-") and (cover_pos < start):
            poss["stop_point"] = cover_pos
            go_out = True
    return go_out
示例#16
0
def detect_cover_utr_srna(cover_results, pos, inter, cond, track,
                          args_srna, lib_type, start, end, strand):
    datas = {"num": 0, "cover_tmp": {"5utr": 0, "total": 0, "ori_total": 0},
             "checks": {"first": True, "detect_decrease": False,
                        "srna": False, "utr": False},
             "final_poss": {"start": pos["start"], "end": pos["end"]}}
    index_pos = 0
    for cover in cover_results["covers"]:
        if strand == "+":
            cover_pos = start + index_pos
        else:
            cover_pos = end - index_pos
        datas["checks"]["srna"] = False
        datas["checks"]["utr"] = False
        check_pos(cover, cover_results["check_point"], datas["checks"],
                  cover_pos)
        if datas["checks"]["utr"]:
            datas["cover_tmp"]["ori_total"] = \
                datas["cover_tmp"]["ori_total"] + cover
        if datas["checks"]["srna"]:
            datas["cover_tmp"]["total"] = \
                datas["cover_tmp"]["total"] + cover
            datas["checks"]["first"] = coverage_comparison(
                    cover, cover_results["cover_sets"], cover_results["pos"],
                    datas["checks"]["first"], inter["strand"], cover_pos)
            if (datas["checks"]["first"] is not True) and (
                    cover_results["cover_sets"]["high"] > 0):
                if (cover_results["type"] == "5utr") or (
                        cover_results["type"] == "3utr") or (
                        (cover_results["type"] == "interCDS") and (
                         cover_results["intercds"] == "TSS")):
                    if ((cover_results["cover_sets"]["low"] /
                            cover_results["cover_sets"]["high"]) <
                            args_srna.decrease_utr) and (
                            cover_results["cover_sets"]["low"] > -1):
                        datas["checks"]["detect_decrease"] = True
                        datas["cover_tmp"]["5utr"] = cover
            if datas["checks"]["detect_decrease"]:
                go_out = get_cover_5utr(datas, cover_results["cover_sets"],
                                        cover, inter, args_srna, cover_pos)
                if go_out is True:
                    break
        index_pos += 1
    if (datas["checks"]["first"] is not True) and (
            cover_results["cover_sets"]["high"] > 0):
        check_import_srna_covers(datas, cover_results, inter, cond, track,
                                 cover, pos, args_srna, lib_type)
示例#17
0
def get_coverage(wigs, srna):
    cover_sets = {"high": -1, "low": -1, "total": 0, "diff": 0}
    poss = {"high": 0, "low": 0, "pos": 0}
    srna_covers = {}
    for wig_strain, conds in wigs.items():
        if wig_strain == srna.seq_id:
            for cond, tracks in conds.items():
                srna_covers[cond] = []
                for track, covers in tracks.items():
                    cover_sets["total"] = 0
                    cover_sets["diff"] = 0
                    first = True
                    if srna.strand == "+":
                        covers = covers[srna.start-2:srna.end+1]
                    elif srna.strand == "-":
                        covers = reversed(covers[srna.start-2:srna.end+1])
                    for cover in covers:
                        if (cover["strand"] == srna.strand):
                            if (srna.start <= cover["pos"]) and (
                                    srna.end >= cover["pos"]):
                                cover_sets["total"] = (cover_sets["total"] +
                                                       cover["coverage"])
                                first = coverage_comparison(
                                        cover, cover_sets, poss,
                                        first, srna.strand)
                            else:
                                if (srna.strand == "+") and (
                                        cover["pos"] > srna.end):
                                    cover_sets["pos"] = cover["pos"]
                                    break
                                elif (srna.strand == "-") and (
                                        cover["pos"] < srna.start):
                                    cover_sets["pos"] = cover["pos"]
                                    break
                    avg = cover_sets["total"] / float(
                            srna.end - srna.start + 1)
                    srna_covers[cond].append({"track": track,
                                              "high": cover_sets["high"],
                                              "low": cover_sets["low"],
                                              "avg": avg,
                                              "pos": poss["pos"],
                                              "type": cover["type"],
                                              "final_start": srna.start,
                                              "final_end": srna.end})
    return srna_covers
示例#18
0
def coverage2term(covers, term, hl_covers, hl_poss, strand, term_covers, track,
                  args_term, start_plus, end_minus, lib_type):
    '''It is for get the highest and lowest coverage'''
    first = True
    pos = 0
    for cover in covers:
        if strand == "+":
            cover_pos = start_plus + pos
        else:
            cover_pos = end_minus - pos
        if (term["start"] <= cover_pos + args_term.fuzzy) and (
                term["end"] >= cover_pos - args_term.fuzzy):
            first = coverage_comparison(cover, hl_covers, hl_poss, first,
                                        strand, cover_pos)
        else:
            if (strand == "+") and (cover_pos > term["end"] + args_term.fuzzy):
                break
            elif (strand
                  == "-") and (cover_pos < term["start"] - args_term.fuzzy):
                break
        if (first is not True) and (hl_covers["high"] > 0):
            if ((hl_covers["low"] / hl_covers["high"]) <
                    args_term.decrease) and (hl_covers["low"] > -1):
                term_covers.append({
                    "track":
                    track,
                    "high":
                    hl_covers["high"],
                    "low":
                    hl_covers["low"],
                    "detect":
                    "True",
                    "diff": (hl_covers["high"] - hl_covers["low"]),
                    "type":
                    lib_type
                })
                break
        pos += 1