~ubuntu-branches/debian/jessie/ugene/jessie

« back to all changes in this revision

Viewing changes to src/plugins_3rdparty/psipred/src/seq2mtx.cpp

  • Committer: Package Import Robot
  • Author(s): Steffen Moeller
  • Date: 2011-11-02 13:29:07 UTC
  • mfrom: (1.2.1) (3.1.11 natty)
  • Revision ID: package-import@ubuntu.com-20111102132907-o34gwnt0uj5g6hen
Tags: 1.9.8+repack-1
* First release to Debian
  - added README.Debian
  - increased policy version to 3.9.2
  - added URLs for version control system
* Added debug package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* seq2mtx - convert single sequence to pseudo IMPALA mtx file */
 
2
 
 
3
/* Copyright (C) 2000 D.T. Jones */
 
4
 
 
5
#include <QtGlobal>
 
6
#include <QtCore/QTemporaryFile>
 
7
#include <QtCore/QTextStream>
 
8
#include <stdio.h>
 
9
#include <stdlib.h>
 
10
#include <ctype.h>
 
11
#include <math.h>
 
12
#include <string.h>
 
13
 
 
14
#ifdef Q_OS_WIN
 
15
#pragma warning(disable: 4996)
 
16
#endif
 
17
 
 
18
#include "sspred_utils.h"
 
19
 
 
20
#define MAXSEQLEN 65536
 
21
 
 
22
// #define FALSE 0
 
23
// #define TRUE 1
 
24
 
 
25
#define SQR(x) ((x)*(x))
 
26
#define MIN(x,y) (((x)<(y))?(x):(y))
 
27
#define MAX(x,y) (((x)>(y))?(x):(y))
 
28
 
 
29
const char *rescodes = "ARNDCQEGHILKMFPSTWYVBZX";
 
30
 
 
31
/*  BLOSUM 62 */
 
32
const short           aamat[23][23] =
 
33
{
 
34
    {4, -1, -2, -2, 0, -1, -1, 0, -2, -1, -1, -1, -1, -2, -1, 1, 0, -3, -2, 0, -2, -1, 0},
 
35
    {-1, 5, 0, -2, -3, 1, 0, -2, 0, -3, -2, 2, -1, -3, -2, -1, -1, -3, -2, -3, -1, 0, -1},
 
36
    {-2, 0, 6, 1, -3, 0, 0, 0, 1, -3, -3, 0, -2, -3, -2, 1, 0, -4, -2, -3, 3, 0, -1},
 
37
    {-2, -2, 1, 6, -3, 0, 2, -1, -1, -3, -4, -1, -3, -3, -1, 0, -1, -4,
 
38
     -3, -3, 4, 1, -1},
 
39
    {0, -3, -3, -3,10, -3, -4, -3, -3, -1, -1, -3, -1, -2, -3, -1, -1, -2,
 
40
     -2, -1, -3, -3, -2},
 
41
    {-1, 1, 0, 0, -3, 5, 2, -2, 0, -3, -2, 1, 0, -3, -1, 0, -1, -2,
 
42
     -1, -2, 0, 3, -1},
 
43
    {-1, 0, 0, 2, -4, 2, 5, -2, 0, -3, -3, 1, -2, -3, -1, 0, -1, -3,
 
44
     -2, -2, 1, 4, -1},
 
45
    {0, -2, 0, -1, -3, -2, -2, 6, -2, -4, -4, -2, -3, -3, -2, 0, -2, -2,
 
46
     -3, -3, -1, -2, -1},
 
47
    {-2, 0, 1, -1, -3, 0, 0, -2, 8, -3, -3, -1, -2, -1, -2, -1, -2, -2,
 
48
     2, -3, 0, 0, -1},
 
49
    {-1, -3, -3, -3, -1, -3, -3, -4, -3, 4, 2, -3, 1, 0, -3, -2, -1, -3,
 
50
     -1, 3, -3, -3, -1},
 
51
    {-1, -2, -3, -4, -1, -2, -3, -4, -3, 2, 4, -2, 2, 0, -3, -2, -1, -2,
 
52
     -1, 1, -4, -3, -1},
 
53
    {-1, 2, 0, -1, -3, 1, 1, -2, -1, -3, -2, 5, -1, -3, -1, 0, -1, -3,
 
54
     -2, -2, 0, 1, -1},
 
55
    {-1, -1, -2, -3, -1, 0, -2, -3, -2, 1, 2, -1, 5, 0, -2, -1, -1, -1,
 
56
     -1, 1, -3, -1, -1},
 
57
    {-2, -3, -3, -3, -2, -3, -3, -3, -1, 0, 0, -3, 0, 6, -4, -2, -2, 1,
 
58
     3, -1, -3, -3, -1},
 
59
    {-1, -2, -2, -1, -3, -1, -1, -2, -2, -3, -3, -1, -2, -4, 7, -1, -1, -4,
 
60
     -3, -2, -2, -1, -2},
 
61
    {1, -1, 1, 0, -1, 0, 0, 0, -1, -2, -2, 0, -1, -2, -1, 4, 1, -3,
 
62
     -2, -2, 0, 0, 0},
 
63
    {0, -1, 0, -1, -1, -1, -1, -2, -2, -1, -1, -1, -1, -2, -1, 1, 5, -2,
 
64
     -2, 0, -1, -1, 0},
 
65
    {-3, -3, -4, -4, -2, -2, -3, -2, -2, -3, -2, -3, -1, 1, -4, -3, -2, 11,
 
66
     2, -3, -4, -3, -2},
 
67
    {-2, -2, -2, -3, -2, -1, -2, -3, 2, -1, -1, -2, -1, 3, -3, -2, -2, 2,
 
68
     7, -1, -3, -2, -1},
 
69
    {0, -3, -3, -3, -1, -2, -2, -3, -3, 3, 1, -2, 1, -1, -2, -2, 0, -3,
 
70
     -1, 4, -3, -2, -1},
 
71
    {-2, -1, 3, 4, -3, 0, 1, -1, 0, -3, -4, 0, -3, -3, -2, 0, -1, -4,
 
72
     -3, -3, 4, 1, -1},
 
73
    {-1, 0, 0, 1, -3, 3, 4, -2, 0, -3, -3, 1, -1, -3, -1, 0, -1, -3,
 
74
     -2, -2, 1, 4, -1},
 
75
    {0, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, 0, 0, -2,
 
76
     -1, -1, -1, -1, 4}
 
77
};
 
78
 
 
79
int seq2mtx(const char* seq, int seqlen, const char* outFileName)
 
80
{
 
81
    int i, j;
 
82
    const char *ncbicodes = "XAXCDEFGHIKLMNPQRSTVWXYXXX";
 
83
    
 
84
    if (seqlen < 5 || seqlen >= MAXSEQLEN)
 
85
        fail("Sequence length error!");
 
86
    
 
87
    
 
88
    FILE* pFile = fopen( outFileName, "w" );
 
89
    if (!pFile)
 
90
    {
 
91
        fail("open file for writing failed");
 
92
    }
 
93
 
 
94
    fprintf(pFile, "%d\n", seqlen);
 
95
 
 
96
    for (i=0; i<seqlen; i++)
 
97
        putc(seq[i], pFile);
 
98
 
 
99
    fprintf(pFile, "\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n");
 
100
 
 
101
    for (i=0; i<seqlen; i++)
 
102
    {
 
103
        for (j=0; j<26; j++)
 
104
            if (ncbicodes[j] != 'X')
 
105
                fprintf(pFile, "%d  ", aamat[aanum(seq[i])][aanum(ncbicodes[j])]*100);
 
106
            else
 
107
                fprintf(pFile, "-32768  ");
 
108
        putc('\n', pFile);
 
109
    }
 
110
    fclose(pFile);
 
111
    
 
112
    return 0;
 
113
}
 
114
 
 
115
int seq2mtx( const char* seq, int seqlen, QTemporaryFile* tmpFile )
 
116
{
 
117
    int i, j;
 
118
    const char *ncbicodes = "XAXCDEFGHIKLMNPQRSTVWXYXXX";
 
119
 
 
120
    if (seqlen < 5 || seqlen >= MAXSEQLEN)
 
121
        fail("Sequence length error!");
 
122
    tmpFile->open();
 
123
    QTextStream stream(tmpFile);
 
124
    
 
125
    stream << seqlen << '\n';
 
126
    
 
127
    for (i=0; i<seqlen; i++)
 
128
        stream << seq[i];
 
129
 
 
130
    stream << "\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n";
 
131
 
 
132
    for (i=0; i<seqlen; i++)
 
133
    {
 
134
        for (j=0; j<26; j++)
 
135
            if (ncbicodes[j] != 'X')
 
136
                stream << aamat[aanum(seq[i])][aanum(ncbicodes[j])]*100 << "  ";
 
137
                //fprintf(pFile, "%d  ", aamat[aanum(seq[i])][aanum(ncbicodes[j])]*100);
 
138
            else
 
139
                stream << "-32768 ";
 
140
                //fprintf(pFile, "-32768  ");
 
141
        stream << '\n';
 
142
        //putc('\n', pFile);
 
143
    }
 
144
   
 
145
    return 0;
 
146
 
 
147
}