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

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

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

行番号 
1#!/usr/bin/python2.6
2
3"""
4Merge any overlapping regions of bed files. Bed files can be provided on the
5command line or on stdin. Merged regions are always reported on the '+'
6strand, and any fields beyond chrom/start/stop are lost.
7
8usage: %prog bed files ...
9"""
10
11import psyco_full
12import sys
13
14from bx.bitset import *
15from bx.bitset_builders import *
16from itertools import *
17
18bed_filenames = sys.argv[1:]
19if bed_filenames:
20    input = chain( * imap( open, bed_filenames ) )
21else:
22    input = sys.stdin
23
24bitsets = binned_bitsets_from_bed_file( input )
25
26for chrom in bitsets:
27    bits = bitsets[chrom]
28    end = 0
29    while 1:
30        start = bits.next_set( end )
31        if start == bits.size: break
32        end = bits.next_clear( start )
33        print "%s\t%d\t%d" % ( chrom, start, end )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。