root/galaxy-central/eggs/bx_python-0.5.0_dev_f74aec067563-py2.6-macosx-10.6-universal-ucs2.egg/EGG-INFO/scripts/interval_join.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"""
4Match up intersecting intervals from two files. This performs a "full join",
5any pair of intervals with any basewise overlap will be printed side-by-side.
6
7usage: %prog bed1 bed2
8"""
9
10from __future__ import division
11
12import psyco_full
13
14import string
15import sys
16
17import bx.intervals.io
18import bx.intervals.intersection
19
20def main():
21
22    intersecters = {}
23
24    # Read second set into intersecter
25    for interval in bx.intervals.io.GenomicIntervalReader( open( sys.argv[2] ) ):
26        if not intersecters.has_key( interval.chrom ):
27            intersecters[ interval.chrom ] = bx.intervals.Intersecter()
28        intersecters[ interval.chrom ].add_interval( interval )
29
30    # Join with first set   
31    for interval in bx.intervals.io.GenomicIntervalReader( open( sys.argv[1] ) ):
32        if intersecters.has_key( interval.chrom ):
33            intersection = intersecters[ interval.chrom ].find( interval.start, interval.end )
34            for interval2 in intersection:
35                print "\t".join( [ str( interval ), str( interval2 ) ] )
36
37
38if __name__ == "__main__":
39    main()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。