File: test_dialign.py

package info (click to toggle)
python-cogent 1.4.1-1.2
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze
  • size: 13,260 kB
  • ctags: 20,087
  • sloc: python: 116,163; ansic: 732; makefile: 74; sh: 9
file content (133 lines) | stat: -rw-r--r-- 4,417 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python

from os import getcwd, remove, rmdir, mkdir, path
import tempfile, shutil
from cogent.util.unit_test import TestCase, main
from cogent.util.misc import flatten
from cogent.app.dialign import Dialign

__author__ = "Gavin Huttley"
__copyright__ = "Copyright 2007-2009, The Cogent Project"
__credits__ = ["Gavin Huttley"]
__license__ = "GPL"
__version__ = "1.4.1"
__maintainer__ = "Gavin Huttley"
__email__ = "gavin.huttley@anu.edu.au"
__status__ = "Production"

class GeneralSetUp(TestCase):
    
    def setUp(self):
        """Dialign general setUp method for all tests"""
        self.seqs1 = ['LDTAPCLFSDGSPQKAAYVLWDQTILQQDITPLPSHETHSAQKGELLALICGLRAAK',
            'PDADHTWYTDGSSLLQEGQRKAGAAVTTETEVIWAKALDAGTSAQRAELIALTQALKM',
            'RPGLCQVFADATPTGWGLVMGHQRMRGTFSAPLPIHTAELLAACFARSRSGANIIGTDNSVV',
            'MLKQVEIFTDGSCLGNPGPGGYGAILRYRGREKTFSAGYTRTTNNRMELMAAIV']
        self.labels1 = ['>HTL2','>MMLV', '>HEPB', '>ECOL']
        self.lines1 = flatten(zip(self.labels1,self.seqs1))
        self.out = \
"""
                            DIALIGN 2.2.1 
                            *************

           Program code written by Burkhard Morgenstern and Said Abdeddaim 
              e-mail contact: dialign (at) gobics (dot) de 

           Published research assisted by DIALIGN 2 should cite:  

              Burkhard Morgenstern (1999).
              DIALIGN 2: improvement of the segment-to-segment
              approach to multiple sequence alignment.
              Bioinformatics 15, 211 - 218. 

           For more information, please visit the DIALIGN home page at 

              http://bibiserv.techfak.uni-bielefeld.de/dialign/ 

          ************************************************************



    program call:  dialign2-2 -fa -fn /tmp/di/seq1.fasta /tmp/di/seq1.txt  


    Aligned sequences:          length:
    ==================          =======

    1) HTL2                        57
    2) MMLV                        58
    3) HEPB                        62
    4) ECOL                        54

    Average seq. length:           57.8 


    Please note that only upper-case letters are considered to be aligned. 


    Alignment (DIALIGN format):
    ===========================

 HTL2               1   ldtapC-LFS DGS------P QKAAYVL--- ----WDQTIL QQDITPLPSH 
 MMLV               1   pdadhtw-YT DGSSLLQEGQ RKAGAAVtte teviWa---- KALDAG---T 
 HEPB               1   rpgl-CQVFA DAT------P TGWGLVM--- ----GHQRMR GTFSAPLPIH 
 ECOL               1   mlkqv-EIFT DGSCLGNPGP GGYGAIL--- ----RYRGRE KTFSAGytrT 

                        0000000588 8882222229 9999999000 0000666666 6666633334 

 HTL2              37   ethSAQKGEL LALICGLRAa k--------- --- 
 MMLV              43   ---SAQRAEL IALTQALKm- ---------- --- 
 HEPB              37   t------AEL LAA-CFARSr sganiigtdn svv 
 ECOL              43   ---TNNRMEL MAAIv----- ---------- --- 

                        0003333455 5533333300 0000000000 000 




    Sequence tree:
    ==============

 Tree constructed using UPGMAbased on DIALIGN fragment weight scores

 ((HTL2        :0.130254MMLV        :0.130254):0.067788(HEPB        :0.120520ECOL        :0.120520):0.077521);



"""
        self.temp_dir = tempfile.mkdtemp()
        try:
            #create sequence files
            f = open(path.join(self.temp_dir, 'seq1.txt'),'w')
            f.write('\n'.join(self.lines1))
            f.close()
        except OSError:
            pass

class DialignTests(GeneralSetUp):
    """Tests for the Dialign application controller"""
    
    def test_base_command(self):
        """Dialign BaseCommand should return the correct BaseCommand"""
        c = Dialign()
        self.assertEqual(c.BaseCommand,
            ''.join(['cd ','"%s/"; ' % getcwd(),'dialign2-2']))
        
        c.Parameters["-fa"].on()
        self.assertEqual(c.BaseCommand,\
            ''.join(['cd ','"%s/"; ' % getcwd(),'dialign2-2 -fa']))
    
    def test_align(self):
        """test aligning samples"""
        c = Dialign(WorkingDir=self.temp_dir,
            params={"-fn":path.join(self.temp_dir,"seq1.txt")})
        c.Parameters["-fa"].on()
        res = c(path.join(self.temp_dir, 'seq1.txt'))
        align = "".join(res["Align"].readlines())
    
    def test_cleaning_up(self):
        """not a test, just removes the temp files"""
        shutil.rmtree(self.temp_dir)

if __name__ == '__main__':
    main()