void Scale::UpdateMatrix() const { m_Matrix.resize(m_Scale.size(), m_Scale.size()); for (Matrix::size_type row = 0; row < m_Matrix.size1(); row++) { for (Matrix::size_type column = 0; column < m_Matrix.size2(); column++) { if (row == column) m_Matrix(row, column) = m_Scale(row); else m_Matrix(row, column) = 0.0f; } } }
void CDistances::ComputeMatrix(vector<CSequence>& query_data, CHitList& hitlist, SNCBIFullScoreMatrix& score_matrix, Blast_KarlinBlk& karlin_blk) { int num_queries = query_data.size(); vector<double> self_score(num_queries); // Get the self score of each sequence x_GetSelfScores(query_data, hitlist, score_matrix, self_score, karlin_blk); // All sequences start out equally far from each other m_Matrix.Resize(num_queries, num_queries); m_Matrix.Set(1.0); // Every pairwise alignment pulls the two sequences involved // in the alignment closer together. This formulation of // pairwise distances amounts to calculating the average // per-letter distance between the two sequences. See // // Clarke et al, "Inferring Genome Trees by Using a Filter // to Eliminate Phylogenetically Discordant Sequences and // a Distance Matrix Based on Mean Normalized BLASTP Scores", // Jour. Bacteriology Apr. 2002 pp 2072-2080 for (int i = 0; i < hitlist.Size(); i++) { CHit *hit = hitlist.GetHit(i); int j = hit->m_SeqIndex1; int k = hit->m_SeqIndex2; double align_score = karlin_blk.Lambda * hit->m_Score - karlin_blk.logK; _ASSERT(j < k); m_Matrix(j,k) -= 0.5 * align_score * (1.0 / self_score[j] + 1.0 / self_score[k]); } // Force distance matrix to be symmetric for (int i = 0; i < num_queries; i++) { m_Matrix(i, i) = 0.0; for (int j = 0; j < i; j++) { // clamp to zero any distances that are negative // or too small if (fabs(m_Matrix(j, i)) < 1e-6) m_Matrix(j, i) = 0; if (m_Matrix(j, i) < 0) m_Matrix(j, i) = 0; m_Matrix(i, j) = m_Matrix(j, i); } } }
float Matrix::operator()(UINT row, UINT column) const { return m_Matrix(row, column); }
float& Matrix::operator()(UINT row, UINT column) { return m_Matrix(row, column); }