Coverage for test_alignment.py: 96%

23 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-03-21 09:19 +0100

1 

2import sys 

3import os 

4import tarfile 

5from io import StringIO, BytesIO 

6import unittest 

7sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + '/..')) 

8 

9#from collections import namedtuple 

10from tempfile import NamedTemporaryFile, TemporaryDirectory 

11 

12from ete4 import Tree 

13from treeprofiler import tree_annotate 

14from treeprofiler.src import utils 

15 

16class TestMSA(unittest.TestCase): 

17 def test_annotate_msa(self): 

18 # test alignment 

19 # load tree 

20 internal_parser = "name" 

21 parser = utils.get_internal_parser(internal_parser) 

22 

23 test_tree_msa = utils.ete4_parse("(A:1,(B:1,(E:1,D:1)Internal_1:0.5)Internal_2:0.5)Root;") 

24 

25 # load metadata 

26 with NamedTemporaryFile(suffix='.faa') as f_alignment: 

27 f_alignment.write(b'>A\nMAEIPDETIQQFMALT---HNIAVQYLSEFGDLNEALNSYYASQTDDIKDRREEAH\n>B\nMAEIPDATIQQFMALTNVSHNIAVQY--EFGDLNEALNSYYAYQTDDQKDRREEAH\n>E\nMAEIPDATIQ---ALTNVSHNIAVQYLSEFGDLNEALNSYYASQTDDQPDRREEAH\n>D\nMAEAPDETIQQFMALTNVSHNIAVQYLSEFGDLNEAL--------------REEAH') 

28 f_alignment.flush() 

29 

30 #metadata_dict, node_props, columns, prop2type = tree_annotate.parse_csv([f_annotation.name]) 

31 

32 test_tree_annotated_msa, annotated_prop2type = tree_annotate.run_tree_annotate(test_tree_msa, 

33 alignment=f_alignment.name, emapper_annotations=None 

34 ) 

35 

36 expected_tree_msa = '(A:1[&&NHX:alignment=MAEIPDETIQQFMALT---HNIAVQYLSEFGDLNEALNSYYASQTDDIKDRREEAH],(B:1[&&NHX:alignment=MAEIPDATIQQFMALTNVSHNIAVQY--EFGDLNEALNSYYAYQTDDQKDRREEAH],(E:1[&&NHX:alignment=MAEIPDATIQ---ALTNVSHNIAVQYLSEFGDLNEALNSYYASQTDDQPDRREEAH],D:1[&&NHX:alignment=MAEAPDETIQQFMALTNVSHNIAVQYLSEFGDLNEAL--------------REEAH])Internal_1:0.5[&&NHX:alignment=MAE-PD-TIQQFMALTNVSHNIAVQYLSEFGDLNEALNSYYASQTDDQPDRREEAH])Internal_2:0.5[&&NHX:alignment=MAE-PD-TIQQFMALTNVSHNIAVQYLSEFGDLNEALNSYYA-QTDDQ-DRREEAH])Root[&&NHX:alignment=MAEIPD-TIQQFMALTNVSHNIAVQYLSEFGDLNEALNSYYA-QTDD--DRREEAH];' 

37 self.assertEqual(test_tree_annotated_msa.write(props=['alignment'], parser=parser, format_root_node=True), expected_tree_msa) 

38 

39if __name__ == '__main__': 

40 unittest.main() 

41#pytest.main(['-v'])