~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to util/tables/raw_scoremat.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  $Id: raw_scoremat.c,v 1.3 2003/12/29 21:25:50 ucko Exp $
 
2
 * ===========================================================================
 
3
 *
 
4
 *                            PUBLIC DOMAIN NOTICE
 
5
 *               National Center for Biotechnology Information
 
6
 *
 
7
 *  This software/database is a "United States Government Work" under the
 
8
 *  terms of the United States Copyright Act.  It was written as part of
 
9
 *  the author's official duties as a United States Government employee and
 
10
 *  thus cannot be copyrighted.  This software/database is freely available
 
11
 *  to the public for use. The National Library of Medicine and the U.S.
 
12
 *  Government have not placed any restriction on its use or reproduction.
 
13
 *
 
14
 *  Although all reasonable efforts have been taken to ensure the accuracy
 
15
 *  and reliability of the software and data, the NLM and the U.S.
 
16
 *  Government do not and cannot warrant the performance or results that
 
17
 *  may be obtained by using this software or data. The NLM and the U.S.
 
18
 *  Government disclaim all warranties, express or implied, including
 
19
 *  warranties of performance, merchantability or fitness for any particular
 
20
 *  purpose.
 
21
 *
 
22
 *  Please cite the author in any work or product based on this material.
 
23
 *
 
24
 * ===========================================================================
 
25
 *
 
26
 * Author:  Aaron Ucko
 
27
 *
 
28
 * File Description:
 
29
 *   Protein alignment score matrices; shared between the two toolkits.
 
30
 *
 
31
 */
 
32
 
 
33
#include <util/tables/raw_scoremat.h>
 
34
 
 
35
#include <ctype.h>
 
36
#include <string.h>
 
37
 
 
38
#include "sm_blosum45.c"
 
39
#include "sm_blosum62.c"
 
40
#include "sm_blosum80.c"
 
41
#include "sm_pam30.c"
 
42
#include "sm_pam70.c"
 
43
#include "sm_pam250.c"
 
44
 
 
45
static const char kNCBIstdaa[] = "-ABCDEFGHIKLMNPQRSTVWXYZU*";
 
46
 
 
47
 
 
48
int NCBISM_GetIndex(const SNCBIPackedScoreMatrix* sm, int aa)
 
49
{
 
50
    const char *p;
 
51
 
 
52
    /* Translate to NCBIeaa */
 
53
    if (aa >= 0  &&  aa < sizeof(kNCBIstdaa)) {
 
54
        aa = kNCBIstdaa[aa];
 
55
    } else if (islower(aa)) {
 
56
        aa = toupper(aa);
 
57
    }
 
58
 
 
59
    p = strchr(sm->symbols, aa);
 
60
    return p ? p - sm->symbols : -1;
 
61
}
 
62
 
 
63
 
 
64
TNCBIScore NCBISM_GetScore(const SNCBIPackedScoreMatrix* sm,
 
65
                           int aa1, int aa2)
 
66
{
 
67
    int i1, i2;
 
68
    i1 = NCBISM_GetIndex(sm, aa1);
 
69
    i2 = NCBISM_GetIndex(sm, aa2);
 
70
    if (i1 >=0  &&  i2 >= 0) {
 
71
        return sm->scores[i1 * strlen(sm->symbols) + i2];
 
72
    } else {
 
73
        return sm->defscore;
 
74
    }
 
75
}
 
76
 
 
77
 
 
78
void NCBISM_Unpack(const SNCBIPackedScoreMatrix* psm,
 
79
                   SNCBIFullScoreMatrix* fsm)
 
80
{
 
81
    const char* sym;
 
82
    int         dim, i, j, aa1, aa2;
 
83
 
 
84
    sym = psm->symbols;
 
85
    dim = strlen(sym);
 
86
    /* fill with default */
 
87
    memset(&fsm->s, psm->defscore, NCBI_FSM_DIM * NCBI_FSM_DIM);
 
88
    for (i = 0;  i < dim;  ++i) {
 
89
        aa1 = sym[i];
 
90
        /* get core (NCBIeaa x NCBIeaa) */
 
91
        for (j = 0;  j < dim;  ++j) {
 
92
            aa2 = sym[j];
 
93
            fsm->s[aa1][aa2] = psm->scores[i * dim + j];
 
94
        }
 
95
        /* extend horizontally */
 
96
        for (aa2 = 0;  aa2 < sizeof(kNCBIstdaa);  ++aa2) {
 
97
            fsm->s[aa1][aa2] = fsm->s[aa1][(int)kNCBIstdaa[aa2]];
 
98
        }
 
99
        for (aa2 = 'a';  aa2 <= 'z';  ++aa2) {
 
100
            fsm->s[aa1][aa2] = fsm->s[aa1][toupper(aa2)];
 
101
        }
 
102
    }
 
103
    /* extend vertically */
 
104
    for (aa1 = 0;  aa1 < sizeof(kNCBIstdaa);  ++aa1) {
 
105
        memcpy(fsm->s[aa1], fsm->s[(int)kNCBIstdaa[aa1]], NCBI_FSM_DIM);
 
106
    }
 
107
    for (aa1 = 'a';  aa1 <= 'z';  ++aa1) {
 
108
        memcpy(fsm->s[aa1], fsm->s[toupper(aa1)], NCBI_FSM_DIM);
 
109
    }
 
110
}
 
111
 
 
112
 
 
113
/*
 
114
 * ===========================================================================
 
115
 * $Log: raw_scoremat.c,v $
 
116
 * Revision 1.3  2003/12/29 21:25:50  ucko
 
117
 * +PAM250
 
118
 *
 
119
 * Revision 1.2  2003/10/02 15:37:34  ivanov
 
120
 * Get rid of compilation warnings
 
121
 *
 
122
 * Revision 1.1  2003/08/21 19:48:20  ucko
 
123
 * Add tables library (shared with C) for raw score matrices, etc.
 
124
 *
 
125
 * ===========================================================================
 
126
 */