root/galaxy-central/eggs/bx_python-0.5.0_dev_f74aec067563-py2.6-macosx-10.6-universal-ucs2.egg/EGG-INFO/scripts/bed_subtract_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 continuous regions that are covered by the first bed file (`bed_file_1`)
5but not by the second bed file (`bed_file_2`)
6
7usage: %prog bed_file_1 bed_file_2
8"""
9
10import sys
11from warnings import warn
12from bx.bitset_builders import binned_bitsets_from_file
13from bx.cookbook import doc_optparse
14
15def print_bits_as_bed( bits ):
16    end = 0
17    while 1:
18        start = bits.next_set( end )
19        if start == bits.size: break
20        end = bits.next_clear( start )
21        print "%s\t%d\t%d" % ( chrom, start, end )
22
23options, args = doc_optparse.parse( __doc__ )
24try:
25    in_fname, in2_fname = args
26except:
27    doc_optparse.exit()
28
29# Read first bed into some bitsets
30
31bitsets1 = binned_bitsets_from_file( open( in_fname ) )
32bitsets2 = binned_bitsets_from_file( open( in2_fname ) )
33
34for chrom in bitsets1: 
35    if chrom not in bitsets1:
36        continue
37    bits1 = bitsets1[chrom]
38    if chrom in bitsets2:
39        bits2 = bitsets2[chrom]
40        bits2.invert()
41        bits1.iand( bits2 )
42    print_bits_as_bed( bits1 )
43   
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。