+++ /dev/null
-#include "muscle.h"\r
-#include "msa.h"\r
-\r
-/***\r
-Compute Henikoff weights.\r
-Steven Henikoff and Jorja G. Henikoff (1994), Position-based sequence weights.\r
-J. Mol. Biol., 243(4):574-578.\r
-\r
-Award each different residue an equal share of the weight, and then to divide up\r
-that weight equally among the sequences sharing the same residue. So if in a\r
-position of a multiple alignment, r different residues are represented, a residue\r
-represented in only one sequence contributes a score of 1/r to that sequence, whereas a\r
-residue represented in s sequences contributes a score of 1/rs to each of the s\r
-sequences. For each sequence, the contributions from each position are summed to give\r
-a sequence weight.\r
-\r
-Here we use the variant from PSI-BLAST, which (a) treats gaps as a 21st letter,\r
-and (b) ignores columns that are perfectly conserved.\r
-\r
->>> WARNING -- I SUSPECT THIS DOESN'T WORK CORRECTLY <<<\r
-***/\r
-\r
-void MSA::CalcHenikoffWeightsColPB(unsigned uColIndex) const\r
- {\r
- const unsigned uSeqCount = GetSeqCount();\r
-\r
-// Compute letter counts in this column\r
- unsigned uLetterCount[MAX_ALPHA+1];\r
- memset(uLetterCount, 0, (MAX_ALPHA+1)*sizeof(unsigned));\r
- unsigned uLetter;\r
- for (unsigned uSeqIndex = 0; uSeqIndex < uSeqCount; ++uSeqIndex)\r
- {\r
- if (IsGap(uSeqIndex, uColIndex) || IsWildcard(uSeqIndex, uColIndex))\r
- uLetter = MAX_ALPHA;\r
- else\r
- uLetter = GetLetter(uSeqIndex, uColIndex);\r
- ++(uLetterCount[uLetter]);\r
- }\r
-\r
-// Check for special case of perfect conservation\r
- for (unsigned uLetter = 0; uLetter < MAX_ALPHA+1; ++uLetter)\r
- {\r
- unsigned uCount = uLetterCount[uLetter];\r
- if (uCount > 0)\r
- {\r
- // Perfectly conserved?\r
- if (uCount == uSeqCount)\r
- return;\r
- else\r
- // If count > 0 but less than nr. sequences, can't be conserved\r
- break;\r
- }\r
- }\r
-\r
-// Compute weight contributions\r
- for (unsigned uSeqIndex = 0; uSeqIndex < uSeqCount; ++uSeqIndex)\r
- {\r
- unsigned uLetter;\r
- if (IsGap(uSeqIndex, uColIndex) || IsWildcard(uSeqIndex, uColIndex))\r
- uLetter = MAX_ALPHA;\r
- else\r
- uLetter = GetLetter(uSeqIndex, uColIndex);\r
- const unsigned uCount = uLetterCount[uLetter];\r
- m_Weights[uSeqIndex] += (WEIGHT) (1.0/uCount);\r
- }\r
- }\r
-\r
-bool MSA::IsGapSeq(unsigned uSeqIndex) const\r
- {\r
- const unsigned uColCount = GetColCount();\r
- for (unsigned uColIndex = 0; uColIndex < uColCount; ++uColIndex)\r
- if (!IsGap(uSeqIndex, uColIndex))\r
- return false;\r
- return true;\r
- }\r
-\r
-void MSA::SetUniformWeights() const\r
- {\r
- const unsigned uSeqCount = GetSeqCount();\r
- if (0 == uSeqCount)\r
- return;\r
-\r
- const WEIGHT w = (WEIGHT) (1.0 / uSeqCount);\r
- for (unsigned uSeqIndex = 0; uSeqIndex < uSeqCount; ++uSeqIndex)\r
- m_Weights[uSeqIndex] = w;\r
- }\r
-\r
-void MSA::SetHenikoffWeightsPB() const\r
- {\r
- const unsigned uColCount = GetColCount();\r
- const unsigned uSeqCount = GetSeqCount();\r
-\r
- if (0 == uSeqCount)\r
- return;\r
- else if (1 == uSeqCount)\r
- {\r
- m_Weights[0] = 1.0;\r
- return;\r
- }\r
- else if (2 == uSeqCount)\r
- {\r
- m_Weights[0] = (WEIGHT) 0.5;\r
- m_Weights[1] = (WEIGHT) 0.5;\r
- return;\r
- }\r
-\r
- for (unsigned uSeqIndex = 0; uSeqIndex < uSeqCount; ++uSeqIndex)\r
- m_Weights[uSeqIndex] = 0.0;\r
-\r
- for (unsigned uColIndex = 0; uColIndex < uColCount; ++uColIndex)\r
- CalcHenikoffWeightsColPB(uColIndex);\r
-\r
-// Set all-gap seqs weight to 0\r
- for (unsigned uSeqIndex = 0; uSeqIndex < uSeqCount; ++uSeqIndex)\r
- if (IsGapSeq(uSeqIndex))\r
- m_Weights[uSeqIndex] = 0.0;\r
-\r
-// Check for special case of identical sequences, which will cause all\r
-// columns to be skipped becasue they're perfectly conserved.\r
- if (VectorIsZero(m_Weights, uSeqCount))\r
- VectorSet(m_Weights, uSeqCount, 1.0);\r
-\r
- Normalize(m_Weights, uSeqCount);\r
- }\r