root/galaxy-central/eggs/bx_python-0.5.0_dev_f74aec067563-py2.6-macosx-10.6-universal-ucs2.egg/bx/phylo/phast.py @ 3

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

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

行番号 
1"""
2Rudimentary support for PHAST's tree model file format (a simple format for
3storing trees and rate matrices).
4"""
5
6from numpy import *
7
8class TreeModel:
9    def __init__( self ):
10        self.alphabet = None
11        self.radix = 0
12        self.order = 0
13        self.subst_mod = None
14        self.background = None
15        self.tree = None
16        self.matrix = None
17    ## TODO: Need scipy for this method
18    ## def matrix_for_time( self, t ):
19    ##     return expm( self.matrix * t )
20    ## matrix_for_time = cachedmethod( matrix_for_time )
21    @staticmethod
22    def from_file( f ):
23        input = iter( f )
24        tm = TreeModel()
25        for line in input:
26            if line.startswith( "ALPHABET:" ):
27                tm.alphabet = tuple( line.split()[1:] )   
28                tm.radix = len( tm.alphabet )
29            if line.startswith( "ORDER:" ):
30                tm.order = int( line.split()[1] )
31            if line.startswith( "SUBST_MOD:" ):
32                tm.subst_mod = line[11:].rstrip()                   
33            if line.startswith( "BACKGROUND:" ):
34                tm.background = tuple( map( float, line.split()[1:] ) )
35            if line.startswith( "TREE:" ):
36                tm.tree = line[6:].strip()
37            if line.startswith( "RATE_MAT:" ):
38                matrix = zeros( (tm.radix,tm.radix), float )
39                for i in range( len( tm.alphabet ) ):
40                    matrix[i] = map( float, input.next().split() )
41                tm.matrix = matrix
42        return tm
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。