diff --git a/modules/seq/alg/pymod/mat.py b/modules/seq/alg/pymod/mat.py index d500be8fd614befbaa84af003fe9e0c47042e1d9..f79bf8326891d5aa9bab92724a5cf781c97cde0a 100644 --- a/modules/seq/alg/pymod/mat.py +++ b/modules/seq/alg/pymod/mat.py @@ -1,125 +1,13 @@ from ost.seq.alg import SubstWeightMatrix -def _InitMatrix(data): - """ - Initialise a new substitution weight matrix with the weights in data. data - must be a 24x24 array of ints. - """ - mat=SubstWeightMatrix() - # string of valid amino acid one letter codes - chars='ABCDEFGHIKLMNPQRSTVWXYZ' - for i, row in enumerate(data): - for j, weight in enumerate(row): - mat.SetWeight(chars[i], chars[j], weight) +def _InitMatrix(preset_enum): + mat = SubstWeightMatrix() + mat.AssignPreset(preset_enum) return mat -_RAW_BLOSUM45_DATA=( - ( 5, -1, -1, -2, -1, -2, 0, -2, -1, -1, -1, -1, -1, -1, -1, -2, 1, 0, 0, -2, 0, -2, -1), - (-1, 4, -2, 5, 1, -3, -1, 0, -3, 0, -3, -2, 4, -2, 0, -1, 0, 0, -3, -4, -1, -2, 2), - (-1, -2, 12, -3, -3, -2, -3, -3, -3, -3, -2, -2, -2, -4, -3, -3, -1, -1, -1, -5, -2, -3, -3), - (-2, 5, -3, 7, 2, -4, -1, 0, -4, 0, -3, -3, 2, -1, 0, -1, 0, -1, -3, -4, -1, -2, 1), - (-1, 1, -3, 2, 6, -3, -2, 0, -3, 1, -2, -2, 0, 0, 2, 0, 0, -1, -3, -3, -1, -2, 4), - (-2, -3, -2, -4, -3, 8, -3, -2, 0, -3, 1, 0, -2, -3, -4, -2, -2, -1, 0, 1, -1, 3, -3), - ( 0, -1, -3, -1, -2, -3, 7, -2, -4, -2, -3, -2, 0, -2, -2, -2, 0, -2, -3, -2, -1, -3, -2), - (-2, 0, -3, 0, 0, -2, -2, 10, -3, -1, -2, 0, 1, -2, 1, 0, -1, -2, -3, -3, -1, 2, 0), - (-1, -3, -3, -4, -3, 0, -4, -3, 5, -3, 2, 2, -2, -2, -2, -3, -2, -1, 3, -2, -1, 0, -3), - (-1, 0, -3, 0, 1, -3, -2, -1, -3, 5, -3, -1, 0, -1, 1, 3, -1, -1, -2, -2, -1, -1, 1), - (-1, -3, -2, -3, -2, 1, -3, -2, 2, -3, 5, 2, -3, -3, -2, -2, -3, -1, 1, -2, -1, 0, -2), - (-1, -2, -2, -3, -2, 0, -2, 0, 2, -1, 2, 6, -2, -2, 0, -1, -2, -1, 1, -2, -1, 0, -1), - (-1, 4, -2, 2, 0, -2, 0, 1, -2, 0, -3, -2, 6, -2, 0, 0, 1, 0, -3, -4, -1, -2, 0), - (-1, -2, -4, -1, 0, -3, -2, -2, -2, -1, -3, -2, -2, 9, -1, -2, -1, -1, -3, -3, -1, -3, -1), - (-1, 0, -3, 0, 2, -4, -2, 1, -2, 1, -2, 0, 0, -1, 6, 1, 0, -1, -3, -2, -1, -1, 4), - (-2, -1, -3, -1, 0, -2, -2, 0, -3, 3, -2, -1, 0, -2, 1, 7, -1, -1, -2, -2, -1, -1, 0), - ( 1, 0, -1, 0, 0, -2, 0, -1, -2, -1, -3, -2, 1, -1, 0, -1, 4, 2, -1, -4, 0, -2, 0), - ( 0, 0, -1, -1, -1, -1, -2, -2, -1, -1, -1, -1, 0, -1, -1, -1, 2, 5, 0, -3, 0, -1, -1), - ( 0, -3, -1, -3, -3, 0, -3, -3, 3, -2, 1, 1, -3, -3, -3, -2, -1, 0, 5, -3, -1, -1, -3), - (-2, -4, -5, -4, -3, 1, -2, -3, -2, -2, -2, -2, -4, -3, -2, -2, -4, -3, -3, 15, -2, 3, -2), - ( 0, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, -2, -1, -1, -1), - (-2, -2, -3, -2, -2, 3, -3, 2, 0, -1, 0, 0, -2, -3, -1, -1, -2, -1, -1, 3, -1, 8, -2), - (-1, 2, -3, 1, 4, -3, -2, 0, -3, 1, -2, -1, 0, -1, 4, 0, 0, -1, -3, -2, -1, -2, 4), -) - -_RAW_BLOSUM62_DATA=( - ( 4, -2, 0, -2, -1, -2, 0, -2, -1, -1, -1, -1, -2, -1, -1, -1, 1, 0, 0, -3, 0, -2, -1), - (-2, 4, -3, 4, 1, -3, -1, 0, -3, 0, -4, -3, 3, -2, 0, -1, 0, -1, -3, -4, -1, -3, 1), - ( 0, -3, 9, -3, -4, -2, -3, -3, -1, -3, -1, -1, -3, -3, -3, -3, -1, -1, -1, -2, -2, -2, -3), - (-2, 4, -3, 6, 2, -3, -1, -1, -3, -1, -4, -3, 1, -1, 0, -2, 0, -1, -3, -4, -1, -3, 1), - (-1, 1, -4, 2, 5, -3, -2, 0, -3, 1, -3, -2, 0, -1, 2, 0, 0, -1, -2, -3, -1, -2, 4), - (-2, -3, -2, -3, -3, 6, -3, -1, 0, -3, 0, 0, -3, -4, -3, -3, -2, -2, -1, 1, -1, 3, -3), - ( 0, -1, -3, -1, -2, -3, 6, -2, -4, -2, -4, -3, 0, -2, -2, -2, 0, -2, -3, -2, -1, -3, -2), - (-2, 0, -3, -1, 0, -1, -2, 8, -3, -1, -3, -2, 1, -2, 0, 0, -1, -2, -3, -2, -1, 2, 0), - (-1, -3, -1, -3, -3, 0, -4, -3, 4, -3, 2, 1, -3, -3, -3, -3, -2, -1, 3, -3, -1, -1, -3), - (-1, 0, -3, -1, 1, -3, -2, -1, -3, 5, -2, -1, 0, -1, 1, 2, 0, -1, -2, -3, -1, -2, 1), - (-1, -4, -1, -4, -3, 0, -4, -3, 2, -2, 4, 2, -3, -3, -2, -2, -2, -1, 1, -2, -1, -1, -3), - (-1, -3, -1, -3, -2, 0, -3, -2, 1, -1, 2, 5, -2, -2, 0, -1, -1, -1, 1, -1, -1, -1, -1), - (-2, 3, -3, 1, 0, -3, 0, 1, -3, 0, -3, -2, 6, -2, 0, 0, 1, 0, -3, -4, -1, -2, 0), - (-1, -2, -3, -1, -1, -4, -2, -2, -3, -1, -3, -2, -2, 7, -1, -2, -1, -1, -2, -4, -2, -3, -1), - (-1, 0, -3, 0, 2, -3, -2, 0, -3, 1, -2, 0, 0, -1, 5, 1, 0, -1, -2, -2, -1, -1, 3), - (-1, -1, -3, -2, 0, -3, -2, 0, -3, 2, -2, -1, 0, -2, 1, 5, -1, -1, -3, -3, -1, -2, 0), - ( 1, 0, -1, 0, 0, -2, 0, -1, -2, 0, -2, -1, 1, -1, 0, -1, 4, 1, -2, -3, 0, -2, 0), - ( 0, -1, -1, -1, -1, -2, -2, -2, -1, -1, -1, -1, 0, -1, -1, -1, 1, 5, 0, -2, 0, -2, -1), - ( 0, -3, -1, -3, -2, -1, -3, -3, 3, -2, 1, 1, -3, -2, -2, -3, -2, 0, 4, -3, -1, -1, -2), - (-3, -4, -2, -4, -3, 1, -2, -2, -3, -3, -2, -1, -4, -4, -2, -3, -3, -2, -3, 11, -2, 2, -3), - ( 0, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, 0, 0, -1, -2, -1, -1, -1), - (-2, -3, -2, -3, -2, 3, -3, 2, -1, -2, -1, -1, -2, -3, -1, -2, -2, -2, -1, 2, -1, 7, -2), - (-1, 1, -3, 1, 4, -3, -2, 0, -3, 1, -3, -1, 0, -1, 3, 0, 0, -1, -2, -3, -1, -2, 4), -) +BLOSUM45 = _InitMatrix(SubstWeightMatrix.Preset.BLOSUM45) +BLOSUM62 = _InitMatrix(SubstWeightMatrix.Preset.BLOSUM62) +BLOSUM80 = _InitMatrix(SubstWeightMatrix.Preset.BLOSUM80) +BLOSUM100 = _InitMatrix(SubstWeightMatrix.Preset.BLOSUM100) -_RAW_BLOSUM80_DATA=( - ( 7, -3, -1, -3, -2, -4, 0, -3, -3, -1, -3, -2, -3, -1, -2, -3, 2, 0, -1, -5, -1, -4, -2), - (-3, 6, -6, 6, 1, -6, -2, -1, -6, -1, -7, -5, 5, -4, -1, -2, 0, -1, -6, -8, -3, -5, 0), - (-1, -6, 13, -7, -7, -4, -6, -7, -2, -6, -3, -3, -5, -6, -5, -6, -2, -2, -2, -5, -4, -5, -7), - (-3, 6, -7, 10, 2, -6, -3, -2, -7, -2, -7, -6, 2, -3, -1, -3, -1, -2, -6, -8, -3, -6, 1), - (-2, 1, -7, 2, 8, -6, -4, 0, -6, 1, -6, -4, -1, -2, 3, -1, -1, -2, -4, -6, -2, -5, 6), - (-4, -6, -4, -6, -6, 10, -6, -2, -1, -5, 0, 0, -6, -6, -5, -5, -4, -4, -2, 0, -3, 4, -6), - ( 0, -2, -6, -3, -4, -6, 9, -4, -7, -3, -7, -5, -1, -5, -4, -4, -1, -3, -6, -6, -3, -6, -4), - (-3, -1, -7, -2, 0, -2, -4, 12, -6, -1, -5, -4, 1, -4, 1, 0, -2, -3, -5, -4, -2, 3, 0), - (-3, -6, -2, -7, -6, -1, -7, -6, 7, -5, 2, 2, -6, -5, -5, -5, -4, -2, 4, -5, -2, -3, -6), - (-1, -1, -6, -2, 1, -5, -3, -1, -5, 8, -4, -3, 0, -2, 2, 3, -1, -1, -4, -6, -2, -4, 1), - (-3, -7, -3, -7, -6, 0, -7, -5, 2, -4, 6, 3, -6, -5, -4, -4, -4, -3, 1, -4, -2, -2, -5), - (-2, -5, -3, -6, -4, 0, -5, -4, 2, -3, 3, 9, -4, -4, -1, -3, -3, -1, 1, -3, -2, -3, -3), - (-3, 5, -5, 2, -1, -6, -1, 1, -6, 0, -6, -4, 9, -4, 0, -1, 1, 0, -5, -7, -2, -4, -1), - (-1, -4, -6, -3, -2, -6, -5, -4, -5, -2, -5, -4, -4, 12, -3, -3, -2, -3, -4, -7, -3, -6, -2), - (-2, -1, -5, -1, 3, -5, -4, 1, -5, 2, -4, -1, 0, -3, 9, 1, -1, -1, -4, -4, -2, -3, 5), - (-3, -2, -6, -3, -1, -5, -4, 0, -5, 3, -4, -3, -1, -3, 1, 9, -2, -2, -4, -5, -2, -4, 0), - ( 2, 0, -2, -1, -1, -4, -1, -2, -4, -1, -4, -3, 1, -2, -1, -2, 7, 2, -3, -6, -1, -3, -1), - ( 0, -1, -2, -2, -2, -4, -3, -3, -2, -1, -3, -1, 0, -3, -1, -2, 2, 8, 0, -5, -1, -3, -2), - (-1, -6, -2, -6, -4, -2, -6, -5, 4, -4, 1, 1, -5, -4, -4, -4, -3, 0, 7, -5, -2, -3, -4), - (-5, -8, -5, -8, -6, 0, -6, -4, -5, -6, -4, -3, -7, -7, -4, -5, -6, -5, -5, 16, -5, 3, -5), - (-1, -3, -4, -3, -2, -3, -3, -2, -2, -2, -2, -2, -2, -3, -2, -2, -1, -1, -2, -5, -2, -3, -1), - (-4, -5, -5, -6, -5, 4, -6, 3, -3, -4, -2, -3, -4, -6, -3, -4, -3, -3, -3, 3, -3, 11, -4), - (-2, 0, -7, 1, 6, -6, -4, 0, -6, 1, -5, -3, -1, -2, 5, 0, -1, -2, -4, -5, -1, -4, 6), -) - -_RAW_BLOSUM100_DATA=( - ( 8, -4, -2, -5, -3, -5, -1, -4, -4, -2, -4, -3, -4, -2, -2, -3, 1, -1, -2, -6, -2, -5, -2), - (-4, 6, -7, 6, 0, -7, -3, -2, -8, -2, -8, -7, 5, -5, -2, -4, -1, -2, -7, -9, -4, -6, 0), - (-2, -7, 14, -8, -9, -4, -7, -8, -3, -8, -5, -4, -5, -8, -7, -8, -3, -3, -3, -7, -5, -6, -8), - (-5, 6, -8, 10, 2, -8, -4, -3, -8, -3, -8, -8, 1, -5, -2, -5, -2, -4, -8,-10, -4, -7, 0), - (-3, 0, -9, 2, 10, -8, -6, -2, -7, 0, -7, -5, -2, -4, 2, -2, -2, -3, -5, -8, -3, -7, 7), - (-5, -7, -4, -8, -8, 11, -8, -4, -2, -6, 0, -1, -7, -7, -6, -6, -5, -5, -3, 0, -4, 4, -7), - (-1, -3, -7, -4, -6, -8, 9, -6, -9, -5, -8, -7, -2, -6, -5, -6, -2, -5, -8, -7, -4, -8, -5), - (-4, -2, -8, -3, -2, -4, -6, 13, -7, -3, -6, -5, 0, -5, 1, -1, -3, -4, -7, -5, -4, 1, -1), - (-4, -8, -3, -8, -7, -2, -9, -7, 8, -6, 2, 1, -7, -7, -6, -7, -5, -3, 4, -6, -3, -4, -7), - (-2, -2, -8, -3, 0, -6, -5, -3, -6, 10, -6, -4, -1, -3, 2, 3, -2, -3, -5, -8, -3, -5, 0), - (-4, -8, -5, -8, -7, 0, -8, -6, 2, -6, 8, 3, -7, -7, -5, -6, -6, -4, 0, -5, -3, -4, -6), - (-3, -7, -4, -8, -5, -1, -7, -5, 1, -4, 3, 12, -5, -5, -2, -4, -4, -2, 0, -4, -3, -5, -4), - (-4, 5, -5, 1, -2, -7, -2, 0, -7, -1, -7, -5, 11, -5, -1, -2, 0, -1, -7, -8, -3, -5, -2), - (-2, -5, -8, -5, -4, -7, -6, -5, -7, -3, -7, -5, -5, 12, -4, -5, -3, -4, -6, -8, -4, -7, -4), - (-2, -2, -7, -2, 2, -6, -5, 1, -6, 2, -5, -2, -1, -4, 11, 0, -2, -3, -5, -5, -2, -4, 5), - (-3, -4, -8, -5, -2, -6, -6, -1, -7, 3, -6, -4, -2, -5, 0, 10, -3, -3, -6, -7, -3, -5, -1), - ( 1, -1, -3, -2, -2, -5, -2, -3, -5, -2, -6, -4, 0, -3, -2, -3, 9, 2, -4, -7, -2, -5, -2), - (-1, -2, -3, -4, -3, -5, -5, -4, -3, -3, -4, -2, -1, -4, -3, -3, 2, 9, -1, -7, -2, -5, -3), - (-2, -7, -3, -8, -5, -3, -8, -7, 4, -5, 0, 0, -7, -6, -5, -6, -4, -1, 8, -5, -3, -5, -5), - (-6, -9, -7, 10, -8, 0, -7, -5, -6, -8, -5, -4, -8, -8, -5, -7, -7, -7, -5, 17, -6, 2, -7), - (-2, -4, -5, -4, -3, -4, -4, -4, -3, -3, -3, -3, -3, -4, -2, -3, -2, -2, -3, -6, -3, -4, -2), - (-5, -6, -6, -7, -7, 4, -8, 1, -4, -5, -4, -5, -5, -7, -4, -5, -5, -5, -5, 2, -4, 12, -6), - (-2, 0, -8, 0, 7, -7, -5, -1, -7, 0, -6, -4, -2, -4, 5, -1, -2, -3, -5, -7, -2, -6, 6), -) - -BLOSUM45=_InitMatrix(_RAW_BLOSUM45_DATA) -BLOSUM62=_InitMatrix(_RAW_BLOSUM62_DATA) -BLOSUM80=_InitMatrix(_RAW_BLOSUM80_DATA) -BLOSUM100=_InitMatrix(_RAW_BLOSUM100_DATA) - -__all__=['BLOSUM45','BLOSUM62','BLOSUM80','BLOSUM100'] \ No newline at end of file +__all__=['BLOSUM45','BLOSUM62','BLOSUM80','BLOSUM100'] diff --git a/modules/seq/alg/pymod/wrap_seq_alg.cc b/modules/seq/alg/pymod/wrap_seq_alg.cc index 37d1609b771b0ad07ff93e1cd5c849243a2525bc..46b2123845e72545477e5d6daa3b4111c1256102 100644 --- a/modules/seq/alg/pymod/wrap_seq_alg.cc +++ b/modules/seq/alg/pymod/wrap_seq_alg.cc @@ -58,13 +58,6 @@ BOOST_PYTHON_MODULE(_ost_seq_alg) .def("GetInsertions", &InsDel::GetInsertions) ; - class_<SubstWeightMatrix, SubstWeightMatrixPtr>("SubstWeightMatrix", init<>()) - .def("GetWeight", &SubstWeightMatrix::GetWeight) - .def("SetWeight", &SubstWeightMatrix::SetWeight) - .def("GetMinWeight", &SubstWeightMatrix::GetMinWeight) - .def("GetMaxWeight", &SubstWeightMatrix::GetMaxWeight) - ; - def("MergePairwiseAlignments", &MergePairwiseAlignments); def("Conservation", &Conservation, (arg("assign")=true, arg("prop_name")="cons", arg("ignore_gap")=false)); def("LocalAlign", &LocalAlign, (arg("seq1"), arg("seq2"),arg("subst_weight"), @@ -75,4 +68,20 @@ BOOST_PYTHON_MODULE(_ost_seq_alg) arg("gap_open")=-5, arg("gap_ext")=-2)); def("ShannonEntropy", &ShannonEntropy, (arg("aln"), arg("ignore_gaps")=true)); + + scope mat_scope = class_<SubstWeightMatrix, SubstWeightMatrixPtr>("SubstWeightMatrix", init<>()) + .def("GetWeight", &SubstWeightMatrix::GetWeight) + .def("SetWeight", &SubstWeightMatrix::SetWeight) + .def("GetMinWeight", &SubstWeightMatrix::GetMinWeight) + .def("GetMaxWeight", &SubstWeightMatrix::GetMaxWeight) + .def("AssignPreset", &SubstWeightMatrix::AssignPreset) + ; + + enum_<SubstWeightMatrix::Preset>("Preset") + .value("BLOSUM45", SubstWeightMatrix::BLOSUM45) + .value("BLOSUM62", SubstWeightMatrix::BLOSUM62) + .value("BLOSUM80", SubstWeightMatrix::BLOSUM80) + .value("BLOSUM100", SubstWeightMatrix::BLOSUM100) + ; + } diff --git a/modules/seq/alg/src/CMakeLists.txt b/modules/seq/alg/src/CMakeLists.txt index 2124aa283530a09d78ac9bf0f9fe1b436527f023..ecce32a40214a08893720e58223555be66d2611c 100644 --- a/modules/seq/alg/src/CMakeLists.txt +++ b/modules/seq/alg/src/CMakeLists.txt @@ -23,12 +23,9 @@ sequence_identity.cc sequence_similarity.cc ins_del.cc conservation.cc +subst_weight_matrix.cc ) -if (ENABLE_INFO) - list (APPEND OST_SEQ_ALG_SOURCES subst_weight_matrix.cc) -endif() - module(NAME seq_alg HEADER_OUTPUT_DIR ost/seq/alg SOURCES ${OST_SEQ_ALG_SOURCES} HEADERS ${OST_SEQ_ALG_HEADERS} DEPENDS_ON ost_seq) diff --git a/modules/seq/alg/src/subst_weight_matrix.cc b/modules/seq/alg/src/subst_weight_matrix.cc index 85851ce2c6689a99b1a311f615019b35a0296c76..d8102aa230cf7e4acb738f716e823e8ebb4ab884 100644 --- a/modules/seq/alg/src/subst_weight_matrix.cc +++ b/modules/seq/alg/src/subst_weight_matrix.cc @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // This file is part of the OpenStructure project <www.openstructure.org> // -// Copyright (C) 2008-2011 by the OpenStructure authors +// Copyright (C) 2008-2015 by the OpenStructure authors // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License as published by the Free @@ -16,38 +16,155 @@ // along with this library; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //------------------------------------------------------------------------------ -#include <ost/info/info.hh> + #include "subst_weight_matrix.hh" +#include <iostream> -namespace ost { namespace seq { namespace alg { +namespace{ -SubstWeightMatrixPtr SubstWeightMatrixFromInfo(const info::InfoGroup& group) -{ - SubstWeightMatrixPtr m(new SubstWeightMatrix); - info::InfoItemList weights=group.GetItems("Weight"); - for (info::InfoItemList::iterator i=weights.begin(), - e=weights.end(); i!=e; ++i) { - info::InfoItem item=*i; - String from=item.GetAttribute("From"); - String to=item.GetAttribute("To"); - m->SetWeight(from[0], to[0], item.AsInt()); +short RAW_BLOSUM45_DATA[23][23]={ + { 5, -1, -1, -2, -1, -2, 0, -2, -1, -1, -1, -1, -1, -1, -1, -2, 1, 0, 0, -2, 0, -2, -1}, + {-1, 4, -2, 5, 1, -3, -1, 0, -3, 0, -3, -2, 4, -2, 0, -1, 0, 0, -3, -4, -1, -2, 2}, + {-1, -2, 12, -3, -3, -2, -3, -3, -3, -3, -2, -2, -2, -4, -3, -3, -1, -1, -1, -5, -2, -3, -3}, + {-2, 5, -3, 7, 2, -4, -1, 0, -4, 0, -3, -3, 2, -1, 0, -1, 0, -1, -3, -4, -1, -2, 1}, + {-1, 1, -3, 2, 6, -3, -2, 0, -3, 1, -2, -2, 0, 0, 2, 0, 0, -1, -3, -3, -1, -2, 4}, + {-2, -3, -2, -4, -3, 8, -3, -2, 0, -3, 1, 0, -2, -3, -4, -2, -2, -1, 0, 1, -1, 3, -3}, + { 0, -1, -3, -1, -2, -3, 7, -2, -4, -2, -3, -2, 0, -2, -2, -2, 0, -2, -3, -2, -1, -3, -2}, + {-2, 0, -3, 0, 0, -2, -2, 10, -3, -1, -2, 0, 1, -2, 1, 0, -1, -2, -3, -3, -1, 2, 0}, + {-1, -3, -3, -4, -3, 0, -4, -3, 5, -3, 2, 2, -2, -2, -2, -3, -2, -1, 3, -2, -1, 0, -3}, + {-1, 0, -3, 0, 1, -3, -2, -1, -3, 5, -3, -1, 0, -1, 1, 3, -1, -1, -2, -2, -1, -1, 1}, + {-1, -3, -2, -3, -2, 1, -3, -2, 2, -3, 5, 2, -3, -3, -2, -2, -3, -1, 1, -2, -1, 0, -2}, + {-1, -2, -2, -3, -2, 0, -2, 0, 2, -1, 2, 6, -2, -2, 0, -1, -2, -1, 1, -2, -1, 0, -1}, + {-1, 4, -2, 2, 0, -2, 0, 1, -2, 0, -3, -2, 6, -2, 0, 0, 1, 0, -3, -4, -1, -2, 0}, + {-1, -2, -4, -1, 0, -3, -2, -2, -2, -1, -3, -2, -2, 9, -1, -2, -1, -1, -3, -3, -1, -3, -1}, + {-1, 0, -3, 0, 2, -4, -2, 1, -2, 1, -2, 0, 0, -1, 6, 1, 0, -1, -3, -2, -1, -1, 4}, + {-2, -1, -3, -1, 0, -2, -2, 0, -3, 3, -2, -1, 0, -2, 1, 7, -1, -1, -2, -2, -1, -1, 0}, + { 1, 0, -1, 0, 0, -2, 0, -1, -2, -1, -3, -2, 1, -1, 0, -1, 4, 2, -1, -4, 0, -2, 0}, + { 0, 0, -1, -1, -1, -1, -2, -2, -1, -1, -1, -1, 0, -1, -1, -1, 2, 5, 0, -3, 0, -1, -1}, + { 0, -3, -1, -3, -3, 0, -3, -3, 3, -2, 1, 1, -3, -3, -3, -2, -1, 0, 5, -3, -1, -1, -3}, + {-2, -4, -5, -4, -3, 1, -2, -3, -2, -2, -2, -2, -4, -3, -2, -2, -4, -3, -3, 15, -2, 3, -2}, + { 0, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, -2, -1, -1, -1}, + {-2, -2, -3, -2, -2, 3, -3, 2, 0, -1, 0, 0, -2, -3, -1, -1, -2, -1, -1, 3, -1, 8, -2}, + {-1, 2, -3, 1, 4, -3, -2, 0, -3, 1, -2, -1, 0, -1, 4, 0, 0, -1, -3, -2, -1, -2, 4}, +}; + +short RAW_BLOSUM62_DATA[23][23]={ + { 4, -2, 0, -2, -1, -2, 0, -2, -1, -1, -1, -1, -2, -1, -1, -1, 1, 0, 0, -3, 0, -2, -1}, + {-2, 4, -3, 4, 1, -3, -1, 0, -3, 0, -4, -3, 3, -2, 0, -1, 0, -1, -3, -4, -1, -3, 1}, + { 0, -3, 9, -3, -4, -2, -3, -3, -1, -3, -1, -1, -3, -3, -3, -3, -1, -1, -1, -2, -2, -2, -3}, + {-2, 4, -3, 6, 2, -3, -1, -1, -3, -1, -4, -3, 1, -1, 0, -2, 0, -1, -3, -4, -1, -3, 1}, + {-1, 1, -4, 2, 5, -3, -2, 0, -3, 1, -3, -2, 0, -1, 2, 0, 0, -1, -2, -3, -1, -2, 4}, + {-2, -3, -2, -3, -3, 6, -3, -1, 0, -3, 0, 0, -3, -4, -3, -3, -2, -2, -1, 1, -1, 3, -3}, + { 0, -1, -3, -1, -2, -3, 6, -2, -4, -2, -4, -3, 0, -2, -2, -2, 0, -2, -3, -2, -1, -3, -2}, + {-2, 0, -3, -1, 0, -1, -2, 8, -3, -1, -3, -2, 1, -2, 0, 0, -1, -2, -3, -2, -1, 2, 0}, + {-1, -3, -1, -3, -3, 0, -4, -3, 4, -3, 2, 1, -3, -3, -3, -3, -2, -1, 3, -3, -1, -1, -3}, + {-1, 0, -3, -1, 1, -3, -2, -1, -3, 5, -2, -1, 0, -1, 1, 2, 0, -1, -2, -3, -1, -2, 1}, + {-1, -4, -1, -4, -3, 0, -4, -3, 2, -2, 4, 2, -3, -3, -2, -2, -2, -1, 1, -2, -1, -1, -3}, + {-1, -3, -1, -3, -2, 0, -3, -2, 1, -1, 2, 5, -2, -2, 0, -1, -1, -1, 1, -1, -1, -1, -1}, + {-2, 3, -3, 1, 0, -3, 0, 1, -3, 0, -3, -2, 6, -2, 0, 0, 1, 0, -3, -4, -1, -2, 0}, + {-1, -2, -3, -1, -1, -4, -2, -2, -3, -1, -3, -2, -2, 7, -1, -2, -1, -1, -2, -4, -2, -3, -1}, + {-1, 0, -3, 0, 2, -3, -2, 0, -3, 1, -2, 0, 0, -1, 5, 1, 0, -1, -2, -2, -1, -1, 3}, + {-1, -1, -3, -2, 0, -3, -2, 0, -3, 2, -2, -1, 0, -2, 1, 5, -1, -1, -3, -3, -1, -2, 0}, + { 1, 0, -1, 0, 0, -2, 0, -1, -2, 0, -2, -1, 1, -1, 0, -1, 4, 1, -2, -3, 0, -2, 0}, + { 0, -1, -1, -1, -1, -2, -2, -2, -1, -1, -1, -1, 0, -1, -1, -1, 1, 5, 0, -2, 0, -2, -1}, + { 0, -3, -1, -3, -2, -1, -3, -3, 3, -2, 1, 1, -3, -2, -2, -3, -2, 0, 4, -3, -1, -1, -2}, + {-3, -4, -2, -4, -3, 1, -2, -2, -3, -3, -2, -1, -4, -4, -2, -3, -3, -2, -3, 11, -2, 2, -3}, + { 0, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, 0, 0, -1, -2, -1, -1, -1}, + {-2, -3, -2, -3, -2, 3, -3, 2, -1, -2, -1, -1, -2, -3, -1, -2, -2, -2, -1, 2, -1, 7, -2}, + {-1, 1, -3, 1, 4, -3, -2, 0, -3, 1, -3, -1, 0, -1, 3, 0, 0, -1, -2, -3, -1, -2, 4}, +}; + +short RAW_BLOSUM80_DATA[23][23]={ + { 7, -3, -1, -3, -2, -4, 0, -3, -3, -1, -3, -2, -3, -1, -2, -3, 2, 0, -1, -5, -1, -4, -2}, + {-3, 6, -6, 6, 1, -6, -2, -1, -6, -1, -7, -5, 5, -4, -1, -2, 0, -1, -6, -8, -3, -5, 0}, + {-1, -6, 13, -7, -7, -4, -6, -7, -2, -6, -3, -3, -5, -6, -5, -6, -2, -2, -2, -5, -4, -5, -7}, + {-3, 6, -7, 10, 2, -6, -3, -2, -7, -2, -7, -6, 2, -3, -1, -3, -1, -2, -6, -8, -3, -6, 1}, + {-2, 1, -7, 2, 8, -6, -4, 0, -6, 1, -6, -4, -1, -2, 3, -1, -1, -2, -4, -6, -2, -5, 6}, + {-4, -6, -4, -6, -6, 10, -6, -2, -1, -5, 0, 0, -6, -6, -5, -5, -4, -4, -2, 0, -3, 4, -6}, + { 0, -2, -6, -3, -4, -6, 9, -4, -7, -3, -7, -5, -1, -5, -4, -4, -1, -3, -6, -6, -3, -6, -4}, + {-3, -1, -7, -2, 0, -2, -4, 12, -6, -1, -5, -4, 1, -4, 1, 0, -2, -3, -5, -4, -2, 3, 0}, + {-3, -6, -2, -7, -6, -1, -7, -6, 7, -5, 2, 2, -6, -5, -5, -5, -4, -2, 4, -5, -2, -3, -6}, + {-1, -1, -6, -2, 1, -5, -3, -1, -5, 8, -4, -3, 0, -2, 2, 3, -1, -1, -4, -6, -2, -4, 1}, + {-3, -7, -3, -7, -6, 0, -7, -5, 2, -4, 6, 3, -6, -5, -4, -4, -4, -3, 1, -4, -2, -2, -5}, + {-2, -5, -3, -6, -4, 0, -5, -4, 2, -3, 3, 9, -4, -4, -1, -3, -3, -1, 1, -3, -2, -3, -3}, + {-3, 5, -5, 2, -1, -6, -1, 1, -6, 0, -6, -4, 9, -4, 0, -1, 1, 0, -5, -7, -2, -4, -1}, + {-1, -4, -6, -3, -2, -6, -5, -4, -5, -2, -5, -4, -4, 12, -3, -3, -2, -3, -4, -7, -3, -6, -2}, + {-2, -1, -5, -1, 3, -5, -4, 1, -5, 2, -4, -1, 0, -3, 9, 1, -1, -1, -4, -4, -2, -3, 5}, + {-3, -2, -6, -3, -1, -5, -4, 0, -5, 3, -4, -3, -1, -3, 1, 9, -2, -2, -4, -5, -2, -4, 0}, + { 2, 0, -2, -1, -1, -4, -1, -2, -4, -1, -4, -3, 1, -2, -1, -2, 7, 2, -3, -6, -1, -3, -1}, + { 0, -1, -2, -2, -2, -4, -3, -3, -2, -1, -3, -1, 0, -3, -1, -2, 2, 8, 0, -5, -1, -3, -2}, + {-1, -6, -2, -6, -4, -2, -6, -5, 4, -4, 1, 1, -5, -4, -4, -4, -3, 0, 7, -5, -2, -3, -4}, + {-5, -8, -5, -8, -6, 0, -6, -4, -5, -6, -4, -3, -7, -7, -4, -5, -6, -5, -5, 16, -5, 3, -5}, + {-1, -3, -4, -3, -2, -3, -3, -2, -2, -2, -2, -2, -2, -3, -2, -2, -1, -1, -2, -5, -2, -3, -1}, + {-4, -5, -5, -6, -5, 4, -6, 3, -3, -4, -2, -3, -4, -6, -3, -4, -3, -3, -3, 3, -3, 11, -4}, + {-2, 0, -7, 1, 6, -6, -4, 0, -6, 1, -5, -3, -1, -2, 5, 0, -1, -2, -4, -5, -1, -4, 6}, +}; + +short RAW_BLOSUM100_DATA[23][23]={ + { 8, -4, -2, -5, -3, -5, -1, -4, -4, -2, -4, -3, -4, -2, -2, -3, 1, -1, -2, -6, -2, -5, -2}, + {-4, 6, -7, 6, 0, -7, -3, -2, -8, -2, -8, -7, 5, -5, -2, -4, -1, -2, -7, -9, -4, -6, 0}, + {-2, -7, 14, -8, -9, -4, -7, -8, -3, -8, -5, -4, -5, -8, -7, -8, -3, -3, -3, -7, -5, -6, -8}, + {-5, 6, -8, 10, 2, -8, -4, -3, -8, -3, -8, -8, 1, -5, -2, -5, -2, -4, -8,-10, -4, -7, 0}, + {-3, 0, -9, 2, 10, -8, -6, -2, -7, 0, -7, -5, -2, -4, 2, -2, -2, -3, -5, -8, -3, -7, 7}, + {-5, -7, -4, -8, -8, 11, -8, -4, -2, -6, 0, -1, -7, -7, -6, -6, -5, -5, -3, 0, -4, 4, -7}, + {-1, -3, -7, -4, -6, -8, 9, -6, -9, -5, -8, -7, -2, -6, -5, -6, -2, -5, -8, -7, -4, -8, -5}, + {-4, -2, -8, -3, -2, -4, -6, 13, -7, -3, -6, -5, 0, -5, 1, -1, -3, -4, -7, -5, -4, 1, -1}, + {-4, -8, -3, -8, -7, -2, -9, -7, 8, -6, 2, 1, -7, -7, -6, -7, -5, -3, 4, -6, -3, -4, -7}, + {-2, -2, -8, -3, 0, -6, -5, -3, -6, 10, -6, -4, -1, -3, 2, 3, -2, -3, -5, -8, -3, -5, 0}, + {-4, -8, -5, -8, -7, 0, -8, -6, 2, -6, 8, 3, -7, -7, -5, -6, -6, -4, 0, -5, -3, -4, -6}, + {-3, -7, -4, -8, -5, -1, -7, -5, 1, -4, 3, 12, -5, -5, -2, -4, -4, -2, 0, -4, -3, -5, -4}, + {-4, 5, -5, 1, -2, -7, -2, 0, -7, -1, -7, -5, 11, -5, -1, -2, 0, -1, -7, -8, -3, -5, -2}, + {-2, -5, -8, -5, -4, -7, -6, -5, -7, -3, -7, -5, -5, 12, -4, -5, -3, -4, -6, -8, -4, -7, -4}, + {-2, -2, -7, -2, 2, -6, -5, 1, -6, 2, -5, -2, -1, -4, 11, 0, -2, -3, -5, -5, -2, -4, 5}, + {-3, -4, -8, -5, -2, -6, -6, -1, -7, 3, -6, -4, -2, -5, 0, 10, -3, -3, -6, -7, -3, -5, -1}, + { 1, -1, -3, -2, -2, -5, -2, -3, -5, -2, -6, -4, 0, -3, -2, -3, 9, 2, -4, -7, -2, -5, -2}, + {-1, -2, -3, -4, -3, -5, -5, -4, -3, -3, -4, -2, -1, -4, -3, -3, 2, 9, -1, -7, -2, -5, -3}, + {-2, -7, -3, -8, -5, -3, -8, -7, 4, -5, 0, 0, -7, -6, -5, -6, -4, -1, 8, -5, -3, -5, -5}, + {-6, -9, -7, 10, -8, 0, -7, -5, -6, -8, -5, -4, -8, -8, -5, -7, -7, -7, -5, 17, -6, 2, -7}, + {-2, -4, -5, -4, -3, -4, -4, -4, -3, -3, -3, -3, -3, -4, -2, -3, -2, -2, -3, -6, -3, -4, -2}, + {-5, -6, -6, -7, -7, 4, -8, 1, -4, -5, -4, -5, -5, -7, -4, -5, -5, -5, -5, 2, -4, 12, -6}, + {-2, 0, -8, 0, 7, -7, -5, -1, -7, 0, -6, -4, -2, -4, 5, -1, -2, -3, -5, -7, -2, -6, 6}, +}; + +void FillData(ost::seq::alg::SubstWeightMatrix* subst, short (&data)[23][23]){ + char chars[23] = {'A','B','C','D','E','F','G','H','I','K','L','M','N','P','Q', + 'R','S','T','V','W','X','Y','Z'}; + for(uint i = 0; i < 23; ++i){ + for(uint j = 0; j < 23; ++j){ + subst->SetWeight(chars[i],chars[j],data[i][j]); + } } - return m; } -void SubstWeightMatrixToInfo(const SubstWeightMatrixPtr& subst_mat, - info::InfoGroup& group) +} + +namespace ost { namespace seq { namespace alg { + +void SubstWeightMatrix::AssignPreset(SubstWeightMatrix::Preset p) { - for (int i=0; i<SubstWeightMatrix::ALPHABET_SIZE; ++i) { - for (int j=0; j<SubstWeightMatrix::ALPHABET_SIZE; ++j) { - char from=char(i+'A'); - char to=char(j+'A'); - info::InfoItem item=group.CreateItem("Weight", - subst_mat->GetWeight(from, to)); - item.SetAttribute("From", String(1, from)); - item.SetAttribute("To", String(1, to)); + max_weight_ = 0; + min_weight_ = 0; + memset(weights_, 0, sizeof(WeightType)*ALPHABET_SIZE*ALPHABET_SIZE); + + switch(p){ + case BLOSUM45:{ + FillData(this,RAW_BLOSUM45_DATA); + break; + } + case BLOSUM62:{ + FillData(this,RAW_BLOSUM62_DATA); + break; + } + case BLOSUM80:{ + FillData(this,RAW_BLOSUM80_DATA); + break; + } + case BLOSUM100:{ + FillData(this,RAW_BLOSUM100_DATA); + break; } } } + }}} diff --git a/modules/seq/alg/src/subst_weight_matrix.hh b/modules/seq/alg/src/subst_weight_matrix.hh index 7ccabc68f87a325c5d161623d2eff63446faf244..c3bb6d6057607b87969b1f7179614173f014b5da 100644 --- a/modules/seq/alg/src/subst_weight_matrix.hh +++ b/modules/seq/alg/src/subst_weight_matrix.hh @@ -23,9 +23,6 @@ #include <string.h> #include <boost/shared_ptr.hpp> #include <ost/config.hh> -#if(OST_INFO_ENABLED) -#include <ost/info/info_fw.hh> -#endif #include <ost/seq/alg/module_config.hh> /* @@ -43,6 +40,10 @@ class DLLEXPORT_OST_SEQ_ALG SubstWeightMatrix { public: typedef short WeightType; const static int ALPHABET_SIZE='Z'-'A'+1; + enum Preset{BLOSUM45 = 0, + BLOSUM62 = 1, + BLOSUM80 = 2, + BLOSUM100 = 3}; /// \brief Initialize substitution matrix with zero. /// /// In order to get a useful substitution weight matrix, use SetWeight(). @@ -51,6 +52,8 @@ public: ::memset(weights_, 0, sizeof(WeightType)*ALPHABET_SIZE*ALPHABET_SIZE); } + void AssignPreset(Preset p); + /// \brief Get the substitution weight between two amino acids /// /// If the amino acid single letter code is unknown (e.g. '?') @@ -100,15 +103,6 @@ private: WeightType min_weight_; }; -#if(OST_INFO_ENABLED) -SubstWeightMatrixPtr DLLEXPORT_OST_SEQ_ALG -SubstWeightMatrixFromInfo(const info::InfoGroup& group); - -void DLLEXPORT_OST_SEQ_ALG -SubstWeightMatrixToInfo(const SubstWeightMatrixPtr& subst_mat, - info::InfoGroup& group); -#endif - }}} #endif