root/galaxy-central/eggs/bx_python-0.5.0_dev_f74aec067563-py2.6-macosx-10.6-universal-ucs2.egg/EGG-INFO/scripts/bed_intersect_basewise.py

リビジョン 3, 1.0 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1#!/usr/bin/python2.6
2
3"""
4Find regions of first bed file that overlap regions in a second bed file. This
5program performs a base-by-base intersection, so only runs of bases that are
6covered in both of the inputs will be output.
7
8usage: %prog bed_file_1 bed_file_2
9"""
10
11import sys
12from warnings import warn
13from bx.bitset import *
14from bx.bitset_builders import *
15from bx.cookbook import doc_optparse
16
17options, args = doc_optparse.parse( __doc__ )
18try:
19    in_fname, in2_fname = args
20except:
21    doc_optparse.exit()
22
23bits1 = binned_bitsets_from_file( open( in_fname ) )
24bits2 = binned_bitsets_from_file( open( in2_fname ) )
25
26bitsets = dict()
27
28for key in bits1:
29    if key in bits2:
30        bits1[key].iand( bits2[key] )
31        bitsets[key] = bits1[key]
32
33for chrom in bitsets:
34    bits = bitsets[chrom]
35    end = 0
36    while 1:
37        start = bits.next_set( end )
38        if start == bits.size: break
39        end = bits.next_clear( start )
40        print "%s\t%d\t%d" % ( chrom, start, end )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。