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

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

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

行番号 
1import unittest
2import sys
3import bx.pwm.position_weight_matrix as pwm
4from StringIO import StringIO
5
6basicPwm = \
7""">MA0101 c-REL REL
80   5   8   4
90   1   15  1
101   0   15  1
115   1   9   2
126   5   3   3
135   1   1   10
141   0   0   16
152   0   0   15
160   15  0   2
171   16  0   0
18"""
19
20transfacPwm = \
21"""ID  TATA
22XX
23P0    A    C    G    T
2401   33   73   78   16      S
2502   10   24   11  155      T
2603  176    3    2   19      A
2704    2    7    3  188      T
2805  178    2    3   17      A
2906  133    2    2   63      A
3007  183    3   10    4      A
3108  112    2   24   62      W
3209   78   26   80   16      R
3310   29   72   75   24      N
3411   42   74   68   16      N
3512   42   65   66   27      N
3613   41   60   67   32      N
3714   35   54   72   39      N
3815   40   51   73   36      N
39XX
40"""
41
42background = { 'A':.28,'C':.21, 'G':.24, 'T':.27 }
43
44dSeq = "ACCGAGTTAGCGTAAA"
45dScoresExpected = "-15.3697 0.4240 -16.5309 0.4027"
46
47qSeq = [{'A':0.27,'C':0.34,'G':0.07,'T':0.32},
48        {'A':0.24,'C':0.32,'G':0.09,'T':0.35},
49        {'A':0.80,'C':0.11,'G':0.03,'T':0.06},
50        {'A':0.07,'C':0.22,'G':0.37,'T':0.34},
51        {'A':0.07,'C':0.44,'G':0.03,'T':0.46},
52        {'A':0.43,'C':0.04,'G':0.18,'T':0.35},
53        {'A':0.84,'C':0.14,'G':0.01,'T':0.01},
54        {'A':0.31,'C':0.52,'G':0.13,'T':0.04},
55        {'A':0.22,'C':0.22,'G':0.45,'T':0.11},
56        {'A':0.36,'C':0.15,'G':0.42,'T':0.07},
57        {'A':0.11,'C':0.78,'G':0.07,'T':0.04},
58        {'A':0.07,'C':0.16,'G':0.64,'T':0.13},
59        {'A':0.34,'C':0.59,'G':0.03,'T':0.04},
60        {'A':0.32,'C':0.15,'G':0.07,'T':0.46},
61        {'A':0.07,'C':0.03,'G':0.59,'T':0.31}]
62
63qScoresExpected = "4.1106 0.7810"
64
65class PWMTestCase (unittest.TestCase):
66
67    def testReader(self):
68
69        # test basic format: i.e. for jaspar
70        wms = [wm for wm in pwm.Reader(StringIO(basicPwm),format="basic", \
71                          background=background,score_correction=False)]
72        assert len(wms) == 1
73
74        # test transfac format
75        wms = [wm for wm in pwm.Reader(StringIO(transfacPwm),format="transfac", \
76                          background=background,score_correction=False)]
77        assert len(wms) == 1
78
79        wm = wms[0]
80        dScores = wm.score_seq(dSeq)
81        assert len(dScores) == 2
82        assert "%.4f %.4f %.4f %.4f" % (dScores[0][0],dScores[0][1],dScores[1][0],dScores[1][1]) == dScoresExpected
83
84        qdSeq = []
85        for (ix,nt) in enumerate(dSeq):
86            qdSeq.append(dict())
87            qdSeq[ix][nt] = 1.0
88        qScores = wm.score_seq(qdSeq)
89        assert len(qScores) == 2
90        assert "%.4f %.4f %.4f %.4f" % (qScores[0][0],qScores[0][1],qScores[1][0],qScores[1][1]) == dScoresExpected
91
92        qScores = wm.score_seq(qSeq)
93        assert len(qScores) == 1
94        assert "%.4f %.4f" % (qScores[0][0],qScores[0][1]) == qScoresExpected
95
96test_classes = [PWMTestCase]
97suite = unittest.TestSuite ([unittest.makeSuite (c) for c in test_classes])
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。