Exemple #1
0
def compare_replicates(term_covers, template_texs, cond, args_term):
    '''check the cutoff of replicate match'''
    detect_num = 0
    term_datas = []
    diff_cover = -1
    diff = []
    detect = False
    detect_num = check_tex(template_texs, term_covers, term_datas, None,
                           "terminator", None, None, None, None, 0,
                           args_term.tex_notex)

    if ("texnotex" in cond):
        tex_rep = get_repmatch(args_term.replicates["tex"], cond)
        if detect_num >= tex_rep:
            detect = True
    elif ("frag" in cond):
        frag_rep = get_repmatch(args_term.replicates["frag"], cond)
        if detect_num >= frag_rep:
            detect = True
    if detect:
        detect = False
        for term in term_datas:
            if (len(diff) == 0) or (diff_cover < term["diff"]):
                diff_cover = term["diff"]
                diff = term
    return diff_cover, diff, term_datas, detect_num
Exemple #2
0
def elongation(lib_conds, template_texs, libs, strand, trans,
               args_tran, strain, tolers):
    '''check coverage and replicate match to form transcript'''
    first = True
    pre_pos = -1
    check_tex = []
    tracks = []
    conds = {}
    pre_wig = None
    detect = False
    texs = template_texs.copy()
    tmp_covers = {"best": 0, "toler": -1}
    for cond, lib_tracks in lib_conds.items():
        for lib_name, covers in lib_tracks.items():
            index_pos = 0
            for cover in covers:
                for cond, lib_tracks in lib_conds.items():
                    for lib_track in lib_tracks.keys():
                        real_track = lib_track.split("|")[-3]
                        if index_pos < len(lib_tracks[lib_track]):
                            compare_cover = lib_tracks[lib_track][index_pos]
                        else:
                            compare_cover = 0
                        detect_hight_toler(
                                compare_cover, args_tran.height,
                                tmp_covers, tracks, real_track)
                for track in tracks:
                    if len(texs) != 0:
                        for key, num in texs.items():
                            if track in key:
                                texs[key] += 1
                check_tex_conds(tracks, libs, texs, check_tex,
                                conds, args_tran.tex)
                for cond, detect_num in conds.items():
                    if ("tex" in cond):
                        tex_rep = get_repmatch(args_tran.replicates["tex"], cond)
                        if detect_num >= tex_rep:
                            detect = True
                    elif ("frag" in cond):
                        frag_rep = get_repmatch(args_tran.replicates["frag"], cond)
                        if detect_num >= frag_rep:
                            detect = True
                if detect:
                    detect = False
                    trans[strain].append(tmp_covers["best"])
                else:
                    trans[strain].append(-1)
                if (tmp_covers["toler"] != -1):
                    tolers.append(tmp_covers["toler"])
                else:
                    tolers.append(args_tran.height + 10)
                tmp_covers = {"best": 0, "toler": -1}
                tracks = []
                conds = {}
                check_tex = []
                texs = template_texs.copy()
                index_pos += 1
            break
        break
Exemple #3
0
def get_coverage(term, wigs, strand, template_texs, args_term):
    '''get proper coverage to check the coverage decrease'''
    hl_poss = {"high": 0, "low": 0}
    hl_covers = {"high": 0, "low": 0}
    term_datas = {}
    detect_nums = {}
    diff_cover = -1
    diff = []
    for wig_strain, conds in wigs.items():
        if wig_strain == term["strain"]:
            for cond, tracks in conds.items():
                term_covers = []
                term_datas[cond] = []
                detect_nums[cond] = 0
                for lib_name, covers in tracks.items():
                    track = lib_name.split("|")[-3]
                    lib_strand = lib_name.split("|")[-2]
                    lib_type = lib_name.split("|")[-1]
                    c_start, c_end = check_start_and_end(
                        term, args_term, covers)
                    covers = covers[c_start:c_end]
                    if strand == "-":
                        covers = covers[::-1]
                    coverage2term(covers, term, hl_covers, hl_poss, strand,
                                  term_covers, track, args_term, c_start,
                                  c_end, lib_type)
                if len(term_covers) != 0:
                    tmp_cov, tmp_diff, term_datas[cond], detect_nums[cond] = (
                        compare_replicates(term_covers, template_texs, cond,
                                           args_term))
                    if (diff_cover == -1) or (diff_cover < tmp_cov):
                        diff_cover = tmp_cov
                        diff = tmp_diff
    detect = False
    for cond, num in detect_nums.items():
        if ("texnotex" in cond):
            tex_rep = get_repmatch(args_term.replicates["tex"], cond)
            if num >= tex_rep:
                detect = True
        elif ("frag" in cond):
            frag_rep = get_repmatch(args_term.replicates["frag"], cond)
            if num >= frag_rep:
                detect = True
        if detect:
            detect = False
            if strand == "+":
                term["detect_p"] = True
            else:
                term["detect_m"] = True
    return diff_cover, diff, term_datas, detect_nums