File: muttag.cpp

package info (click to toggle)
staden 2.0.0%2Bb11-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 21,556 kB
  • sloc: ansic: 240,603; tcl: 65,360; cpp: 12,854; makefile: 11,201; sh: 2,952; fortran: 2,033; perl: 63; awk: 46
file content (233 lines) | stat: -rw-r--r-- 5,231 bytes parent folder | download | duplicates (5)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
 * Copyright (c) Medical Research Council 2000. All rights reserved.
 *
 * Permission to use, copy, modify and distribute this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * this copyright and notice appears in all copies.
 *
 * This file was written as part of the Staden Package at the MRC Laboratory
 * of Molecular Biology, Hills Road, Cambridge, CB2 2QH, United Kingdom.
 *
 * MRC disclaims all warranties with regard to this software.
 *
 */


#include <locale>            // For toupper()
#include <cstring>           // For strcpy(), strlen(), ...
#include <cstdio>            // For sprintf()
#include <muttag.hpp>


//--------
// Tables
//--------

// Must have same layout as enum values in muttag.hpp
static const char* pCommentTable[] = {
"",
"A->A",
"A->C",
"A->G",
"A->T",
"A->*",
"A->?",
"C->A",
"C->C",
"C->G",
"C->T",
"C->*",
"C->?",
"G->A",
"G->C",
"G->G",
"G->T",
"G->*",
"G->?",
"T->A",
"T->C",
"T->G",
"T->T",
"T->*",
"T->?",
"*->A",
"*->C",
"*->G",
"*->T",
"*->*",
"*->?",
"?->A",
"?->C",
"?->G",
"?->T",
"?->*",
"?->?"
};



//-------------
// Constructor
//-------------

MutTag::MutTag( const char* Name, mutlib_mutation_t mt, int p, mutlib_strand_t d )
{
   assert(Name != NULL);
   assert(std::strlen(Name)<5);
   m_nType                   = mt;
   m_nStrand                 = d;
   m_nConfidence             = 0;
   std::strncpy( m_pName, Name, 4 );
   int n;
   for( n=0; n<4; n++ )
       m_pName[n] = std::toupper( m_pName[n] );
   m_pName[n]                = 0;
   m_pComment[0]             = 0;
   m_nPosition[0]            = p;
   m_nPosition[1]            = 0;
   m_nPosition[2]            = 0;
   m_nAmplitude[0]           = 0;
   m_nAmplitude[1]           = 0;
   m_nAmplitudeRatio         = 0.0;
   m_nAmplitudePercentage[0] = 0.0;
   m_nAmplitudePercentage[1] = 0.0;
   m_nWidth                  = 0.0;
   m_nAlignment              = 0.0;
   m_nSensitivity            = 0.0;
}




//-------
// Clone
//-------

void MutTag::Clone( const MutTag& rhs )
{
   // Ensures proper copy of list item pointers and contained strings
   Copy( rhs );
   m_nType                   = rhs.m_nType;
   m_nStrand                 = rhs.m_nStrand;
   m_nConfidence             = rhs.m_nConfidence;
   std::strcpy( m_pName, rhs.m_pName );
   std::strcpy( m_pComment, rhs.m_pComment );
   m_nPosition[0]            = rhs.m_nPosition[0];
   m_nPosition[1]            = rhs.m_nPosition[1];
   m_nPosition[2]            = rhs.m_nPosition[2];
   m_nAmplitude[0]           = rhs.m_nAmplitude[0];
   m_nAmplitude[1]           = rhs.m_nAmplitude[1];
   m_nAmplitudeRatio         = rhs.m_nAmplitudeRatio;
   m_nAmplitudePercentage[0] = rhs.m_nAmplitudePercentage[0];
   m_nAmplitudePercentage[1] = rhs.m_nAmplitudePercentage[1];
   m_nWidth                  = rhs.m_nWidth;
   m_nAlignment              = rhs.m_nAlignment;
   m_nSensitivity            = rhs.m_nSensitivity;
}



//------------
// Complement
//------------

void MutTag::Complement( char* s )
{
/*
   Complements any base calls in the string. ie.

   A -> T
   C -> G
   G -> C
   T -> A
*/

   if(!s) return;
   int slen = std::strlen(s);
   for( int n=0; n<slen; n++ )
   {
       switch( s[n] )
       {
          case 'A':
          case 'a': s[n] = 'T'; break;
          case 'C':
          case 'c': s[n] = 'G'; break;
          case 'G':
          case 'g': s[n] = 'C'; break;
          case 'T':
          case 't': s[n] = 'A'; break;
       }
    }
}



//---------
// Comment
//---------

const char* MutTag::Comment( bool bComplement )
{
    // Copy comment from table
    std::strcpy( m_pComment, pCommentTable[m_nType] );
    if( std::strcmp(m_pName,"HETE") == 0 )
    {
        // Remove arrow "->" for heterozygotes
        m_pComment[1] = m_pComment[3];
        m_pComment[2] = 0;
    }
    if( (m_nStrand==MUTLIB_STRAND_REVERSE) && bComplement )
        Complement( m_pComment );
    int slen = std::strlen( m_pComment );


    // Append mutation parameter measurements
    if( std::strcmp(m_pName,"MUTA") == 0 )
    {
        std::sprintf( &m_pComment[slen], " Sensitivity=%5.2f, Alignment=%4.2f, Width=%4.2f, Amplitude=%d",
                      m_nSensitivity, m_nAlignment, m_nWidth, 
                      static_cast<int>(m_nAmplitude[0]+m_nAmplitude[1]) );
    }


    // Append heterozygote parameter measurements
    else if( std::strcmp(m_pName,"HETE") == 0 )
    {
        std::sprintf( &m_pComment[slen], " Ratio=%4.2f, Alignment=%4.2f, Amplitude1=%4.2f, Amplitude2=%4.2f",
                      m_nAmplitudeRatio, m_nAlignment,
                      m_nAmplitudePercentage[0], m_nAmplitudePercentage[1] );
    }
    assert(std::strlen(m_pComment)<MAX_COMMENT);
    return m_pComment;
}



//------
// Type
//------

void MutTag::Type( int ni, int nw )
{
    m_nType = mutlib_mutation_t( MUTLIB_MUTATION_AA + (nw*6) + ni );
}



//-------------
// BaseToIndex
//-------------

int MutTag::BaseToIndex( int b )
{
    switch( b )
    {
        case 'A': case 'a': return 0;
        case 'C': case 'c': return 1;
        case 'G': case 'g': return 2;
        case 'T': case 't': return 3;
        case '*':           return 4;
        default:            return 5;
    }
}