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

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

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

行番号 
1#!/usr/bin/python2.6
2
3"""
4Given two bed files print the number of bases covered 1) by both, 2) only by
5the first, and 3) only by the second.
6
7usage: %prog bed_file_1 bed_file_2
8"""
9import sys
10from warnings import warn
11from bx.bitset import BinnedBitSet
12from bx.bitset_builders import *
13from bx.cookbook import doc_optparse
14
15def coverage( bitsets ):
16    total = 0
17    for chrom in bitsets:
18        total += bitsets[chrom].count_range( 0, bitsets[chrom].size )
19    return total   
20
21options, args = doc_optparse.parse( __doc__ )
22try:
23    in_fname, in2_fname = args
24except:
25    doc_optparse.exit()
26
27bits1 = binned_bitsets_from_file( open( in_fname ) )
28bits2 = binned_bitsets_from_file( open( in2_fname ) )
29
30bits1_covered = coverage( bits1 )
31bits2_covered = coverage( bits2 )
32
33bitsets = dict()
34
35for key in bits1:
36    if key in bits2:
37        bits1[key].iand( bits2[key] )
38        bitsets[key] = bits1[key]
39
40both_covered = coverage( bitsets )
41
42print "in both:  \t%d" % both_covered
43print "only in %s:\t%d" % ( in_fname, bits1_covered - both_covered )
44print "only in %s:\t%d" % ( in2_fname, bits2_covered - both_covered )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。