1 /****************************************************************\
2 *                                                                *
3 *  Module for various affine gapped models                       *
4 *                                                                *
5 *  Guy St.C. Slater..   mailto:guy@ebi.ac.uk                     *
6 *  Copyright (C) 2000-2009.  All Rights Reserved.                *
7 *                                                                *
8 *  This source code is distributed under the terms of the        *
9 *  GNU General Public License, version 3. See the file COPYING   *
10 *  or http://www.gnu.org/licenses/gpl.txt for details            *
11 *                                                                *
12 *  If you use this code, please keep this notice intact.         *
13 *                                                                *
14 \****************************************************************/
15 
16 #include "affine.h"
17 #include "alignment.h"
18 #include "optimal.h"
19 
test_model(Affine_Model_Type type,C4_Score expected_score)20 static void test_model(Affine_Model_Type type, C4_Score expected_score){
21     register C4_Model *affine = Affine_create(type,
22                                               Alphabet_Type_PROTEIN,
23                                               Alphabet_Type_PROTEIN,
24                                               FALSE);
25 /**/
26     register C4_Score score;
27     register Alignment *alignment;
28     register gchar *name = NULL;
29     register Optimal *optimal;
30     register Alphabet *alphabet = Alphabet_create(Alphabet_Type_PROTEIN,
31                                                   FALSE);
32     register Sequence
33         *query = Sequence_create("qy", NULL,
34                      "MEEPQSDPSVEPPLSQETFSDLWKLL", 0,
35                      Sequence_Strand_UNKNOWN, alphabet),
36         *target = Sequence_create("tg", NULL,
37                      "PENNVLSPLPSQAMDDLMLSPDDIEQWFTEDPGP"
38                      "EHSCETFDIWKWCPIECDFLNVISEPNEPIPSQ", 0,
39                      Sequence_Strand_UNKNOWN, alphabet);
40     register Affine_Data *ad = Affine_Data_create(query, target, FALSE);
41       /*
42       "TVPEPIVTEPTTITEPEVPEKEEPKAEVEKTKKAKGSKPKKASKPRNPA"
43       "SHPTYEEMIKDAIVSLKEKNGSSQYAIA",
44       "VVEEQAAPETVKDEANPPAKSGKAKKETKAKKPAAPRKRSATPTHPPYF"
45       "EMIKDAIVTLKERTGSSQHAIT",
46       */
47       /* Paracelsus challenge sequences: */
48       /*
49       "MTYKLILNGKTLKGETTTEAVDAATAEKVFKQYANDNGVDGEWTYDDATKTFTVTE",
50       "MTKKAILALNTAKFLRTQAAVLAAKLEKLGAQEANDNAVDLEDTADDLYKTLLVLA",
51       */
52     Region region;
53 /**/
54     switch(type){
55         case Affine_Model_Type_GLOBAL:
56             name = "global affine";
57             break;
58         case Affine_Model_Type_BESTFIT:
59             name = "bestfit affine";
60             break;
61         case Affine_Model_Type_LOCAL:
62             name = "local affine";
63             break;
64         case Affine_Model_Type_OVERLAP:
65             name = "overlap affine";
66             break;
67         default:
68             g_error("Model Type not supported [%d]", type);
69             break;
70         }
71     optimal = Optimal_create(affine, NULL,
72                              Optimal_Type_SCORE|Optimal_Type_PATH,
73                              FALSE);
74 /**/
75     Region_init_static(&region, 0, 0, ad->ud.query->len,
76                                       ad->ud.target->len);
77     score = Optimal_find_score(optimal, &region, ad, NULL);
78     g_message("Score for [%s] [%d]", name, score);
79     g_assert(score == expected_score);
80 /**/
81     alignment = Optimal_find_path(optimal, &region, ad,
82                                   C4_IMPOSSIBLY_LOW_SCORE, NULL);
83     g_message("Alignment score is [%d]", alignment->score);
84     Alignment_display(alignment, query, target,
85             Affine_Data_get_dna_submat(ad),
86             Affine_Data_get_protein_submat(ad), NULL, stdout);
87     Alignment_display_vulgar(alignment, query, target, stdout);
88     g_assert(score == alignment->score);
89 /**/
90     C4_Model_destroy(affine);
91     Alignment_destroy(alignment);
92     Optimal_destroy(optimal);
93     Affine_Data_destroy(ad);
94     Sequence_destroy(query);
95     Sequence_destroy(target);
96     Alphabet_destroy(alphabet);
97     return;
98     }
99 
Argument_main(Argument * arg)100 int Argument_main(Argument *arg){
101     Match_ArgumentSet_create(arg);
102     Affine_ArgumentSet_create(arg);
103     Argument_process(arg, "affine.test", NULL, NULL);
104     test_model(Affine_Model_Type_GLOBAL, -151);
105     test_model(Affine_Model_Type_BESTFIT, 18);
106     test_model(Affine_Model_Type_LOCAL, 32);
107     test_model(Affine_Model_Type_OVERLAP, 18);
108     return 0;
109     }
110 
111 
112 
113