void CCmdLineBlastXML2ReportData::x_FillScoreMatrix(const char *matrix_name) { if (matrix_name == NULL) return; int matrix[kMatrixCols][kMatrixCols]; int * tmp[kMatrixCols]; const SNCBIPackedScoreMatrix *packed_matrix = 0; if (strcmp(matrix_name, "BLOSUM45") == 0) packed_matrix = &NCBISM_Blosum45; else if (strcmp(matrix_name, "BLOSUM50") == 0) packed_matrix = &NCBISM_Blosum50; else if (strcmp(matrix_name, "BLOSUM62") == 0) packed_matrix = &NCBISM_Blosum62; else if (strcmp(matrix_name, "BLOSUM80") == 0) packed_matrix = &NCBISM_Blosum80; else if (strcmp(matrix_name, "BLOSUM90") == 0) packed_matrix = &NCBISM_Blosum90; else if (strcmp(matrix_name, "PAM30") == 0) packed_matrix = &NCBISM_Pam30; else if (strcmp(matrix_name, "PAM70") == 0) packed_matrix = &NCBISM_Pam70; else if (strcmp(matrix_name, "PAM250") == 0) packed_matrix = &NCBISM_Pam250; else { string prog_name = Blast_ProgramNameFromType( m_Options->GetProgramType()); if (prog_name != "blastn" && prog_name != "megablast") { NCBI_THROW(blast::CBlastException, eInvalidArgument, "unsupported score matrix"); } } if (packed_matrix) { SNCBIFullScoreMatrix m; NCBISM_Unpack(packed_matrix, &m); for (unsigned int i = 0; i < kMatrixCols; i++) { tmp[i] = matrix[i]; for (unsigned int j = 0; j < kMatrixCols; j++) { matrix[i][j] = m.s[i][j]; } } } m_Matrix = (new CBlastFormattingMatrix(tmp, kMatrixCols, kMatrixCols)); }
void ScoreMatrix::initialize(EScoreMatrixType type) { SNCBIPackedScoreMatrix matrix; m_type = type; switch (m_type) { case eBlosum45: matrix = NCBISM_Blosum45; break; case eBlosum62: matrix = NCBISM_Blosum62; break; case eBlosum80: matrix = NCBISM_Blosum80; break; case ePam30: matrix = NCBISM_Pam30; break; case ePam70: matrix = NCBISM_Pam70; break; case ePam250: matrix = NCBISM_Pam250; break; case eInvalidMatrixType: default: m_numLetters = INVALIDSIZE; m_alphabet = NULL; return; break; } m_name = GetScoringMatrixName(type); if (type != eInvalidMatrixType) { m_alphabet = matrix.symbols; m_numLetters = strlen(m_alphabet); NCBISM_Unpack(&matrix, &m_scoreMatrix); } }
int CAlnVec::CalculateScore(const string& s1, const string& s2, bool s1_is_prot, bool s2_is_prot, int gen_code1, int gen_code2) { // check the lengths if (s1_is_prot == s2_is_prot && s1.length() != s2.length()) { NCBI_THROW(CAlnException, eInvalidRequest, "CAlnVec::CalculateScore(): " "Strings should have equal lenghts."); } else if (s1.length() * (s1_is_prot ? 1 : 3) != s1.length() * (s1_is_prot ? 1 : 3)) { NCBI_THROW(CAlnException, eInvalidRequest, "CAlnVec::CalculateScore(): " "Strings lengths do not match."); } int score = 0; const unsigned char * res1 = (unsigned char *) s1.c_str(); const unsigned char * res2 = (unsigned char *) s2.c_str(); const unsigned char * end1 = res1 + s1.length(); const unsigned char * end2 = res2 + s2.length(); static bool s_FullScoreMatrixInitialized = false; if (s1_is_prot && s2_is_prot) { if ( !s_FullScoreMatrixInitialized ) { s_FullScoreMatrixInitialized = true; NCBISM_Unpack(&NCBISM_Blosum62, &s_FullScoreMatrix); } // use BLOSUM62 matrix for ( ; res1 != end1; res1++, res2++) { _ASSERT(*res1 < NCBI_FSM_DIM); _ASSERT(*res2 < NCBI_FSM_DIM); score += s_FullScoreMatrix.s[*res1][*res2]; } } else if ( !s1_is_prot && !s2_is_prot ) { // use match score/mismatch penalty for ( ; res1 != end1; res1++, res2++) { if (*res1 == *res2) { score += 1; } else { score -= 3; } } } else { string t; if (s1_is_prot) { TranslateNAToAA(s2, t, gen_code2); for ( ; res1 != end1; res1++, res2++) { _ASSERT(*res1 < NCBI_FSM_DIM); _ASSERT(*res2 < NCBI_FSM_DIM); score += s_FullScoreMatrix.s[*res1][*res2]; } } else { TranslateNAToAA(s1, t, gen_code1); for ( ; res2 != end2; res1++, res2++) { _ASSERT(*res1 < NCBI_FSM_DIM); _ASSERT(*res2 < NCBI_FSM_DIM); score += s_FullScoreMatrix.s[*res1][*res2]; } } } return score; }