1
/* seq2mtx - convert single sequence to pseudo IMPALA mtx file */
3
/* Copyright (C) 2000 D.T. Jones */
6
#include <QtCore/QTemporaryFile>
7
#include <QtCore/QTextStream>
15
#pragma warning(disable: 4996)
18
#include "sspred_utils.h"
20
#define MAXSEQLEN 65536
25
#define SQR(x) ((x)*(x))
26
#define MIN(x,y) (((x)<(y))?(x):(y))
27
#define MAX(x,y) (((x)>(y))?(x):(y))
29
const char *rescodes = "ARNDCQEGHILKMFPSTWYVBZX";
32
const short aamat[23][23] =
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,
39
{0, -3, -3, -3,10, -3, -4, -3, -3, -1, -1, -3, -1, -2, -3, -1, -1, -2,
41
{-1, 1, 0, 0, -3, 5, 2, -2, 0, -3, -2, 1, 0, -3, -1, 0, -1, -2,
43
{-1, 0, 0, 2, -4, 2, 5, -2, 0, -3, -3, 1, -2, -3, -1, 0, -1, -3,
45
{0, -2, 0, -1, -3, -2, -2, 6, -2, -4, -4, -2, -3, -3, -2, 0, -2, -2,
47
{-2, 0, 1, -1, -3, 0, 0, -2, 8, -3, -3, -1, -2, -1, -2, -1, -2, -2,
49
{-1, -3, -3, -3, -1, -3, -3, -4, -3, 4, 2, -3, 1, 0, -3, -2, -1, -3,
51
{-1, -2, -3, -4, -1, -2, -3, -4, -3, 2, 4, -2, 2, 0, -3, -2, -1, -2,
53
{-1, 2, 0, -1, -3, 1, 1, -2, -1, -3, -2, 5, -1, -3, -1, 0, -1, -3,
55
{-1, -1, -2, -3, -1, 0, -2, -3, -2, 1, 2, -1, 5, 0, -2, -1, -1, -1,
57
{-2, -3, -3, -3, -2, -3, -3, -3, -1, 0, 0, -3, 0, 6, -4, -2, -2, 1,
59
{-1, -2, -2, -1, -3, -1, -1, -2, -2, -3, -3, -1, -2, -4, 7, -1, -1, -4,
61
{1, -1, 1, 0, -1, 0, 0, 0, -1, -2, -2, 0, -1, -2, -1, 4, 1, -3,
63
{0, -1, 0, -1, -1, -1, -1, -2, -2, -1, -1, -1, -1, -2, -1, 1, 5, -2,
65
{-3, -3, -4, -4, -2, -2, -3, -2, -2, -3, -2, -3, -1, 1, -4, -3, -2, 11,
67
{-2, -2, -2, -3, -2, -1, -2, -3, 2, -1, -1, -2, -1, 3, -3, -2, -2, 2,
69
{0, -3, -3, -3, -1, -2, -2, -3, -3, 3, 1, -2, 1, -1, -2, -2, 0, -3,
71
{-2, -1, 3, 4, -3, 0, 1, -1, 0, -3, -4, 0, -3, -3, -2, 0, -1, -4,
73
{-1, 0, 0, 1, -3, 3, 4, -2, 0, -3, -3, 1, -1, -3, -1, 0, -1, -3,
75
{0, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, 0, 0, -2,
79
int seq2mtx(const char* seq, int seqlen, const char* outFileName)
82
const char *ncbicodes = "XAXCDEFGHIKLMNPQRSTVWXYXXX";
84
if (seqlen < 5 || seqlen >= MAXSEQLEN)
85
fail("Sequence length error!");
88
FILE* pFile = fopen( outFileName, "w" );
91
fail("open file for writing failed");
94
fprintf(pFile, "%d\n", seqlen);
96
for (i=0; i<seqlen; i++)
99
fprintf(pFile, "\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n");
101
for (i=0; i<seqlen; i++)
104
if (ncbicodes[j] != 'X')
105
fprintf(pFile, "%d ", aamat[aanum(seq[i])][aanum(ncbicodes[j])]*100);
107
fprintf(pFile, "-32768 ");
115
int seq2mtx( const char* seq, int seqlen, QTemporaryFile* tmpFile )
118
const char *ncbicodes = "XAXCDEFGHIKLMNPQRSTVWXYXXX";
120
if (seqlen < 5 || seqlen >= MAXSEQLEN)
121
fail("Sequence length error!");
123
QTextStream stream(tmpFile);
125
stream << seqlen << '\n';
127
for (i=0; i<seqlen; i++)
130
stream << "\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n";
132
for (i=0; i<seqlen; i++)
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);
140
//fprintf(pFile, "-32768 ");