当前位置: 首页>>代码示例>>Python>>正文


Python RNA.doubleP_getitem方法代码示例

本文整理汇总了Python中RNA.doubleP_getitem方法的典型用法代码示例。如果您正苦于以下问题:Python RNA.doubleP_getitem方法的具体用法?Python RNA.doubleP_getitem怎么用?Python RNA.doubleP_getitem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RNA的用法示例。


在下文中一共展示了RNA.doubleP_getitem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import RNA [as 别名]
# 或者: from RNA import doubleP_getitem [as 别名]
def main():
    usage = """
    python scripts/dotplus.py sequence

    Create a file for displaying as a dotplot using the provided sequence.

    If the provided sequence is '-', then read the sequence from stdin.
    """
    num_args= 1
    parser = OptionParser(usage=usage)

    parser.add_option('-p', '--probability', dest='probability', default=0.01, help="The probability cutoff for displaying base pair points", type='float')
    #parser.add_option('-u', '--useless', dest='uselesss', default=False, action='store_true', help='Another useless option')

    (options, args) = parser.parse_args()

    if len(args) < num_args:
        parser.print_help()
        sys.exit(1)

    if args[0] == '-':
        seq = sys.stdin.read()
    else:
        seq = args[0].strip()

    # pf_fold returns the MFE as well as the partition function energy
    mfe, pfe = RNA.pf_fold(seq)
    prob_matrix = RNA.export_bppm()

    bp_to_seq = {}

    # get all of the suboptimal structures
    subopts = RNA.zukersubopt(seq)
    for i in range(0, subopts.size()):
        s = subopts.get(i)
        pt = fus.dotbracket_to_pairtable(s.structure)

        # go through each base pair and store the sequence
        # it came from so that it can be output later
        for j in range(1, pt[0]+1):
            bp = tuple(sorted([j, pt[j]]))

            if bp in bp_to_seq:
                continue

            bp_to_seq[bp] = (s.structure, s.energy)

        #print s.structure, s.energy

    bps = []
    structs = []

    counter = 0
    struct_dict = {}
    base_probs = col.defaultdict(float)

    print >>sys.stderr, "probability:", options.probability
    for i,j in it.combinations(range(1, len(seq)+1), 2):
        prob = RNA.doubleP_getitem(prob_matrix, 
                                   RNA.intP_getitem(RNA.cvar.iindx, i) - j)

        base_probs[i] += prob
        base_probs[j] += prob

        if prob > options.probability:
            struct, energy = bp_to_seq[(i,j)]
            pp = math.exp((pfe - (energy / 100.)) / .616310776)

            if struct not in struct_dict:
                struct_dict[struct] = (struct, pp, counter)
                index = counter
                counter += 1
            else:
                index = struct_dict[struct][2]

            print >>sys.stderr, "ix:", index, "struct:", struct, "pp:", pp
            bps += [{"i": i, "j": j, "p": "{:.3f}".format(math.sqrt(prob)), "ix": index}]


    structs = struct_dict.values()
    structs.sort(key=lambda x: -x[1])
    base_probs = dict([(i, "{:.3f}".format(j)) for (i,j) in base_probs.items()])

    structs = [{"struct": st[0], "sprob": st[1], "ix": st[2]} for st in structs]
    print json.dumps({"seq": seq, "structs": structs, "bps": bps, "baseProbs": base_probs.items()}, indent=2)
开发者ID:pkerpedjiev,项目名称:dotstruct,代码行数:87,代码来源:dotplus.py


注:本文中的RNA.doubleP_getitem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。