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


Python Interval.toBedstring方法代码示例

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


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

示例1: main

# 需要导入模块: from Interval import Interval [as 别名]
# 或者: from Interval.Interval import toBedstring [as 别名]

#.........这里部分代码省略.........
    #pick haplotype to pass
    flip=np.random.uniform(0,1)
    if flip <= .5: 
        haplotype="maternal"
    else:
        haplotype="paternal"
    intervalstring=''
    #now get the crossover points and record them in Interval format http://107.20.183.198/documentation.php#interval-format
    #if zero crossovers, then just past the entire chromosome
    if ncrossovers ==0:
        intervalstring="\t".join([haplotype, chrom, "+",'0', str(options.chromSize), str(ncrossovers),',',','])
        crossoverfh.write(chrom + " " + haplotype + " " + str(ncrossovers) + " " + str(options.chromSize) + "\n")
    #otherise randomly throw down crossover points according to uniform random
    else:
        chromsize=options.chromSize
        points=np.random.random_integers(1, chromsize, ncrossovers)
        points.sort()
        pointstrings=[]
        for p in points: pointstrings.append(str(p))
        outstring="\t".join(pointstrings)
        crossoverfh.write(chrom + " " + haplotype + " " + str(ncrossovers) + " " + ",".join(pointstrings) + "\n")
        if len(points) %2 == 0:
            #sys.stderr.write(haplotype + " " + chrom + " " + outstring +"\n")
            starts=list(points[1::2])
            ends=list(points[::2])
            ends.append(int(chromsize))
            starts.insert(0,0)
            startstrings=",".join(map(lambda x: str(x), starts))
            endstrings=",".join(map(lambda x: str(x), ends))
            intervalstring="\t".join([haplotype, chrom, "+",str(starts[0]), str(ends[-1]),str(ncrossovers), startstrings, endstrings])
               
        else:
            #sys.stderr.write(haplotype + " " + chrom + " " + outstring +"\n")
            starts=list(points[1::2])
            ends=list(points[0::2])
            starts.insert(0,0)
            startstrings=",".join(map(lambda x: str(x), starts))
            endstrings=",".join(map(lambda x: str(x), ends))
            #print starts
            #print ends
            intervalstring="\t".join([haplotype, chrom, "+",str(starts[0]), str(ends[-1]),str(ncrossovers), startstrings, endstrings])
            #print intervalstring
    print intervalstring
    intervalobj=Interval(intervalstring)
    if haplotype=='maternal':
        inbtwn_name='paternal'
    else:
        inbtwn_name='maternal'
    print intervalstring
        
    

    #extract DNA sequence from the maternal/paternal 2bit files according to the crossover intervals
    for (bedstring) in intervalobj.toBedstring():
        crossoverfh.write(bedstring+"\n")
        if haplotype=='maternal':
            (chr, start, end, name)=bedstring.split('\t')
            chr=maternalname
            bedstring="\t".join([ chr, start,end,name])
            print bedstring
            gametesequence += twoBitExtract(bedstring, twobit_maternal)
        else:
            (chr, start, end, name)=bedstring.split('\t')
            
            chr=paternalname
            bedstring="\t".join([ chr, start,end,name])
            print bedstring
            gametesequence += twoBitExtract(bedstring, twobit_paternal)
    #print "=="
    for bedstring in intervalobj.yieldInBtwnBedstring(inbtwn_name):
        crossoverfh.write(bedstring+"\n")
        if inbtwn_name=='maternal':
            (chr, start, end, name)=bedstring.split('\t')
            chr=maternalname
            bedstring="\t".join([ chr, start,end,name])
            gametesequence += twoBitExtract(bedstring, twobit_maternal)
        else:
            (chr, start, end, name)=bedstring.split('\t')
            chr=paternalname
            bedstring="\t".join([ chr, start,end,name])
            gametesequence += twoBitExtract(bedstring, twobit_paternal)
    if intervalobj.getLastSubIntervalEnd() != -1 and intervalobj.getLastSubIntervalEnd() < chromsize:
        #print inbtwn_name, chrom,  intervalobj.getLastSubIntervalEnd(), chromsize
        bedstring="\t".join(map( lambda(x): str(x), [ chrom, intervalobj.getLastSubIntervalEnd(), chromsize, inbtwn_name ] ) )
        crossoverfh.write(bedstring+"\n")
        if inbtwn_name=='maternal':
            (chr, start, end, name)=bedstring.split('\t')
            chr=maternalname
            bedstring="\t".join([ chr, start,end,name])
            gametesequence += twoBitExtract(bedstring, twobit_maternal)
        else:
            (chr, start, end, name)=bedstring.split('\t')
            chr=paternalname
            bedstring="\t".join([ chr, start,end,name])
            gametesequence += twoBitExtract(bedstring, twobit_paternal)
    #finally write out teh fasta file
    sys.stderr.write("writing gametic fasta file ... " + chrom + "\n")
    gametefastaname="_".join([chrom,"gamete", "meiosis"+str(options.nmeiosis), options.samplename])
    #writefasta("".join(gametesequence), chrom + "." + options.samplename, gametefastaname+".fa")
    writefasta("".join(gametesequence),options.samplename, options.samplename+".fa")
开发者ID:indapa,项目名称:MySimulations,代码行数:104,代码来源:simulate-crossovers.py


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