| 1 | #include "muscle.h" |
|---|
| 2 | #include "msa.h" |
|---|
| 3 | #include <errno.h> |
|---|
| 4 | |
|---|
| 5 | extern float VTML_SP[32][32]; |
|---|
| 6 | extern float NUC_SP[32][32]; |
|---|
| 7 | |
|---|
| 8 | static double GetColScore(const MSA &msa, unsigned uCol) |
|---|
| 9 | { |
|---|
| 10 | const unsigned uSeqCount = msa.GetSeqCount(); |
|---|
| 11 | unsigned uPairCount = 0; |
|---|
| 12 | double dSum = 0.0; |
|---|
| 13 | for (unsigned uSeq1 = 0; uSeq1 < uSeqCount; ++uSeq1) |
|---|
| 14 | { |
|---|
| 15 | if (msa.IsGap(uSeq1, uCol)) |
|---|
| 16 | continue; |
|---|
| 17 | unsigned uLetter1 = msa.GetLetterEx(uSeq1, uCol); |
|---|
| 18 | if (uLetter1 >= g_AlphaSize) |
|---|
| 19 | continue; |
|---|
| 20 | for (unsigned uSeq2 = uSeq1 + 1; uSeq2 < uSeqCount; ++uSeq2) |
|---|
| 21 | { |
|---|
| 22 | if (msa.IsGap(uSeq2, uCol)) |
|---|
| 23 | continue; |
|---|
| 24 | unsigned uLetter2 = msa.GetLetterEx(uSeq2, uCol); |
|---|
| 25 | if (uLetter2 >= g_AlphaSize) |
|---|
| 26 | continue; |
|---|
| 27 | double Score; |
|---|
| 28 | switch (g_Alpha) |
|---|
| 29 | { |
|---|
| 30 | case ALPHA_Amino: |
|---|
| 31 | Score = VTML_SP[uLetter1][uLetter2]; |
|---|
| 32 | break; |
|---|
| 33 | case ALPHA_DNA: |
|---|
| 34 | case ALPHA_RNA: |
|---|
| 35 | Score = NUC_SP[uLetter1][uLetter2]; |
|---|
| 36 | break; |
|---|
| 37 | default: |
|---|
| 38 | Quit("GetColScore: invalid alpha=%d", g_Alpha); |
|---|
| 39 | } |
|---|
| 40 | dSum += Score; |
|---|
| 41 | ++uPairCount; |
|---|
| 42 | } |
|---|
| 43 | } |
|---|
| 44 | if (0 == uPairCount) |
|---|
| 45 | return 0; |
|---|
| 46 | return dSum / uPairCount; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | void WriteScoreFile(const MSA &msa) |
|---|
| 50 | { |
|---|
| 51 | FILE *f = fopen(g_pstrScoreFileName, "w"); |
|---|
| 52 | if (0 == f) |
|---|
| 53 | Quit("Cannot open score file '%s' errno=%d", g_pstrScoreFileName, errno); |
|---|
| 54 | |
|---|
| 55 | const unsigned uColCount = msa.GetColCount(); |
|---|
| 56 | const unsigned uSeqCount = msa.GetSeqCount(); |
|---|
| 57 | for (unsigned uCol = 0; uCol < uColCount; ++uCol) |
|---|
| 58 | { |
|---|
| 59 | double Score = GetColScore(msa, uCol); |
|---|
| 60 | fprintf(f, "%10.3f ", Score); |
|---|
| 61 | for (unsigned uSeq = 0; uSeq < uSeqCount; ++uSeq) |
|---|
| 62 | { |
|---|
| 63 | char c = msa.GetChar(uSeq, uCol); |
|---|
| 64 | fprintf(f, "%c", c); |
|---|
| 65 | } |
|---|
| 66 | fprintf(f, "\n"); |
|---|
| 67 | } |
|---|
| 68 | fclose(f); |
|---|
| 69 | } |
|---|