root/galaxy-central/eggs/bx_python-0.5.0_dev_f74aec067563-py2.6-macosx-10.6-universal-ucs2.egg/EGG-INFO/scripts/bed_count_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"""
3For each interval in `bed1` count the number of intersecting regions in `bed2`.
4
5usage: %prog bed1 bed2
6"""
7
8import sys
9from bx.intervals import *
10
11bed1,bed2 = sys.argv[1:3]
12
13ranges = {}
14for line in open( bed2 ):
15    fields = line.strip().split()
16    chrom, start, end, = fields[0], int(fields[1]), int(fields[2])
17    if chrom not in ranges: ranges[chrom] = Intersecter()
18    ranges[chrom].add_interval( Interval( start, end ) )
19   
20for line in open( bed1 ):
21    fields = line.strip().split()
22    chrom, start, end = fields[0], int(fields[1]), int(fields[2])
23    other = " ".join(fields[3:])
24    out = " ".join(fields[:3] +[other])
25    if chrom in ranges:
26        print out, len( ranges[chrom].find( start, end ) )
27    else:
28        print out, 0
29
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。