Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/rev/61b61f911a1a
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 00:38:35 2012
Кодировка:

Поисковые слова: m 35
allpy: 61b61f911a1a

allpy

changeset 1094:61b61f911a1a

Reorganized tests to make them more readable
author Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru>
date Sat, 02 Jun 2012 22:15:27 +0400
parents 0aa68678861c
children f05b08e13072
files test/test_base.py test/test_io_biopython.py test/test_io_emboss.py test/test_realign.py
diffstat 4 files changed, 138 insertions(+), 143 deletions(-) [+]
line diff
     1.1 --- a/test/test_base.py	Sat Jun 02 21:56:13 2012 +0400
     1.2 +++ b/test/test_base.py	Sat Jun 02 22:15:27 2012 +0400
     1.3 @@ -1,22 +1,8 @@
     1.4 -import re
     1.5 -from StringIO import StringIO
     1.6 -
     1.7 -import allpy.base
     1.8 -import allpy.protein as p
     1.9 -from allpy import processors
    1.10 -
    1.11 -# XXX Totally missed:
    1.12 -# XXX - monomer representation (should we test it at all?)
    1.13 -# XXX - sequence comparison
    1.14 -# XXX - sequence representation
    1.15 -# XXX - Alignment.columns_as_lists
    1.16 -# XXX - Alignment.flush (which is a backwards-compatibility wrapper)
    1.17 -# XXX - Alignment.process (which is a backwards-compatibility alias)
    1.18 -# XXX - Block.from_alignment with None in either of arguments
    1.19 +from allpy import protein, base
    1.20  
    1.21  def test_new_monomers():
    1.22      """Test creation of monomer objects"""
    1.23 -    s = allpy.base.Sequence()
    1.24 +    s = base.Sequence()
    1.25  
    1.26      try:
    1.27          m = s.append_monomer(code1='A')
    1.28 @@ -25,7 +11,7 @@
    1.29      else:
    1.30          assert False, "base.Seqeuence must not be constructible from code1"
    1.31  
    1.32 -    m = p.Sequence().append_monomer(code3='ALA')
    1.33 +    m = protein.Sequence().append_monomer(code3='ALA')
    1.34      assert m.__class__.__name__ == "Alanine"
    1.35      assert m.code1 == "A"
    1.36      assert m.code3 == "ALA"
    1.37 @@ -48,123 +34,4 @@
    1.38      m = s.append_monomer(code3='SEC')
    1.39      assert m.name == "Selenocysteine"
    1.40  
    1.41 -def assert_alignment(alignment, *body):
    1.42 -    """Helper: check if alignment representation matches strings of body"""
    1.43 -    s = StringIO()
    1.44 -    alignment.to_file(s)
    1.45 -    body = "".join([">\n%s\n" % string for string in body])
    1.46 -    assert s.getvalue() == body, "Expected:\n%s\nGot:\n%s" % (body, s.getvalue())
    1.47 -
    1.48 -def test_alignment_changes():
    1.49 -    """Test operations that modify alignment"""
    1.50 -
    1.51 -    a = (p.Alignment().
    1.52 -        append_row_from_string("a-------cdef").
    1.53 -        append_row_from_string("ghiklmpq--").
    1.54 -        append_row_from_string("-------------rst"))
    1.55 -
    1.56 -    assert_alignment(a,
    1.57 -        "A-------CDEF----",
    1.58 -        "GHIKLMPQ--------",
    1.59 -        "-------------RST",
    1.60 -    )
    1.61 -
    1.62 -    a.realign(processors.Left())
    1.63 -    assert_alignment(a,
    1.64 -        "ACDEF-----------",
    1.65 -        "GHIKLMPQ--------",
    1.66 -        "RST-------------",
    1.67 -    )
    1.68 -
    1.69 -    a.realign(processors.Center())
    1.70 -    assert_alignment(a,
    1.71 -        "-----ACDEF------",
    1.72 -        "----GHIKLMPQ----",
    1.73 -        "------RST-------",
    1.74 -    )
    1.75 -
    1.76 -    a.realign(processors.Right())
    1.77 -    assert_alignment(a,
    1.78 -        "-----------ACDEF",
    1.79 -        "--------GHIKLMPQ",
    1.80 -        "-------------RST",
    1.81 -    )
    1.82 -
    1.83 -def test_stringio_conversions():
    1.84 -    a = (p.Alignment().
    1.85 -        append_row_from_string("a-c-d", name="Seq1").
    1.86 -        append_row_from_string("tgcga", name="Seq2"))
    1.87 -
    1.88 -    o = StringIO()
    1.89 -    a.to_file(o, "fasta")
    1.90 -    got = o.getvalue()
    1.91 -    expect = ">Seq1\nA-C-D\n>Seq2\nTGCGA\n"
    1.92 -    assert expect == got, "Expected:\n%r\nGot:\n%r" % (expect, got)
    1.93 -
    1.94 -    o = StringIO()
    1.95 -    a.to_file(o, "msf")
    1.96 -    got = o.getvalue()
    1.97 -    got = re.sub('(stdout MSF: 5 Type: N) .*', r'\1', got)
    1.98 -    expect = (
    1.99 -        "!!NA_MULTIPLE_ALIGNMENT 1.0\n"
   1.100 -        "\n"
   1.101 -        "  stdout MSF: 5 Type: N 03/06/11 CompCheck: 1918 ..\n"
   1.102 -        "\n"
   1.103 -        "  Name: Seq1       Len: 5  Check:  882 Weight: 1.00\n"
   1.104 -        "  Name: Seq2       Len: 5  Check: 1036 Weight: 1.00\n"
   1.105 -        "\n"
   1.106 -        "//\n"
   1.107 -        "\n"
   1.108 -        "           1   5\n"
   1.109 -        "Seq1       A.C.D\n"
   1.110 -        "Seq2       TGCGA\n"
   1.111 -        "\n"
   1.112 -    )
   1.113 -    expect = re.sub('(stdout MSF: 5 Type: N) .*', r'\1', expect)
   1.114 -    assert expect == got, "Expected:\n%r\nGot:\n%r" % (expect, got)
   1.115 -
   1.116 -    o.name = 'whoopie.msf'
   1.117 -    o.seek(0)
   1.118 -    b = p.Alignment().append_file(o, format='msf')
   1.119 -    assert b.rows_as_strings() == ["A-C-D", "TGCGA"]
   1.120 -    assert b.sequences[0].source == o.name
   1.121 -
   1.122 -def test_bio_io():
   1.123 -    """Test Bio python IO.
   1.124 -
   1.125 -    BioPython does not support msf, so it is not covered in many other tests.
   1.126 -    """
   1.127 -    file = (
   1.128 -        "# STOCKHOLM 1.0\n"
   1.129 -        "#=GS seqA  AC seqA123\n"
   1.130 -        "#=GS seqA  DR PDB; 1abc ; 1-42;\n"
   1.131 -        "#=GS seqB  AC seqB345\n"
   1.132 -        "SeqA             SEQVENCEHELLO\n"
   1.133 -        "#=GR SeqA  SS    -HHHHH---CHHH\n"
   1.134 -        "SeqB             SI-VENCE--LLO\n"
   1.135 -        "#=GR SeqB  SS    X-HHHHH--HHHH\n"
   1.136 -        "#=GC SS_cons     X-HHHHH--HHHH\n"
   1.137 -        "#=GC seq_cons    Si.VENCE.eLLo\n"
   1.138 -        "//\n"
   1.139 -    )
   1.140 -
   1.141 -    o = StringIO()
   1.142 -    o.write(file)
   1.143 -    o.seek(0)
   1.144 -
   1.145 -    aln = p.Alignment().append_file(o, "stockholm")
   1.146 -    assert len(aln.sequences) == 2
   1.147 -    assert len(aln.columns) == 13
   1.148 -    assert aln.sequences[1] not in aln.columns[2]
   1.149 -    assert aln.sequences[0][2].code1 == 'Q'
   1.150 -
   1.151 -    o = StringIO()
   1.152 -    aln.to_file(o, format='stockholm')
   1.153 -    o.seek(0)
   1.154 -    for line in o:
   1.155 -        hd = line.strip().split()[0]
   1.156 -        assert hd in ('#', '#=GS', '#=GF', '#=GC', 'SeqA', 'SeqB', '//')
   1.157 -    o.seek(0)
   1.158 -    assert iter(o).next() == "# STOCKHOLM 1.0\n"
   1.159 -
   1.160  # vim: set et ts=4 sts=4 sw=4:
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/test_io_biopython.py	Sat Jun 02 22:15:27 2012 +0400
     2.3 @@ -0,0 +1,42 @@
     2.4 +from StringIO import StringIO
     2.5 +from allpy import protein
     2.6 +
     2.7 +def test_bio_io():
     2.8 +    """Test Bio python IO.
     2.9 +
    2.10 +    BioPython does not support msf, so it is not covered in many other tests.
    2.11 +    """
    2.12 +    file = (
    2.13 +        "# STOCKHOLM 1.0\n"
    2.14 +        "#=GS seqA  AC seqA123\n"
    2.15 +        "#=GS seqA  DR PDB; 1abc ; 1-42;\n"
    2.16 +        "#=GS seqB  AC seqB345\n"
    2.17 +        "SeqA             SEQVENCEHELLO\n"
    2.18 +        "#=GR SeqA  SS    -HHHHH---CHHH\n"
    2.19 +        "SeqB             SI-VENCE--LLO\n"
    2.20 +        "#=GR SeqB  SS    X-HHHHH--HHHH\n"
    2.21 +        "#=GC SS_cons     X-HHHHH--HHHH\n"
    2.22 +        "#=GC seq_cons    Si.VENCE.eLLo\n"
    2.23 +        "//\n"
    2.24 +    )
    2.25 +
    2.26 +    o = StringIO()
    2.27 +    o.write(file)
    2.28 +    o.seek(0)
    2.29 +
    2.30 +    aln = protein.Alignment().append_file(o, "stockholm")
    2.31 +    assert len(aln.sequences) == 2
    2.32 +    assert len(aln.columns) == 13
    2.33 +    assert aln.sequences[1] not in aln.columns[2]
    2.34 +    assert aln.sequences[0][2].code1 == 'Q'
    2.35 +
    2.36 +    o = StringIO()
    2.37 +    aln.to_file(o, format='stockholm')
    2.38 +    o.seek(0)
    2.39 +    for line in o:
    2.40 +        hd = line.strip().split()[0]
    2.41 +        assert hd in ('#', '#=GS', '#=GF', '#=GC', 'SeqA', 'SeqB', '//')
    2.42 +    o.seek(0)
    2.43 +    assert iter(o).next() == "# STOCKHOLM 1.0\n"
    2.44 +
    2.45 +# vim: set et ts=4 sts=4 sw=4:
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/test_io_emboss.py	Sat Jun 02 22:15:27 2012 +0400
     3.3 @@ -0,0 +1,47 @@
     3.4 +import re
     3.5 +from StringIO import StringIO
     3.6 +
     3.7 +from allpy import protein
     3.8 +
     3.9 +def test_stringio_conversions():
    3.10 +    # MSF is not supported by any other handler, except EMBOSS,
    3.11 +    # so by testing MSF we essentially test EMBOSS
    3.12 +    a = (protein.Alignment().
    3.13 +        append_row_from_string("a-c-d", name="Seq1").
    3.14 +        append_row_from_string("tgcga", name="Seq2"))
    3.15 +
    3.16 +    o = StringIO()
    3.17 +    a.to_file(o, "fasta")
    3.18 +    got = o.getvalue()
    3.19 +    expect = ">Seq1\nA-C-D\n>Seq2\nTGCGA\n"
    3.20 +    assert expect == got, "Expected:\n%r\nGot:\n%r" % (expect, got)
    3.21 +
    3.22 +    o = StringIO()
    3.23 +    a.to_file(o, "msf")
    3.24 +    got = o.getvalue()
    3.25 +    got = re.sub('(stdout MSF: 5 Type: N) .*', r'\1', got)
    3.26 +    expect = (
    3.27 +        "!!NA_MULTIPLE_ALIGNMENT 1.0\n"
    3.28 +        "\n"
    3.29 +        "  stdout MSF: 5 Type: N 03/06/11 CompCheck: 1918 ..\n"
    3.30 +        "\n"
    3.31 +        "  Name: Seq1       Len: 5  Check:  882 Weight: 1.00\n"
    3.32 +        "  Name: Seq2       Len: 5  Check: 1036 Weight: 1.00\n"
    3.33 +        "\n"
    3.34 +        "//\n"
    3.35 +        "\n"
    3.36 +        "           1   5\n"
    3.37 +        "Seq1       A.C.D\n"
    3.38 +        "Seq2       TGCGA\n"
    3.39 +        "\n"
    3.40 +    )
    3.41 +    expect = re.sub('(stdout MSF: 5 Type: N) .*', r'\1', expect)
    3.42 +    assert expect == got, "Expected:\n%r\nGot:\n%r" % (expect, got)
    3.43 +
    3.44 +    o.name = 'whoopie.msf'
    3.45 +    o.seek(0)
    3.46 +    b = protein.Alignment().append_file(o, format='msf')
    3.47 +    assert b.rows_as_strings() == ["A-C-D", "TGCGA"]
    3.48 +    assert b.sequences[0].source == o.name
    3.49 +
    3.50 + # vim: set et ts=4 sts=4 sw=4: