1 /****************************************************************\
2 *                                                                *
3 *  Protein <-> Genome comparison model                           *
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 <string.h> /* For strlen() */
17 
18 #include "protein2genome.h"
19 #include "phase.h"
20 
Protein2Genome_Data_create(Sequence * query,Sequence * target)21 Protein2Genome_Data *Protein2Genome_Data_create(
22                          Sequence *query, Sequence *target){
23     register Protein2Genome_Data *p2gd = g_new0(Protein2Genome_Data, 1);
24     g_assert(query->alphabet->type == Alphabet_Type_PROTEIN);
25     g_assert(target->alphabet->type == Alphabet_Type_DNA);
26     Protein2DNA_Data_init(&p2gd->p2dd, query, target);
27     if(!Protein2Genome_Data_get_Intron_Data(p2gd))
28         Protein2Genome_Data_get_Intron_Data(p2gd)
29                               = Intron_Data_create();
30     return p2gd;
31     }
32 
Protein2Genome_Data_destroy(Protein2Genome_Data * p2gd)33 void Protein2Genome_Data_destroy(Protein2Genome_Data *p2gd){
34     if(Protein2Genome_Data_get_Intron_Data(p2gd)){
35         Intron_Data_destroy(Protein2Genome_Data_get_Intron_Data(p2gd));
36         Protein2Genome_Data_get_Intron_Data(p2gd) = NULL;
37         }
38     Protein2DNA_Data_clear(&p2gd->p2dd);
39     g_free(p2gd);
40     return;
41     }
42 
43 /**/
44 
Protein2Genome_create(Affine_Model_Type type)45 C4_Model *Protein2Genome_create(Affine_Model_Type type){
46     register C4_Model *model = Protein2DNA_create(type);
47     register C4_Transition *match_transition;
48     register C4_Model *phase_model;
49     register Match *match;
50     register gchar *name = g_strdup_printf("protein2genome:%s",
51                                            Affine_Model_Type_get_name(type));
52     g_assert(model);
53     C4_Model_rename(model, name);
54     g_free(name);
55     C4_Model_open(model);
56     match_transition = C4_Model_select_single_transition(model,
57                                                  C4_Label_MATCH);
58     g_assert(match_transition);
59     /* Add phased intron model */
60     match = match_transition->label_data;
61     phase_model = Phase_create(NULL, match, FALSE, TRUE);
62     C4_Model_insert(model, phase_model, match_transition->input,
63                                         match_transition->output);
64     C4_Model_destroy(phase_model);
65     /**/
66     C4_Model_close(model);
67     return model;
68     }
69 
70