root/galaxy-central/eggs/bx_python-0.5.0_dev_f74aec067563-py2.6-macosx-10.6-universal-ucs2.egg/bx/misc/readlengths.py

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

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

行番号 
1"""
2Read sequence lengths from a file.  Each line is of the form <name> <length>
3where <name> is typically a chromsome name (e.g. chr12) and length is the
4number of bases the sequence.
5"""
6
7def read_lengths_file( name ):
8    """
9    Returns a hash from sequence name to length.
10    """
11   
12    chrom_to_length = {}
13    f = file ( name, "rt" )
14    for line in f:
15        line = line.strip()
16        if line == '' or line[0] == '#': continue
17        try:
18            fields = line.split()
19            if len(fields) != 2: raise
20            chrom = fields[0]
21            length = int( fields[1] )
22        except:
23            raise "bad length file line: %s" % line
24        if chrom in chrom_to_length and length != chrom_to_length[chrom]:
25            raise "%s has more than one length!" % chrom
26        chrom_to_length[chrom] = length
27    f.close()
28    return chrom_to_length
29
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。