由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - python大牛请进有问题求教
相关主题
问两个算法题, 没什么头绪一个哈希表问题
简单的perl问题请问如何写bitset or bitmap
[合集] google interview questiong++找不到bitset
请问那里可以找到interval tree的 C code (linux)?问问Bitmap的问题
cookie的问题c++的bitset和C的按位操作哪个效率高?
python 问题,急,在线等。一个C/C++面试题
何用openpyxl 从excel 文档的某一行读起?C++ vector 到底能多大
这两种写法面試时候你喜欢哪种?如何得到位数可变的bitset
相关话题的讨论汇总
话题: intersect话题: bitsets话题: chrom话题: interval话题: intervals
进入Programming版参与讨论
1 (共1页)
f******8
发帖数: 93
1
工作中用的py程序,完全看不懂啊!!!真的给跪了!!!哪个牛人能给注释下,不用
详细大体说下这程序咋运行得就行。。。。。
"""
Compute the intersection of two sets of genomic intervals, either base-by-
base
or at the interval level. The returned GenomicIntervalReader will be in
the order of the first set of intervals passed in, with the corresponding
additional fields.
"""
import traceback
import fileinput
from warnings import warn
from bx.intervals.io import *
from bx.intervals.operations import *
def intersect(readers, mincols=1, upstream_pad=0, downstream_pad=0, pieces=
True, lens={}, comments=True):
# The incoming lens dictionary is a dictionary of chromosome lengths
which are used to initialize the bitsets.
# Read all but first into bitsets and intersect to one
primary = readers[0]
intersect = readers[1:]
# Handle any ValueError, IndexError and OverflowError exceptions that
may be thrown when
# the bitsets are being created by skipping the problem lines
intersect[0] = BitsetSafeReaderWrapper( intersect[0], lens=lens )
bitsets = intersect[0].binned_bitsets( upstream_pad=upstream_pad,
downstream_pad=downstream_pad, lens=lens )
intersect = intersect[1:]
for andset in intersect:
bitset2 = andset.binned_bitsets(upstream_pad = upstream_pad,
downstream_pad = downstream_pad, lens = lens)
for chrom in bitsets:
if chrom not in bitset2: continue
bitsets[chrom].iand(bitset2[chrom])
intersect = intersect[1:]

# Read remaining intervals and intersect
for interval in primary:
if isinstance(interval, Header):
yield interval
if isinstance(interval, Comment) and comments:
yield interval
elif isinstance(interval, GenomicInterval):
chrom = interval.chrom
start = int( interval.start )
end = int( interval.end )
if chrom not in bitsets:
continue
if start > end:
try:
# This will only work if primary is a NiceReaderWrapper
primary.skipped += 1
# no reason to stuff an entire bad file into memmory
if primary.skipped < 10:
primary.skipped_lines.append( ( primary.linenum,
primary.current_line, "Interval start after end!" ) )
except:
pass
continue
out_intervals = []
# Intersect or Overlap
try:
if bitsets[ chrom ].count_range( start, end-start ) >=
mincols:
if pieces:
out_intervals = bits_set_in_range( bitsets[chrom],
start, end )
else:
out_intervals = [ ( start, end ) ]
# Write the intervals
for start, end in out_intervals:
new_interval = interval.copy()
new_interval.start = start
new_interval.end = end
yield new_interval
except IndexError, e:
try:
# This will only work if primary is a NiceReaderWrapper
primary.skipped += 1
# no reason to stuff an entire bad file into memmory
if primary.skipped < 10:
primary.skipped_lines.append( ( primary.linenum,
primary.current_line, str( e ) ) )
except:
pass
continue
e*******o
发帖数: 4654
2
可以import 然后调用intersect 。
http://docs.python.org/2/tutorial/modules.html
你找个Python的入门书看。涉及具体实现找生信的同学帮你看吧。
要不去生物版问问?

【在 f******8 的大作中提到】
: 工作中用的py程序,完全看不懂啊!!!真的给跪了!!!哪个牛人能给注释下,不用
: 详细大体说下这程序咋运行得就行。。。。。
: """
: Compute the intersection of two sets of genomic intervals, either base-by-
: base
: or at the interval level. The returned GenomicIntervalReader will be in
: the order of the first set of intervals passed in, with the corresponding
: additional fields.
: """
: import traceback

1 (共1页)
进入Programming版参与讨论
相关主题
如何得到位数可变的bitsetcookie的问题
为啥 c++ bitset 的大小一定要在编译时给呢?python 问题,急,在线等。
未知大小的bitset能做参数吗?何用openpyxl 从excel 文档的某一行读起?
如何把'101111' 转化成二进制数101111这两种写法面試时候你喜欢哪种?
问两个算法题, 没什么头绪一个哈希表问题
简单的perl问题请问如何写bitset or bitmap
[合集] google interview questiong++找不到bitset
请问那里可以找到interval tree的 C code (linux)?问问Bitmap的问题
相关话题的讨论汇总
话题: intersect话题: bitsets话题: chrom话题: interval话题: intervals