本文整理汇总了Python中Interval.Interval.yieldInBtwnBedstring方法的典型用法代码示例。如果您正苦于以下问题:Python Interval.yieldInBtwnBedstring方法的具体用法?Python Interval.yieldInBtwnBedstring怎么用?Python Interval.yieldInBtwnBedstring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interval.Interval
的用法示例。
在下文中一共展示了Interval.yieldInBtwnBedstring方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Interval import Interval [as 别名]
# 或者: from Interval.Interval import yieldInBtwnBedstring [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")