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

リビジョン 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"""
4Read a set of ranges and a nib file, print portions of nib overlapping
5those ranges to stdout
6
7TODO: General sequence handling would be nice, as well as merging with
8      'nib_intervals_to_fasta.py'.
9
10usage: %prog nib_dir < range_file
11"""
12
13from bx.cookbook import doc_optparse
14import bx.seq.nib
15import string
16import sys
17
18def __main__():
19
20    options, args = doc_optparse.parse( __doc__ )
21
22    try:
23        nib_dir = args[0]
24    except:
25        doc_optparse.exit()
26
27    nibs = {}
28
29    for line in sys.stdin:
30        fields = line.split()
31        chrom, start, end = fields[0], int( fields[1] ), int( fields[2] )
32        print ">", chrom, start, end
33        if chrom in nibs:
34            nib = nibs[chrom]
35        else:
36            nibs[chrom] = nib = bx.seq.nib.NibFile( file( "%s/%s.nib" % ( nib_dir, chrom ) ) )
37        print_wrapped( nib.get( start, end - start ) )
38
39def print_wrapped( s ):
40    l = len( s )       
41    c = 0
42    while c < l:
43        b = min( c + 50, l )
44        print s[c:b]
45        c = b
46
47if __name__ == "__main__": __main__()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。