source: tags/ms_r18q1/SL/PVP/pvp.cxx

Last change on this file was 16901, checked in by westram, 6 years ago
  • fixes #782
    • AWT_translator::Pro2Bitset uses indices (not plain AA-characters)
    • build char_2_bitstring table for protein data
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1// ============================================================= //
2//                                                               //
3//   File      : pvp.cxx                                         //
4//   Purpose   : calculate positional variability (parsimony)    //
5//                                                               //
6//   Institute of Microbiology (Technical University Munich)     //
7//   http://www.arb-home.de/                                     //
8//                                                               //
9// ============================================================= //
10
11#include "pvp.h"
12#include "AP_pos_var.h"
13
14#include <TreeNode.h>
15#include <arb_progress.h>
16
17GB_ERROR PVP_calculate(GBDATA *gb_main, const char *ali_name, const char *tree_name, const char *target_SAI_name) {
18    GB_ERROR       error   = NULp;
19    GB_transaction ta(gb_main);
20    long           ali_len = GBT_get_alignment_len(gb_main, ali_name);
21
22    if (ali_len <= 0) {
23        error = GB_await_error();
24    }
25    else {
26        arb_progress progress("Calculating positional variability");
27        progress.subtitle("Loading Tree");
28
29        // get tree
30        TreeNode *tree;
31        {
32            tree = GBT_read_tree(gb_main, tree_name, new SimpleRoot);
33            if (!tree) {
34                error = GB_await_error();
35            }
36            else {
37                GBT_link_tree(tree, gb_main, true, NULp, NULp);
38            }
39        }
40
41        if (!error) {
42            progress.subtitle("Counting mutations");
43
44            GB_alignment_type at    = GBT_get_alignment_type(gb_main, ali_name);
45            bool              isNUC = at==GB_AT_DNA || at==GB_AT_RNA;
46
47            AP_pos_var pvp(gb_main, ali_name, ali_len, isNUC, tree_name);
48
49            error             = pvp.delete_aliEntry_from_SAI(target_SAI_name);
50            if (!error) error = pvp.retrieve(tree);
51            if (!error) error = pvp.save_aliEntry_to_SAI(target_SAI_name);
52        }
53
54        destroy(tree);
55    }
56
57    ta.close(error);
58
59    return error;
60}
61
62// --------------------------------------------------------------------------------
63
64#ifdef UNIT_TESTS
65#ifndef TEST_UNIT_H
66#include <test_unit.h>
67#endif
68
69static arb_test::match_expectation saidata_equal(GBDATA *gb_main, const char *sainame, const char *aliname, const char *expected_data) {
70    using namespace arb_test;
71
72    GB_transaction ta(gb_main);
73
74    GBDATA *gb_sai     = GBT_find_SAI(gb_main, sainame);
75    GBDATA *gb_saiali  = GB_entry(gb_sai, aliname);
76    GBDATA *gb_saidata = GB_entry(gb_saiali, "data");
77
78    const char *saidata = GB_read_char_pntr(gb_saidata);
79
80    return that(saidata).is_equal_to(expected_data);
81}
82static arb_test::match_expectation saitype_equal(GBDATA *gb_main, const char *sainame, const char *aliname, const char *expected_type) {
83    using namespace arb_test;
84
85    GB_transaction ta(gb_main);
86
87    GBDATA *gb_sai     = GBT_find_SAI(gb_main, sainame);
88    GBDATA *gb_saiali  = GB_entry(gb_sai, aliname);
89    GBDATA *gb_saitype = GB_entry(gb_saiali, "_TYPE");
90
91    const char *saitype = GB_read_char_pntr(gb_saitype);
92
93    return that(saitype).is_equal_to(expected_type);
94}
95
96#define TEST_EXPECT_SAIDATA_EQUAL(expected) TEST_EXPECTATION(saidata_equal(gb_main,SAI_name,aliname,expected))
97#define TEST_EXPECT_SAITYPE_EQUAL(expected) TEST_EXPECTATION(saitype_equal(gb_main,SAI_name,aliname,expected))
98
99void TEST_pvp() {
100    GB_shell    shell;
101    const char *SAI_name = "POS_VAR_BY_PARSIMONY";
102
103    { // nuc data:
104        GBDATA     *gb_main = GB_open("TEST_nuc.arb", "rw");
105        const char *aliname = "ali_16s";
106        TEST_EXPECT_NO_ERROR(PVP_calculate(gb_main, aliname, "tree_nuc", SAI_name));
107
108        TEST_EXPECT_SAITYPE_EQUAL("PVP: Positional Variability by Parsimony: tree 'tree_nuc' ntaxa 12");
109        TEST_EXPECT_SAIDATA_EQUAL(".----222----7------32-7-7----774-----77-----747-77-7-47-----------73--433-.3134--1-41-4-4011222337--"
110                                  "....-632320124--11141-4-..24312434--3----7-77---7----774-4-4-34--44-77-732777424--7-----3247------44"
111                                  "33----------2--73063442221633737777326110244-3----73--2--4-773--4-7--3774777137-7774437274-3372--7--"
112                                  "--7------47-7---24--73--------2-4--7374---74-734------43-777-47-7---3---3----------7-3---3----------"
113                                  "-----7-----4-7----7--4-4------3--3---3----4-4---4-47-------77---4-----447-7--4-7-----377--7-7434373-"
114                                  "-77--5412243422747--7-441244321337--777--3434333-77---777---------7------------7-----------7---77--4"
115                                  "-7----477----4---7-----------4-774-4---7--742237-7-777-7---4---327447----4----43477423-----447-7--77"
116                                  "21234--7---7477-77777-727777---7-3--4---77------7------7---4--4--4-4---7---7------------47727--47777"
117                                  "4477-----7--4-7747-------47---7-7-7--------------------------74--7----------43-7--7477-774734-6----7"
118                                  "47---6-42-447-774-4--------77-----7-34-------7-------747------77-7---------4------------4-----------"
119                                  "7-----------------------4--4---7-.---7--------74437-------7-3424-732233427--7-72333127-6.--7777---6-"
120                                  "-424347-------7-------47--------------77----77---------------7------------------77437-77------4-743-"
121                                  "77-3-77---7----7-3377-------7-7-74--7-7---------7-7---4-------74---7----7------7-3447----7----------"
122                                  "--------2443----7777-33--2-4444-7--44437---37---7746----34447-47---7----7--4--4----------4--4--7----"
123                                  "44-----7---------7-4777-----3-77774-7------------7----47---------------------7--7-47---47-774777744-"
124                                  "--34-7-44227----3...7712.1----123-7742-4-777774-7774----4-3--7--------------------77--447--744--77-7"
125                                  "---------------3-...");
126
127        // tests reported errors:
128        TEST_EXPECT_ERROR_CONTAINS(PVP_calculate(gb_main, "ali_61s", "tree_nuc",  SAI_name), "alignment 'ali_61s' not found");
129        TEST_EXPECT_ERROR_CONTAINS(PVP_calculate(gb_main, "ali_16s", "tree_miss", SAI_name), "tree not found");
130
131        GB_close(gb_main);
132    }
133
134    { // protein data:
135        GBDATA     *gb_main = GB_open("TEST_prot.arb", "rw");
136        const char *aliname = "ali_tuf_pro";
137        TEST_EXPECT_NO_ERROR(PVP_calculate(gb_main, aliname, "tree_prot", SAI_name));
138
139        TEST_EXPECT_SAITYPE_EQUAL("PVP: Positional Variability by Parsimony: tree 'tree_prot' ntaxa 11");
140        TEST_EXPECT_SAIDATA_EQUAL("-----4-634363-4-3-4666----6--6-6-6666466666664666466666-43-34366633334446-4666-364-6--66666664-44646"
141                                  "666-4---4-66---6--66-4-66-6666444-6666466666--4--4--6466633346-62--3-3436343243266464433446433434662"
142                                  "2-4634-663466644346314-23364666646243343-6366-34632-0632-46646-666-43-6-6---46-46-3-3432-32634464334"
143                                  "443636666-66461612636----64664642421634-3-33444443632334-1-3-64-44664646634-433366666623624426246444"
144                                  "4436330334446-63434344622344666320664664--666643--66-446341446--6------6--466----------");
145
146        GB_close(gb_main);
147    }
148}
149
150#endif // UNIT_TESTS
151
152// --------------------------------------------------------------------------------
153
154
155
Note: See TracBrowser for help on using the repository browser.