示例#1
0
def test_rho_simple():
    K = 2
    sequences = [
            'tga',
    ]
    m = create_model( K, sequences, psi, theta, phi, upsilon )
    v = m.var_dist
    v.eta = numpy.array( # a pssm that looks like G[G]A
            [
                    [ 0.25, 0.25, 0.25, 0.25 ],
                    [ 0.01, 0.01, 0.97, 0.01 ],
                    [ 0.01, 0.01, 0.97, 0.01 ],
                    [ 0.97, 0.01, 0.01, 0.01 ]
            ]
    )
    print 'Updating'
    for i in xrange( 100 ):
        print m.update(
                update_rho = True,
                update_eta = False,
                update_tau = False
        ),
        print "\n".join( str( r ) for r in v.r_mode )
    hmm.write_model_svg(
            m,
            name = 'rho_simple',
            dir = 'test',
            show_rev_comp = True,
            show_dists = False,
            edge_lengths = 3.0
    )
    return m, v
示例#2
0
def test_simple():
    K = 2
    sequences = [
        'tg',
        'tg',
        'tag',
        'tag',
    ]
    print theta
    m = create_model(K, sequences, psi, theta, phi, upsilon)
    #hmm.write_model_svg(
    #       m,
    #       name = '%d' % K,
    #       dir = 'test',
    #       show_rev_comp = True,
    #       show_dists = False,
    #       edge_lengths = 3.0
    #)
    #raise ""
    v = m.var_dist
    v.eta = numpy.array(  # a pssm that looks like T[A]G
        [[0.25, 0.25, 0.25, 0.25], [0.01, 0.01, 0.01, 0.97],
         [0.97, 0.01, 0.01, 0.01], [0.01, 0.01, 0.97, 0.01]])
    print 'Updating'
    for i in xrange(100):
        m.update(update_rho=True, update_eta=False, update_tau=True)
    print "\n".join(str(r) for r in m.var_dist.r_mode)
    hmm.write_model_svg(m,
                        name='simple',
                        dir='test',
                        show_rev_comp=True,
                        show_dists=True,
                        edge_lengths=3.0)
    return m, v
示例#3
0
def test_tau_simple():
    K = 1
    sequences =     [
            'tg',
    ]
    m = create_model( K, sequences, psi, theta, phi, upsilon )
    v = m.var_dist
    v.rho = numpy.array(
            [
                    [
                            [ .98, .01, .01 ],
                            [ .01, .98, .01 ]
                    ]
            ]
    )
    print 'Updating'
    for i in xrange( 100 ):
        m.update(
                update_rho = False,
                update_eta = True,
                update_tau = True
        )
    hmm.write_model_svg(
            m,
            name = 'tau_simple',
            dir = 'test',
            show_rev_comp = True,
            show_dists = False,
            edge_lengths = 3.0
    )
    return m, v
示例#4
0
def test_tau_gapped():
    K = 2
    sequences = [
        'tag',
        'tg',
    ]
    m = create_model(K, sequences, psi, theta, phi, upsilon)
    v = m.var_dist
    v.rho = [
        numpy.array([
            [.01, .94, .01, .01, .01, .01, .01],
            [.01, .01, .94, .01, .01, .01, .01],
            [.01, .01, .01, .94, .01, .01, .01],
        ]),
        numpy.array([
            [.01, .94, .01, .01, .01, .01, .01],
            [.01, .01, .01, .94, .01, .01, .01],
        ])
    ]
    print 'Updating'
    for i in xrange(100):
        m.update(update_rho=False, update_eta=True, update_tau=True)
    hmm.write_model_svg(m,
                        name='tau_gapped',
                        dir='test',
                        show_rev_comp=True,
                        show_dists=False,
                        edge_lengths=3.0)
    return m, v
示例#5
0
def test_eta_gapped():
    "Test update eta with gapped 2 base pssm"
    K = 2
    sequences = [
        'tag',  # 'a' is the gap
        #'tg',
    ]
    m = create_model(K, sequences, psi, theta, phi, upsilon)
    v = m.var_dist
    v.rho = [
        numpy.array([
            [.01, .94, .01, .01, .01, .01, .01],
            [.01, .01, .94, .01, .01, .01, .01],
            [.01, .01, .01, .94, .01, .01, .01],
        ]),
        #               numpy.array(
        #                       [
        #                               [ .01, .94, .01, .01, .01, .01, .01 ],
        #                               [ .01, .01, .01, .94, .01, .01, .01 ],
        #                       ]
        #               )
    ]
    for i in xrange(100):
        m.update(update_rho=False, update_eta=True, update_tau=False)
    print 'Updating'
    hmm.write_model_svg(m,
                        name='eta_gapped',
                        dir='test',
                        show_rev_comp=True,
                        show_dists=True,
                        edge_lengths=3.0)
    return m, v
示例#6
0
def test_write_models():
    for k in xrange( 10 ):
        model = hmm.Model(
                hmm.ObservedData(
                        k + 1,
                        hmm.ObservedSequences( sequences )
                )
        )
        hmm.write_model_svg(
                model,
                'states_%d' % (k + 1),
                show_rev_comp = False
        )
示例#7
0
def test_transitions():
    "Test that transition probs are set correctly. Can check by inspecting svg."
    K = 3
    sequences = [
        'tgacg',
    ]
    m = create_model(K, sequences, psi, theta, phi, upsilon)
    v = m.var_dist
    v.tau = numpy.array([[.90, .10], [.50, .50], [.80, .20]])
    hmm.write_model_svg(m,
                        name='transitions',
                        dir='test',
                        show_rev_comp=True,
                        show_dists=False,
                        edge_lengths=3.0)
    return m, v
示例#8
0
def test_simple():
    K = 2
    sequences = [
            'tg',
            'tg',
            'tag',
            'tag',
    ]
    print theta
    m = create_model( K, sequences, psi, theta, phi, upsilon )
    #hmm.write_model_svg(
    #       m,
    #       name = '%d' % K,
    #       dir = 'test',
    #       show_rev_comp = True,
    #       show_dists = False,
    #       edge_lengths = 3.0
    #)
    #raise ""
    v = m.var_dist
    v.eta = numpy.array( # a pssm that looks like T[A]G
            [
                    [ 0.25, 0.25, 0.25, 0.25 ],
                    [ 0.01, 0.01, 0.01, 0.97 ],
                    [ 0.97, 0.01, 0.01, 0.01 ],
                    [ 0.01, 0.01, 0.97, 0.01 ]
            ]
    )
    print 'Updating'
    for i in xrange( 100 ):
        m.update(
                update_rho = True,
                update_eta = False,
                update_tau = True
        )
    print "\n".join(str( r ) for r in m.var_dist.r_mode)
    hmm.write_model_svg(
            m,
            name = 'simple',
            dir = 'test',
            show_rev_comp = True,
            show_dists = True,
            edge_lengths = 3.0
    )
    return m, v
示例#9
0
def test_eta_simple():
    "Test update eta with simple 1 base pssm"
    K = 1
    sequences = [
        'tg',
    ]
    m = create_model(K, sequences, psi, theta, phi, upsilon)
    v = m.var_dist
    v.rho = numpy.array([[[.98, .01, .01], [.01, .98, .01]]])
    print 'Updating'
    for i in xrange(100):
        m.update(update_rho=False, update_eta=True, update_tau=False)
    hmm.write_model_svg(m,
                        name='eta_simple',
                        dir='test',
                        show_rev_comp=True,
                        show_dists=True,
                        edge_lengths=3.0)
    return m, v
示例#10
0
def test_rho_simple():
    K = 2
    sequences = [
        'tga',
    ]
    m = create_model(K, sequences, psi, theta, phi, upsilon)
    v = m.var_dist
    v.eta = numpy.array(  # a pssm that looks like G[G]A
        [[0.25, 0.25, 0.25, 0.25], [0.01, 0.01, 0.97, 0.01],
         [0.01, 0.01, 0.97, 0.01], [0.97, 0.01, 0.01, 0.01]])
    print 'Updating'
    for i in xrange(100):
        print m.update(update_rho=True, update_eta=False, update_tau=False),
        print "\n".join(str(r) for r in v.r_mode)
    hmm.write_model_svg(m,
                        name='rho_simple',
                        dir='test',
                        show_rev_comp=True,
                        show_dists=False,
                        edge_lengths=3.0)
    return m, v
示例#11
0
def test_eta_gapped():
    "Test update eta with gapped 2 base pssm"
    K = 2
    sequences =     [
            'tag', # 'a' is the gap
            #'tg',
    ]
    m = create_model( K, sequences, psi, theta, phi, upsilon )
    v = m.var_dist
    v.rho = [
            numpy.array(
                    [
                            [ .01, .94, .01, .01, .01, .01, .01 ],
                            [ .01, .01, .94, .01, .01, .01, .01 ],
                            [ .01, .01, .01, .94, .01, .01, .01 ],
                    ]
            ),
#               numpy.array(
#                       [
#                               [ .01, .94, .01, .01, .01, .01, .01 ],
#                               [ .01, .01, .01, .94, .01, .01, .01 ],
#                       ]
#               )
    ]
    for i in xrange( 100 ):
        m.update(
                update_rho = False,
                update_eta = True,
                update_tau = False
        )
    print 'Updating'
    hmm.write_model_svg(
            m,
            name = 'eta_gapped',
            dir = 'test',
            show_rev_comp = True,
            show_dists = True,
            edge_lengths = 3.0
    )
    return m, v
示例#12
0
def test_transitions():
    "Test that transition probs are set correctly. Can check by inspecting svg."
    K = 3
    sequences =     [
            'tgacg',
    ]
    m = create_model( K, sequences, psi, theta, phi, upsilon )
    v = m.var_dist
    v.tau = numpy.array(
            [
                    [ .90, .10 ],
                    [ .50, .50 ],
                    [ .80, .20 ]
            ]
    )
    hmm.write_model_svg(
            m,
            name = 'transitions',
            dir = 'test',
            show_rev_comp = True,
            show_dists = False,
            edge_lengths = 3.0
    )
    return m, v
示例#13
0
def test_write_models():
    for k in xrange(10):
        model = hmm.Model(
            hmm.ObservedData(k + 1, hmm.ObservedSequences(sequences)))
        hmm.write_model_svg(model, 'states_%d' % (k + 1), show_rev_comp=False)