| 1 | /* coot-utils/smith-waterman.cc |
| 2 | * |
| 3 | * Copyright 2021 by Medical Research Council |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 18 | * 02110-1301, USA |
| 19 | */ |
| 20 | |
| 21 | #include <iostream> |
| 22 | #include <iomanip> |
| 23 | #include <algorithm> |
| 24 | |
| 25 | #include "smith-waterman.hh"cxx . . $ `<file>/ligand/smith-waterman.hh`/ |
| 26 | |
| 27 | #include <mmdb2/mmdb_tables.h> // for mmdb::Get1LetterCode() |
| 28 | #include <clipper/core/xmap.h> |
| 29 | #include <clipper/ccp4/ccp4_map_io.h> |
| 30 | |
| 31 | #include "utils/coot-utils.hh"cxx . . $ `<file>/utils/coot-utils.hh`/ |
| 32 | #include "analysis/stats.hh"cxx . . $ `<file>/analysis/stats.hh`/ |
| 33 | |
| 34 | |
| 35 | // get rid of this on merge. |
| 36 | stdcxx . . $ std/::stringcxx . . $ std/string# |
| 37 | coot_util_single_letter_to_3_letter_codecxx . . $ coot_util_single_letter_to_3_letter_code(19fb849b05fb51c6).(char code) { |
| 38 | |
| 39 | if (code == 'G') return stdcxx . . $ std/::stringcxx . . $ std/string#("GLY"); |
| 40 | if (code == 'A') return stdcxx . . $ std/::stringcxx . . $ std/string#("ALA"); |
| 41 | if (code == 'V') return stdcxx . . $ std/::stringcxx . . $ std/string#("VAL"); |
| 42 | if (code == 'S') return stdcxx . . $ std/::stringcxx . . $ std/string#("SER"); |
| 43 | if (code == 'N') return stdcxx . . $ std/::stringcxx . . $ std/string#("ASN"); |
| 44 | if (code == 'P') return stdcxx . . $ std/::stringcxx . . $ std/string#("PRO"); |
| 45 | if (code == 'D') return stdcxx . . $ std/::stringcxx . . $ std/string#("ASP"); |
| 46 | if (code == 'C') return stdcxx . . $ std/::stringcxx . . $ std/string#("CYS"); |
| 47 | if (code == 'Q') return stdcxx . . $ std/::stringcxx . . $ std/string#("GLN"); |
| 48 | if (code == 'E') return stdcxx . . $ std/::stringcxx . . $ std/string#("GLU"); |
| 49 | if (code == 'H') return stdcxx . . $ std/::stringcxx . . $ std/string#("HIS"); |
| 50 | if (code == 'I') return stdcxx . . $ std/::stringcxx . . $ std/string#("ILE"); |
| 51 | if (code == 'L') return stdcxx . . $ std/::stringcxx . . $ std/string#("LEU"); |
| 52 | if (code == 'K') return stdcxx . . $ std/::stringcxx . . $ std/string#("LYS"); |
| 53 | if (code == 'M') return stdcxx . . $ std/::stringcxx . . $ std/string#("MET"); |
| 54 | if (code == 'F') return stdcxx . . $ std/::stringcxx . . $ std/string#("PHE"); |
| 55 | if (code == 'T') return stdcxx . . $ std/::stringcxx . . $ std/string#("THR"); |
| 56 | if (code == 'W') return stdcxx . . $ std/::stringcxx . . $ std/string#("TRP"); |
| 57 | if (code == 'Y') return stdcxx . . $ std/::stringcxx . . $ std/string#("TYR"); |
| 58 | if (code == 'R') return stdcxx . . $ std/::stringcxx . . $ std/string#("ARG"); |
| 59 | |
| 60 | return stdcxx . . $ std/::stringcxx . . $ std/string#(""); |
| 61 | } |
| 62 | |
| 63 | |
| 64 | |
| 65 | float sm_watcxx . . $ sm_wat/::scxx . . $ sm_wat/s(dfb6e31d3a1aa160).(char a, const stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > &b) { |
| 66 | |
| 67 | float ss = 0.0; // think about how bad this needs to be when accumulating log likelihoods. |
| 68 | stdcxx . . $ std/::stringcxx . . $ std/string# tlc = coot_util_single_letter_to_3_letter_codecxx . . $ coot_util_single_letter_to_3_letter_code(19fb849b05fb51c6).(a); |
| 69 | stdcxx . . $ std/::mapcxx . . $ std/map#<std::string, std::pair<std::string, double> >::const_iteratorcxx . . $ std/map#const_iterator# it = b.findcxx . . $ std/map#find(7b3585bb5da8f7d).(tlc); |
| 70 | |
| 71 | if (it != b.endcxx . . $ std/map#end(b953fec338ad1a3b).()) |
| 72 | ss = it->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).secondcxx . . $ std/pair#second..secondcxx . . $ std/pair#second.; |
| 73 | |
| 74 | return ss; |
| 75 | } |
| 76 | |
| 77 | // k is at least 1. |
| 78 | // this is the penalty for a gap of size k |
| 79 | float sm_watcxx . . $ sm_wat/::W_gap_sequencecxx . . $ sm_wat/W_gap_sequence(5cde91ea12d43f46).(int k) { |
| 80 | float gp = 3.5 + (k-1) * 0.5; |
| 81 | return gp; |
| 82 | } |
| 83 | |
| 84 | // k is at least 1. |
| 85 | // this is the penalty for a gap of size k |
| 86 | float sm_watcxx . . $ sm_wat/::W_gap_residuescxx . . $ sm_wat/W_gap_residues(5cde91ea12d43f46).(int k) { |
| 87 | float gp = 6.5 + (k-1) * 0.5; |
| 88 | return gp; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | float sm_watcxx . . $ sm_wat/::score_with_method_1cxx . . $ sm_wat/score_with_method_1(8c18082b14898c4a).(int seq_idx, |
| 93 | int types_idx, |
| 94 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> > > &H, |
| 95 | const stdcxx . . $ std/::stringcxx . . $ std/string# &target_sequence, |
| 96 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > > &scored_residues) { |
| 97 | |
| 98 | char a = target_sequence[cxx . . $ std/__cxx11/basic_string#`operator[]`(7daf10330c1c7fee).seq_idx-1]; |
| 99 | const stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > &b = scored_residues[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).types_idx-1].secondcxx . . $ std/pair#second.; |
| 100 | float s_a_b = scxx . . $ sm_wat/s(dfb6e31d3a1aa160).(a,b); |
| 101 | |
| 102 | if (false) { |
| 103 | stdcxx . . $ std/::stringcxx . . $ std/string# tlc = coot_util_single_letter_to_3_letter_codecxx . . $ coot_util_single_letter_to_3_letter_code(19fb849b05fb51c6).(a); |
| 104 | mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *residue_p = scored_residues[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).types_idx-1].firstcxx . . $ std/pair#first.; |
| 105 | if (tlc ==cxx . . $ std/`operator==`(5ea818b58063a774). stdcxx . . $ std/::stringcxx . . $ std/string#(residue_p->GetResNamecxx . . $ mmdb/Residue#GetResName(41208ce6ca65dd58).())) { |
| 106 | s_a_b = 1.0; |
| 107 | } else { |
| 108 | s_a_b = -0.5; |
| 109 | } |
| 110 | } |
| 111 | float sv = H_i_jcxx . . $ sm_wat/H_i_j(8c18082b14898c4a).(seq_idx-1, types_idx-1, H, target_sequence, scored_residues) + s_a_b; |
| 112 | // std::cout << "---- score method_1 " << sv << std::endl; |
| 113 | return sv; |
| 114 | } |
| 115 | |
| 116 | float sm_watcxx . . $ sm_wat/::score_with_method_2cxx . . $ sm_wat/score_with_method_2(8c18082b14898c4a).(int seq_idx, |
| 117 | int types_idx, |
| 118 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> > > &H, |
| 119 | const stdcxx . . $ std/::stringcxx . . $ std/string# &target_sequence, |
| 120 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > > &scored_residues) { |
| 121 | |
| 122 | const int max_gap_size = 13; |
| 123 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<float> scorescxx . . $ std/vector#vector(229e4d6bd205de31).(max_gap_size+1, -1000.0); |
| 124 | for(int k=1; k<=max_gap_size; k++) { |
| 125 | int i_minus_k = seq_idx - k; // i - k; |
| 126 | int j = types_idx; |
| 127 | if (i_minus_k > 0) { |
| 128 | float H_score = H_i_jcxx . . $ sm_wat/H_i_j(8c18082b14898c4a).(i_minus_k, j, H, target_sequence, scored_residues); |
| 129 | float W_score = W_gap_sequencecxx . . $ sm_wat/W_gap_sequence(5cde91ea12d43f46).(k); |
| 130 | scores[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).k] = H_score - W_score; |
| 131 | // std::cout << "debug score[k] k = " << k << " " << H_score << " - " << W_score << " = " << scores[k] << std::endl; |
| 132 | } |
| 133 | } |
| 134 | // pick the best score |
| 135 | float score_best = -10000.0; |
| 136 | for(int k=1; k<=max_gap_size; k++) |
| 137 | if (scores[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).k] > score_best) score_best = scores[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).k]; |
| 138 | |
| 139 | if (false) { |
| 140 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "method_2 scores "; |
| 141 | for (int k=1; k<=max_gap_size; k++) |
| 142 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "k:" <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). k <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/`operator<<`(f54f2ca72cfad5a6). stdcxx . . $ std/::setprecisioncxx . . $ std/setprecision(94726062283fda89).(1) <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). scores[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).k] <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " "; |
| 143 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 144 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "---- best_score method_2 " <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). score_best <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 145 | } |
| 146 | return score_best; |
| 147 | } |
| 148 | |
| 149 | float sm_watcxx . . $ sm_wat/::score_with_method_3cxx . . $ sm_wat/score_with_method_3(8c18082b14898c4a).(int seq_idx, int types_idx, |
| 150 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> > > &H, |
| 151 | const stdcxx . . $ std/::stringcxx . . $ std/string# &target_sequence, |
| 152 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > > &scored_residues) { |
| 153 | |
| 154 | int max_gap_size = 13; // one of these need only be 2 |
| 155 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<float> scorescxx . . $ std/vector#vector(229e4d6bd205de31).(max_gap_size+1, -1000.0); |
| 156 | for(int k=1; k<=max_gap_size; k++) { |
| 157 | int j_minus_k = types_idx - k; // j - k; |
| 158 | int i = seq_idx; |
| 159 | if (j_minus_k > 0) { |
| 160 | float H_score = H_i_jcxx . . $ sm_wat/H_i_j(8c18082b14898c4a).(i, j_minus_k, H, target_sequence, scored_residues); |
| 161 | float W_score = W_gap_residuescxx . . $ sm_wat/W_gap_residues(5cde91ea12d43f46).(k); |
| 162 | scores[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).k] = H_score - W_score; |
| 163 | } |
| 164 | } |
| 165 | // pick the best score |
| 166 | float score_best = -10000.0; |
| 167 | for(int k=1; k<=max_gap_size; k++) |
| 168 | if (scores[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).k] > score_best) score_best = scores[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).k]; |
| 169 | |
| 170 | if (false) { |
| 171 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "method_3 scores "; |
| 172 | for (int k=1; k<=max_gap_size; k++) |
| 173 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "k:" <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). k <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/`operator<<`(f54f2ca72cfad5a6). stdcxx . . $ std/::setprecisioncxx . . $ std/setprecision(94726062283fda89).(1) <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). scores[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).k] <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " "; |
| 174 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 175 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "---- best_score method_3 " <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). score_best <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 176 | } |
| 177 | return score_best; |
| 178 | } |
| 179 | |
| 180 | stdcxx . . $ std/::paircxx . . $ std/pair#<float, stdcxx . . $ std/::vectorcxx . . $ std/vector#<sm_watcxx . . $ sm_wat/::cell_tcxx . . $ sm_wat/cell_t#> > |
| 181 | sm_watcxx . . $ sm_wat/::backtrackcxx . . $ sm_wat/backtrack(db6274172f879dd4).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> > > &H) { |
| 182 | |
| 183 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<cell_tcxx . . $ sm_wat/cell_t#> blankcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 184 | return backtrack_otherscxx . . $ sm_wat/backtrack_others(610a84f56132d21).(H, blank); |
| 185 | |
| 186 | } |
| 187 | |
| 188 | stdcxx . . $ std/::paircxx . . $ std/pair#<float, stdcxx . . $ std/::vectorcxx . . $ std/vector#<sm_watcxx . . $ sm_wat/::cell_tcxx . . $ sm_wat/cell_t#> > |
| 189 | sm_watcxx . . $ sm_wat/::backtrack_otherscxx . . $ sm_wat/backtrack_others(610a84f56132d21).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> > > &H, |
| 190 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<cell_tcxx . . $ sm_wat/cell_t#> &cells_from_better_traces) { |
| 191 | |
| 192 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<sm_watcxx . . $ sm_wat/::cell_tcxx . . $ sm_wat/cell_t#> seq_index_for_matchescxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 193 | |
| 194 | auto as_yet_undiscovered = [cells_from_better_tracescxx . . $ std/vector#vector(a1201200cf0efa42).] (const cell_tcxx . . $ sm_wat/cell_t# &cell) { |
| 195 | // maybe we should check for gaps also e,g (8, -1) |
| 196 | return (! stdcxx . . $ std/::any_ofcxx . . $ std/any_of(f82cc6ce9cd000ea).(cells_from_better_traces.cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), cells_from_better_traces.cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), |
| 197 | [cell] (const cell_tcxx . . $ sm_wat/cell_t# &o) { return (o==cxx . . $ sm_wat/cell_t#`operator==`(5c4afe7e5badb6b1).cell);})); |
| 198 | }; |
| 199 | |
| 200 | auto selected_move_i_was_in_already_accepted_cells = [] (const cell_tcxx . . $ sm_wat/cell_t# &selected_move, |
| 201 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<cell_tcxx . . $ sm_wat/cell_t#> others) { |
| 202 | return (stdcxx . . $ std/::any_ofcxx . . $ std/any_of(f82cc6ce9cd000ea).(others.cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), others.cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), |
| 203 | [selected_move] (const cell_tcxx . . $ sm_wat/cell_t# &c) { return (selected_move.icxx . . $ sm_wat/cell_t#i. == c.icxx . . $ sm_wat/cell_t#i.); }));}; |
| 204 | auto selected_move_j_was_in_already_accepted_cells = [] (const cell_tcxx . . $ sm_wat/cell_t# &selected_move, |
| 205 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<cell_tcxx . . $ sm_wat/cell_t#> others) { |
| 206 | return (stdcxx . . $ std/::any_ofcxx . . $ std/any_of(f82cc6ce9cd000ea).(others.cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), others.cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), |
| 207 | [selected_move] (const cell_tcxx . . $ sm_wat/cell_t# &c) { return (selected_move.jcxx . . $ sm_wat/cell_t#j. == c.jcxx . . $ sm_wat/cell_t#j.); }));}; |
| 208 | // First find where the max is and store it in idx_max_value |
| 209 | |
| 210 | cell_tcxx . . $ sm_wat/cell_t# idx_max_valuecxx . . $ sm_wat/cell_t#cell_t(f27ff5a0a080eb8a).(0,0); |
| 211 | float max_value = -1000.0; |
| 212 | float max_value_first = max_value; |
| 213 | unsigned int lim_1 = H.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 214 | for (unsigned int i=0; i<lim_1; i++) { |
| 215 | unsigned int lim_2 = H[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i].sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 216 | for (unsigned int j=0; j<lim_2; j++) { |
| 217 | if (H[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i][cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).j].secondcxx . . $ std/pair#second. > max_value) { |
| 218 | if (as_yet_undiscovered(cxx . . $ sm_wat/backtrack_others(610a84f56132d21).$anonymous_type_0#`operator()`(5c4afe7e5badb6b1).cell_tcxx . . $ sm_wat/cell_t#cell_t(f27ff5a0a080eb8a).(i,j))) { |
| 219 | max_value = H[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i][cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).j].secondcxx . . $ std/pair#second.; |
| 220 | max_value_first = max_value; |
| 221 | idx_max_value =cxx . . $ sm_wat/cell_t#`operator=`(918c35afe313dbdd). cell_tcxx . . $ sm_wat/cell_t#cell_t(f27ff5a0a080eb8a).(i,j); |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | if (true) |
| 228 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "debug:: grid search found max value " <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). max_value <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " at " |
| 229 | <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). idx_max_value.icxx . . $ sm_wat/cell_t#i. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). idx_max_value.jcxx . . $ sm_wat/cell_t#j. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 230 | |
| 231 | seq_index_for_matches.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(idx_max_value); |
| 232 | |
| 233 | // backtrack until we find a 0 |
| 234 | bool zero_found = false; |
| 235 | |
| 236 | auto sort_moves_fn = [] (const stdcxx . . $ std/::paircxx . . $ std/pair#<cell_tcxx . . $ sm_wat/cell_t#, float> &m1, |
| 237 | const stdcxx . . $ std/::paircxx . . $ std/pair#<cell_tcxx . . $ sm_wat/cell_t#, float> &m2) { |
| 238 | return m1.secondcxx . . $ std/pair#second. > m2.secondcxx . . $ std/pair#second.; |
| 239 | }; |
| 240 | |
| 241 | unsigned int round_number = 0; |
| 242 | bool debug = false; |
| 243 | while (! zero_found) { |
| 244 | round_number++; |
| 245 | if (debug) |
| 246 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "debug:: loop start idx_max_value " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). idx_max_value.icxx . . $ sm_wat/cell_t#i. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). idx_max_value.jcxx . . $ sm_wat/cell_t#j. |
| 247 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " value " <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). max_value <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 248 | |
| 249 | if (idx_max_value.icxx . . $ sm_wat/cell_t#i. > 1) { |
| 250 | if (idx_max_value.jcxx . . $ sm_wat/cell_t#j. > 1) { |
| 251 | const unsigned int &i = idx_max_value.icxx . . $ sm_wat/cell_t#i.; |
| 252 | const unsigned int &j = idx_max_value.jcxx . . $ sm_wat/cell_t#j.; |
| 253 | cell_tcxx . . $ sm_wat/cell_t# cell_upcxx . . $ sm_wat/cell_t#cell_t(f27ff5a0a080eb8a).(i, j-1); |
| 254 | cell_tcxx . . $ sm_wat/cell_t# cell_leftcxx . . $ sm_wat/cell_t#cell_t(f27ff5a0a080eb8a).(i-1, j); |
| 255 | cell_tcxx . . $ sm_wat/cell_t# cell_diagcxx . . $ sm_wat/cell_t#cell_t(f27ff5a0a080eb8a).(i-1, j-1); |
| 256 | const float &diag = H[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i-1][cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).j-1].secondcxx . . $ std/pair#second.; |
| 257 | const float &left = H[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i-1][cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).j ].secondcxx . . $ std/pair#second.; |
| 258 | const float &up = H[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i ][cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).j-1].secondcxx . . $ std/pair#second.; |
| 259 | stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> available_scored_upcxx . . $ std/pair#pair(62e1774a2dc03c82).( as_yet_undiscovered(cxx . . $ sm_wat/backtrack_others(610a84f56132d21).$anonymous_type_0#`operator()`(5c4afe7e5badb6b1).cell_up), up); |
| 260 | stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> available_scored_leftcxx . . $ std/pair#pair(62e1774a2dc03c82).(as_yet_undiscovered(cxx . . $ sm_wat/backtrack_others(610a84f56132d21).$anonymous_type_0#`operator()`(5c4afe7e5badb6b1).cell_left), left); |
| 261 | stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> available_scored_diagcxx . . $ std/pair#pair(62e1774a2dc03c82).(as_yet_undiscovered(cxx . . $ sm_wat/backtrack_others(610a84f56132d21).$anonymous_type_0#`operator()`(5c4afe7e5badb6b1).cell_diag), diag); |
| 262 | bool move_selected = false; |
| 263 | cell_tcxx . . $ sm_wat/cell_t# selected_movecxx . . $ sm_wat/cell_t#cell_t(49f6e7a06ebc5aa8).; |
| 264 | |
| 265 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<cell_tcxx . . $ sm_wat/cell_t#, float> > available_movescxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 266 | if (cell_up.non_zero_indexedcxx . . $ sm_wat/cell_t#non_zero_indexed(50ce9a9e25b4a850).()) |
| 267 | if (available_scored_up.firstcxx . . $ std/pair#first.) |
| 268 | if (up > 0) |
| 269 | available_moves.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(stdcxx . . $ std/pair#pair(62e1774a2dc03c82).::paircxx . . $ std/pair#<cell_tcxx . . $ sm_wat/cell_t#, float>(cell_up, up)); |
| 270 | if (cell_left.non_zero_indexedcxx . . $ sm_wat/cell_t#non_zero_indexed(50ce9a9e25b4a850).()) |
| 271 | if (available_scored_left.firstcxx . . $ std/pair#first.) |
| 272 | if (left > 0) |
| 273 | available_moves.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(stdcxx . . $ std/pair#pair(62e1774a2dc03c82).::paircxx . . $ std/pair#<cell_tcxx . . $ sm_wat/cell_t#, float>(cell_left, left)); |
| 274 | if (cell_diag.non_zero_indexedcxx . . $ sm_wat/cell_t#non_zero_indexed(50ce9a9e25b4a850).()) |
| 275 | if (available_scored_diag.firstcxx . . $ std/pair#first.) |
| 276 | if (diag > 0) |
| 277 | available_moves.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(stdcxx . . $ std/pair#pair(62e1774a2dc03c82).::paircxx . . $ std/pair#<cell_tcxx . . $ sm_wat/cell_t#, float>(cell_diag, diag)); |
| 278 | |
| 279 | if (available_moves.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() == 3) { |
| 280 | stdcxx . . $ std/::sortcxx . . $ std/sort(4d3091562df4e52e).(available_moves.begincxx . . $ std/vector#begin(55a6de06420d4903).(), available_moves.endcxx . . $ std/vector#end(55a6de06420d4903).(), sort_moves_fn); |
| 281 | selected_move =cxx . . $ sm_wat/cell_t#`operator=`(7a1461d3acc03448). available_moves[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0].firstcxx . . $ std/pair#first.; |
| 282 | max_value = available_moves[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0].secondcxx . . $ std/pair#second.; |
| 283 | move_selected = true; |
| 284 | } |
| 285 | |
| 286 | if (available_moves.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() == 2) { |
| 287 | if (available_moves[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0].secondcxx . . $ std/pair#second. > available_moves[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).1].secondcxx . . $ std/pair#second.) { |
| 288 | selected_move =cxx . . $ sm_wat/cell_t#`operator=`(7a1461d3acc03448). available_moves[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0].firstcxx . . $ std/pair#first.; |
| 289 | max_value = available_moves[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0].secondcxx . . $ std/pair#second.; |
| 290 | move_selected = true; |
| 291 | } else { |
| 292 | selected_move =cxx . . $ sm_wat/cell_t#`operator=`(7a1461d3acc03448). available_moves[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).1].firstcxx . . $ std/pair#first.; |
| 293 | max_value = available_moves[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).1].secondcxx . . $ std/pair#second.; |
| 294 | move_selected = true; |
| 295 | } |
| 296 | |
| 297 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "in n_availible_moves == 2 and move_selected is " <<cxx . . $ std/basic_ostream#`operator<<`(511cbee2d2e28827). move_selected <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 298 | } |
| 299 | |
| 300 | if (available_moves.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() == 1) { |
| 301 | selected_move =cxx . . $ sm_wat/cell_t#`operator=`(7a1461d3acc03448). available_moves[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0].firstcxx . . $ std/pair#first.; |
| 302 | max_value = available_moves[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0].secondcxx . . $ std/pair#second.; |
| 303 | move_selected = true; |
| 304 | } |
| 305 | |
| 306 | if (move_selected) { |
| 307 | |
| 308 | idx_max_value =cxx . . $ sm_wat/cell_t#`operator=`(7a1461d3acc03448). selected_move; |
| 309 | if (seq_index_for_matches.emptycxx . . $ std/vector#empty(3482b152b9333168).()) { |
| 310 | seq_index_for_matches.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(selected_move); |
| 311 | } else { |
| 312 | if (selected_move_i_was_in_already_accepted_cells(cxx . . $ sm_wat/backtrack_others(610a84f56132d21).$anonymous_type_1#`operator()`(1468d089c5bbd673).selected_move, seq_index_for_matchescxx . . $ std/vector#vector(a1201200cf0efa42).)) |
| 313 | selected_move.icxx . . $ sm_wat/cell_t#i. = -1; |
| 314 | if (selected_move_j_was_in_already_accepted_cells(cxx . . $ sm_wat/backtrack_others(610a84f56132d21).$anonymous_type_2#`operator()`(1468d089c5bbd673).selected_move, seq_index_for_matchescxx . . $ std/vector#vector(a1201200cf0efa42).)) |
| 315 | selected_move.jcxx . . $ sm_wat/cell_t#j. = -1; |
| 316 | seq_index_for_matches.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(selected_move); |
| 317 | } |
| 318 | |
| 319 | } else { |
| 320 | |
| 321 | if (false) { |
| 322 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "------------ oops - no move selected - nowhere to go " |
| 323 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "n_availible_moves " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). available_moves.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 324 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "up: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). cell_up.icxx . . $ sm_wat/cell_t#i. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). cell_up.jcxx . . $ sm_wat/cell_t#j. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " value " <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). up <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 325 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "left: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). cell_left.icxx . . $ sm_wat/cell_t#i. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). cell_left.jcxx . . $ sm_wat/cell_t#j. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " value " <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). left <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 326 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "diag: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). cell_diag.icxx . . $ sm_wat/cell_t#i. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). cell_diag.jcxx . . $ sm_wat/cell_t#j. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " value " <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). diag <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 327 | if (! cells_from_better_traces.emptycxx . . $ std/vector#empty(3482b152b9333168).()) { |
| 328 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "previous" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 329 | for (const auto &c : cells_from_better_traces) |
| 330 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). c.icxx . . $ sm_wat/cell_t#i. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). c.jcxx . . $ sm_wat/cell_t#j. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | zero_found = true; |
| 335 | } |
| 336 | } else { |
| 337 | zero_found = true; |
| 338 | } |
| 339 | } else { |
| 340 | zero_found = true; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | return stdcxx . . $ std/pair#pair(62e1774a2dc03c82).::paircxx . . $ std/pair#<float, stdcxx . . $ std/::vectorcxx . . $ std/vector#<sm_watcxx . . $ sm_wat/::cell_tcxx . . $ sm_wat/cell_t#> >(max_value_first, seq_index_for_matches); |
| 345 | } |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> > > |
| 351 | sm_watcxx . . $ sm_wat/::construct_Hcxx . . $ sm_wat/construct_H(5272cde88b88ec3).(const stdcxx . . $ std/::stringcxx . . $ std/string# &target_sequence, |
| 352 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > > &scored_residues) { |
| 353 | |
| 354 | // an array of [target_sequence.size() + 1] x [n_residues + 1] |
| 355 | |
| 356 | unsigned int n_model_residues = scored_residues.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 357 | unsigned int n = target_sequence.sizecxx . . $ std/__cxx11/basic_string#size(7e80fff40d76986b).() + 1; |
| 358 | unsigned int m = n_model_residues + 1; |
| 359 | |
| 360 | stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> initial_valuecxx . . $ std/pair#pair(62e1774a2dc03c82).(false, -1.0); |
| 361 | stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> true_0cxx . . $ std/pair#pair(62e1774a2dc03c82).(true, 0.0); |
| 362 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> > > Hcxx . . $ std/vector#vector(83fdeebbe0501a83).(n); |
| 363 | for (unsigned int i=0; i<H.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) |
| 364 | H[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i].resizecxx . . $ std/vector#resize(3804226c8c0acbc3).(m, initial_value); |
| 365 | for (unsigned int i=0; i<H.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) |
| 366 | H[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i][cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0] =cxx . . $ std/pair#`operator=`(277da66fe4726b22). true_0; |
| 367 | for (unsigned int j=0; j<m; j++) |
| 368 | H[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0][cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).j] =cxx . . $ std/pair#`operator=`(277da66fe4726b22). true_0; |
| 369 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "H is constructed " <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). n <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). m <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 370 | return Hcxx . . $ std/vector#vector(6f559d22b039ccdb).; |
| 371 | } |
| 372 | |
| 373 | void |
| 374 | sm_watcxx . . $ sm_wat/::fill_scoring_matrixcxx . . $ sm_wat/fill_scoring_matrix(f5d636d781fa064a).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> > > &H, |
| 375 | const stdcxx . . $ std/::stringcxx . . $ std/string# &target_sequence, |
| 376 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > > &scored_residues) { |
| 377 | |
| 378 | int n = target_sequence.lengthcxx . . $ std/__cxx11/basic_string#length(7e80fff40d76986b).(); |
| 379 | int m = scored_residues.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 380 | int lim_1 = n + 1; |
| 381 | int lim_2 = m + 1; |
| 382 | |
| 383 | // std::cout << "::::::::::::::::: fill_scoring_matrix lims: " << lim_1 << " " << lim_2 << std::endl; |
| 384 | for (int i=0; i<lim_1; i++) { |
| 385 | for (int j=0; j<lim_2; j++) { |
| 386 | // std::cout << "calc H for " << i << " " << j << std::endl; |
| 387 | float v = H_i_jcxx . . $ sm_wat/H_i_j(8c18082b14898c4a).(i, j, H, target_sequence, scored_residues); |
| 388 | // std::cout << "filling H " << i << " " << j << " with " << std::setprecision(4) << v << std::endl; |
| 389 | H[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i][cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).j] =cxx . . $ std/pair#`operator=`(ab9ebd0b824095ec). stdcxx . . $ std/pair#pair(62e1774a2dc03c82).::paircxx . . $ std/pair#<bool, float> (true, v); |
| 390 | } |
| 391 | } |
| 392 | // std::cout << "H is filled" << std::endl; |
| 393 | } |
| 394 | |
| 395 | float |
| 396 | sm_watcxx . . $ sm_wat/::H_i_jcxx . . $ sm_wat/H_i_j(8c18082b14898c4a).(int seq_idx, int residue_idx, |
| 397 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> > > &H, |
| 398 | const stdcxx . . $ std/::stringcxx . . $ std/string# &target_sequence, |
| 399 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > > &scored_residues) { |
| 400 | |
| 401 | // std::cout << "H_i_j called with " << seq_idx << " " << types_idx << std::endl; |
| 402 | |
| 403 | const int &i = seq_idx; |
| 404 | const int &j = residue_idx; |
| 405 | if (seq_idx == 0) return 0.0; |
| 406 | if (residue_idx == 0) return 0.0; |
| 407 | |
| 408 | if (H[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i][cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).j].firstcxx . . $ std/pair#first.) return H[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i][cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).j].secondcxx . . $ std/pair#second.; |
| 409 | |
| 410 | float offset = 0.0; |
| 411 | |
| 412 | float v_1 = score_with_method_1cxx . . $ sm_wat/score_with_method_1(8c18082b14898c4a).(i, j, H, target_sequence, scored_residues) + offset; |
| 413 | float v_2 = score_with_method_2cxx . . $ sm_wat/score_with_method_2(8c18082b14898c4a).(i, j, H, target_sequence, scored_residues) + offset; |
| 414 | float v_3 = score_with_method_3cxx . . $ sm_wat/score_with_method_3(8c18082b14898c4a).(i, j, H, target_sequence, scored_residues) + offset; |
| 415 | float v_4 = 0.0; |
| 416 | float v = v_1; |
| 417 | if (v_2 > v) v = v_2; |
| 418 | if (v_3 > v) v = v_3; |
| 419 | if (v_4 > v) v = v_4; |
| 420 | |
| 421 | // std::cout << "debug:: H " << i << " " << j << " choose between " << v_1 << " " << v_2 << " " << v_3 << " " << v_4 << std::endl; |
| 422 | |
| 423 | return v; |
| 424 | } |
| 425 | |
| 426 | void sm_watcxx . . $ sm_wat/::print_Hcxx . . $ sm_wat/print_H(ba3a9dee6c744893).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> > > &H) { |
| 427 | |
| 428 | unsigned int lim_1 = H.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 429 | |
| 430 | if (true) { |
| 431 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "booleans" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 432 | for (unsigned int i=0; i<lim_1; i++) { |
| 433 | unsigned int lim_2 = H[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i].sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 434 | for (unsigned int j=0; j<lim_2; j++) { |
| 435 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(511cbee2d2e28827). H[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i][cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).j].firstcxx . . $ std/pair#first. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " "; |
| 436 | } |
| 437 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "values" <<cxx . . $ std/basic_ostream#`operator<<`(d90e0e305b0e25c2). stdcxx . . $ std/::fixedcxx . . $ std/fixed(cf36cc481190cd1f). <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 442 | for (unsigned int i=0; i<lim_1; i++) { |
| 443 | unsigned int lim_2 = H[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i].sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 444 | for (unsigned int j=0; j<lim_2; j++) { |
| 445 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(fe9a269018418773). stdcxx . . $ std/::setwcxx . . $ std/setw(f06ce2e9220601fb).(5) <<cxx . . $ std/`operator<<`(f54f2ca72cfad5a6). stdcxx . . $ std/::setprecisioncxx . . $ std/setprecision(94726062283fda89).(5) <<cxx . . $ std/basic_ostream#`operator<<`(d90e0e305b0e25c2). stdcxx . . $ std/::leftcxx . . $ std/left(cf36cc481190cd1f). <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). H[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i][cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).j].secondcxx . . $ std/pair#second. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " "; |
| 446 | } |
| 447 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | |
| 452 | void |
| 453 | sm_watcxx . . $ sm_wat/::print_alignmentcxx . . $ sm_wat/print_alignment(73ce7e7a11668a54).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<cell_tcxx . . $ sm_wat/cell_t#> &indexed_sequences_in, // currently reverse order |
| 454 | const stdcxx . . $ std/::stringcxx . . $ std/string# &sequence, |
| 455 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > > &scored_residues) { |
| 456 | |
| 457 | // std::cout << "in print_alignment() sequence length " << sequence.length() << std::endl; |
| 458 | // std::cout << "in print_alignment() scored residues size " << scored_residues.size() << std::endl; |
| 459 | |
| 460 | auto indexed_sequences = indexed_sequences_incxx . . $ std/vector#vector(a1201200cf0efa42).; |
| 461 | stdcxx . . $ std/::reversecxx . . $ std/reverse(249673c20e2b8d5).(indexed_sequences.begincxx . . $ std/vector#begin(55a6de06420d4903).(), indexed_sequences.endcxx . . $ std/vector#end(55a6de06420d4903).()); |
| 462 | stdcxx . . $ std/::stringcxx . . $ std/string# seq_align_stringcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 463 | stdcxx . . $ std/::stringcxx . . $ std/string# res_align_stringcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 464 | stdcxx . . $ std/::stringcxx . . $ std/string# res_align_string_slccxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 465 | for (const auto &p : indexed_sequences) { |
| 466 | int idx_for_seq = p.icxx . . $ sm_wat/cell_t#i. - 1; |
| 467 | int idx_for_res = p.jcxx . . $ sm_wat/cell_t#j. - 1; |
| 468 | if (p.icxx . . $ sm_wat/cell_t#i. == -1) { |
| 469 | seq_align_string +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). "-"; |
| 470 | } else { |
| 471 | // happy path |
| 472 | char c = sequence[cxx . . $ std/__cxx11/basic_string#`operator[]`(7daf10330c1c7fee).idx_for_seq]; |
| 473 | seq_align_string +=cxx . . $ std/__cxx11/basic_string#`operator+=`(63cc1ae870623930). c; |
| 474 | } |
| 475 | if (p.jcxx . . $ sm_wat/cell_t#j. == -1) { |
| 476 | res_align_string +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). "--- "; |
| 477 | res_align_string_slc +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). "-"; |
| 478 | } else { |
| 479 | mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *res = scored_residues[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).idx_for_res].firstcxx . . $ std/pair#first.;; |
| 480 | stdcxx . . $ std/::stringcxx . . $ std/string# res_name = rescxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).->GetResNamecxx . . $ mmdb/Residue#GetResName(41208ce6ca65dd58).(); |
| 481 | res_align_string +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). res_name; |
| 482 | res_align_string +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). " "; |
| 483 | char r[10]; |
| 484 | mmdbcxx . . $ mmdb/::Get1LetterCodecxx . . $ mmdb/Get1LetterCode(611124a97efc52dd).(res->GetResNamecxx . . $ mmdb/Residue#GetResName(41208ce6ca65dd58).(), r); |
| 485 | res_align_string_slc +=cxx . . $ std/__cxx11/basic_string#`operator+=`(63cc1ae870623930). r[0]; |
| 486 | } |
| 487 | } |
| 488 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " input sequence: " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). sequence <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 489 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " aligned target-seq: " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). seq_align_string <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 490 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " aligned current-model: " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). res_align_string_slc <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 491 | |
| 492 | if (false) // not very useful |
| 493 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " model: " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). res_align_string <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 494 | } |
| 495 | |
| 496 | |
| 497 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<sm_watcxx . . $ sm_wat/::cell_tcxx . . $ sm_wat/cell_t#> // return the alignment |
| 498 | sm_watcxx . . $ sm_wat/::smith_watermancxx . . $ sm_wat/smith_waterman(5ab979c43a0bea5c).(const stdcxx . . $ std/::stringcxx . . $ std/string# &sequence, |
| 499 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > > &scored_residues_in) { |
| 500 | |
| 501 | // because I want to fiddle with them for debugging |
| 502 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > > scored_residues = scored_residues_incxx . . $ std/vector#vector(a1201200cf0efa42).; |
| 503 | |
| 504 | cootcxx . . $ coot/::statscxx . . $ coot/stats/::singlecxx . . $ coot/stats/single# data_precxx . . $ coot/stats/single#single(49f6e7a06ebc5aa8).; |
| 505 | cootcxx . . $ coot/::statscxx . . $ coot/stats/::singlecxx . . $ coot/stats/single# data_postcxx . . $ coot/stats/single#single(49f6e7a06ebc5aa8).; |
| 506 | |
| 507 | for (const auto &scored_residue : scored_residues) { |
| 508 | mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *residue_p = scored_residue.firstcxx . . $ std/pair#first.; |
| 509 | stdcxx . . $ std/::stringcxx . . $ std/string# actual_residue_namecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).(residue_p->GetResNamecxx . . $ mmdb/Residue#GetResName(41208ce6ca65dd58).()); |
| 510 | for (const auto &scored_type : scored_residue.secondcxx . . $ std/pair#second.) { |
| 511 | data_pre.addcxx . . $ coot/stats/single#add(f371dfa6ad81844c).(scored_type.secondcxx . . $ std/pair#second..secondcxx . . $ std/pair#second.); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | float squidge_offset = -data_pre.meancxx . . $ coot/stats/single#mean(21b6c25e127938e2).() + 1.2 * sqrtcxx . . $ sqrt(fee4f1d22bc8e617).(data_pre.variancecxx . . $ coot/stats/single#variance(21b6c25e127938e2).()); // 1.1 may need some adjustment, related to gap penalty |
| 516 | float squidge_scale = 1.0/sqrtcxx . . $ sqrt(fee4f1d22bc8e617).(data_pre.variancecxx . . $ coot/stats/single#variance(21b6c25e127938e2).()); |
| 517 | |
| 518 | for (auto &scored_residue : scored_residues) { |
| 519 | mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *residue_p = scored_residue.firstcxx . . $ std/pair#first.; |
| 520 | stdcxx . . $ std/::stringcxx . . $ std/string# actual_residue_namecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).(residue_p->GetResNamecxx . . $ mmdb/Residue#GetResName(41208ce6ca65dd58).()); |
| 521 | // std::cout << "Residue " << residue_p->GetChainID() << " " << residue_p->GetSeqNum() << " " |
| 522 | // << residue_p->GetResName() << std::endl; |
| 523 | for (auto &scored_type : scored_residue.secondcxx . . $ std/pair#second.) { |
| 524 | scored_type.secondcxx . . $ std/pair#second..secondcxx . . $ std/pair#second. += squidge_offset; |
| 525 | scored_type.secondcxx . . $ std/pair#second..secondcxx . . $ std/pair#second. *= squidge_scale; |
| 526 | data_post.addcxx . . $ coot/stats/single#add(f371dfa6ad81844c).(scored_type.secondcxx . . $ std/pair#second..secondcxx . . $ std/pair#second.); |
| 527 | if (scored_type.firstcxx . . $ std/pair#first. ==cxx . . $ std/`operator==`(5ea818b58063a774). actual_residue_name) |
| 528 | scored_type.secondcxx . . $ std/pair#second..secondcxx . . $ std/pair#second. += 0.0; |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "--------- statistics ---------" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 533 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " data_pre: mean: " <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). data_pre.meancxx . . $ coot/stats/single#mean(21b6c25e127938e2).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " sd: " <<cxx . . $ std/basic_ostream#`operator<<`(2b73cd0f0517cf77). sqrtf(data_pre.variancecxx . . $ coot/stats/single#variance(21b6c25e127938e2).()) <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 534 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " data_post: mean: " <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). data_post.meancxx . . $ coot/stats/single#mean(21b6c25e127938e2).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " sd: " <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). sqrtcxx . . $ sqrt(fee4f1d22bc8e617).(data_post.variancecxx . . $ coot/stats/single#variance(21b6c25e127938e2).()) <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 535 | |
| 536 | bool print_the_residue_scores = false; |
| 537 | |
| 538 | if (print_the_residue_scores) { // print the residue scores |
| 539 | for (const auto &scored_residue : scored_residues) { |
| 540 | mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *residue_p = scored_residue.firstcxx . . $ std/pair#first.; |
| 541 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Residue " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). residue_p->GetChainIDcxx . . $ mmdb/Residue#GetChainID(41208ce6ca65dd58).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). residue_p->GetSeqNumcxx . . $ mmdb/Residue#GetSeqNum(b126dc7c1de90089).() |
| 542 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). residue_p->GetResNamecxx . . $ mmdb/Residue#GetResName(41208ce6ca65dd58).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 543 | for (const auto &scored_type : scored_residue.secondcxx . . $ std/pair#second.) { |
| 544 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). scored_type.firstcxx . . $ std/pair#first. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/`operator<<`(fe9a269018418773). stdcxx . . $ std/::setwcxx . . $ std/setw(f06ce2e9220601fb).(7) <<cxx . . $ std/`operator<<`(f54f2ca72cfad5a6). stdcxx . . $ std/::setprecisioncxx . . $ std/setprecision(94726062283fda89).(4) <<cxx . . $ std/basic_ostream#`operator<<`(d90e0e305b0e25c2). stdcxx . . $ std/::fixedcxx . . $ std/fixed(cf36cc481190cd1f). <<cxx . . $ std/basic_ostream#`operator<<`(d90e0e305b0e25c2). stdcxx . . $ std/::rightcxx . . $ std/right(cf36cc481190cd1f). <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). scored_type.secondcxx . . $ std/pair#second..secondcxx . . $ std/pair#second. |
| 545 | <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<bool, float> > > H = construct_Hcxx . . $ sm_wat/construct_H(5272cde88b88ec3).(sequence, scored_residues); |
| 551 | // print_H(H); |
| 552 | fill_scoring_matrixcxx . . $ sm_wat/fill_scoring_matrix(f5d636d781fa064a).(H, sequence, scored_residues); |
| 553 | // print_H(H); |
| 554 | |
| 555 | // these indices are for residue numbers, not indexing into the string. |
| 556 | // So we need to offset by -1 get the correct single-letter-code from the sequence |
| 557 | // and the residue from the scored_residues (or run-of-residues) |
| 558 | // |
| 559 | stdcxx . . $ std/::paircxx . . $ std/pair#<float, stdcxx . . $ std/::vectorcxx . . $ std/vector#<cell_tcxx . . $ sm_wat/cell_t#> > scored_trace = sm_watcxx . . $ sm_wat/::backtrackcxx . . $ sm_wat/backtrack(db6274172f879dd4).(H); |
| 560 | |
| 561 | // std::cout << "Top Score " << scored_trace.first << std::endl; |
| 562 | |
| 563 | bool print_sequence_indices = true; // debugging really. |
| 564 | if (print_sequence_indices) { |
| 565 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Best indexes:" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 566 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "sequence indices (rev): "; |
| 567 | for (unsigned int i=0; i<scored_trace.secondcxx . . $ std/pair#second..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) |
| 568 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(fe9a269018418773). stdcxx . . $ std/::setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(d90e0e305b0e25c2). stdcxx . . $ std/::rightcxx . . $ std/right(cf36cc481190cd1f). <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). scored_trace.secondcxx . . $ std/pair#second.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i].icxx . . $ sm_wat/cell_t#i. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " "; |
| 569 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 570 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "residue indices (rev): "; |
| 571 | for (unsigned int j=0; j<scored_trace.secondcxx . . $ std/pair#second..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); j++) |
| 572 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(fe9a269018418773). stdcxx . . $ std/::setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(d90e0e305b0e25c2). stdcxx . . $ std/::rightcxx . . $ std/right(cf36cc481190cd1f). <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). scored_trace.secondcxx . . $ std/pair#second.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).j].jcxx . . $ sm_wat/cell_t#j. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " "; |
| 573 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 574 | } |
| 575 | |
| 576 | print_alignmentcxx . . $ sm_wat/print_alignment(73ce7e7a11668a54).(scored_trace.secondcxx . . $ std/pair#second., sequence, scored_residues); |
| 577 | |
| 578 | #if 0 |
| 579 | std::cout << " " << std::endl; |
| 580 | |
| 581 | std::pair<float, std::vector<cell_t> > scored_trace_2 = sm_wat::backtrack_others(H, scored_trace.second); |
| 582 | std::cout << "Next Best " << scored_trace_2.first << std::endl; |
| 583 | std::cout << "Second Best indexes:" << std::endl; |
| 584 | std::cout << "sequence indices (rev): "; |
| 585 | for (unsigned int i=0; i<scored_trace_2.second.size(); i++) |
| 586 | std::cout << std::setw(2) << std::right << scored_trace_2.second[i].i << " "; |
| 587 | std::cout << std::endl; |
| 588 | std::cout << "residue indices (rev): "; |
| 589 | for (unsigned int j=0; j<scored_trace_2.second.size(); j++) |
| 590 | std::cout << std::setw(2) << std::right << scored_trace_2.second[j].j << " "; |
| 591 | std::cout << std::endl; |
| 592 | |
| 593 | print_alignment(scored_trace_2.second, sequence, scored_residues); |
| 594 | #endif |
| 595 | |
| 596 | return scored_tracecxx . . $ std/vector#vector(a1201200cf0efa42)..secondcxx . . $ std/pair#second.; |
| 597 | |
| 598 | } |
| 599 | |
| 600 | #include <ligand/side-chain-densities.hh>cxx . . $ `<file>/ligand/side-chain-densities.hh`/ |
| 601 | |
| 602 | |
| 603 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > > |
| 604 | sm_watcxx . . $ sm_wat/::get_side_chain_density_scores_for_residuescxx . . $ sm_wat/get_side_chain_density_scores_for_residues(4b26bbad5e71e108).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *> &a_run_of_residues, |
| 605 | const clippercxx . . $ clipper/::Xmapcxx . . $ clipper/Xmap#<float> &xmap) { |
| 606 | |
| 607 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > > vcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 608 | |
| 609 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "------------------- a_run_of_residues has " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). a_run_of_residues.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " residues" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 610 | |
| 611 | if (! a_run_of_residues.emptycxx . . $ std/vector#empty(3482b152b9333168).()) { |
| 612 | |
| 613 | cootcxx . . $ coot/::side_chain_densitiescxx . . $ coot/side_chain_densities# scdcxx . . $ coot/side_chain_densities#side_chain_densities(49f6e7a06ebc5aa8).; |
| 614 | |
| 615 | scd.fill_residue_blockscxx . . $ coot/side_chain_densities#fill_residue_blocks(e4ef8f2523c9f2ba).(a_run_of_residues, xmap); // return fast if already filled, uses atomic locking. |
| 616 | int n_residues = a_run_of_residues.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 617 | for (int i=0; i<n_residues; i++) { |
| 618 | mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *residue_p = a_run_of_residues[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i]; |
| 619 | stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > likelihood_map = |
| 620 | scd.likelihood_of_each_rotamer_at_this_residuecxx . . $ coot/side_chain_densities#likelihood_of_each_rotamer_at_this_residue(60c21ebc99b71b0f).(residue_p, xmap); |
| 621 | stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > pcxx . . $ std/pair#pair(62e1774a2dc03c82).(residue_p, likelihood_map); |
| 622 | v.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(p); |
| 623 | } |
| 624 | } |
| 625 | return vcxx . . $ std/vector#vector(6f559d22b039ccdb).; |
| 626 | } |
| 627 | |
| 628 | void |
| 629 | sm_watcxx . . $ sm_wat/::apply_alignment_to_modelcxx . . $ sm_wat/apply_alignment_to_model(73ce7e7a11668a54).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<sm_watcxx . . $ sm_wat/::cell_tcxx . . $ sm_wat/cell_t#> &alignment, |
| 630 | const stdcxx . . $ std/::stringcxx . . $ std/string# &target_sequence, |
| 631 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > > &scored_residues) { |
| 632 | |
| 633 | // mutate away! |
| 634 | for (unsigned int i=0; i<scored_residues.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) { |
| 635 | stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > scored_residue = scored_residuescxx . . $ std/pair#pair(31533a781ed7dba3).[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i]; |
| 636 | mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *residue_p = scored_residue.firstcxx . . $ std/pair#first.; |
| 637 | stdcxx . . $ std/::stringcxx . . $ std/string# current_res_typecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).(residue_p->GetResNamecxx . . $ mmdb/Residue#GetResName(41208ce6ca65dd58).()); |
| 638 | bool mutated_this = false; |
| 639 | int idx_residue_seq = i + 1; |
| 640 | for (unsigned int j=0; j<alignment.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); j++) { |
| 641 | if (alignment[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).j].jcxx . . $ sm_wat/cell_t#j. == idx_residue_seq) { |
| 642 | int raw_index = alignment[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).j].icxx . . $ sm_wat/cell_t#i.-1; |
| 643 | if (raw_index >= 0) { |
| 644 | char c = target_sequence[cxx . . $ std/__cxx11/basic_string#`operator[]`(7daf10330c1c7fee).raw_index]; |
| 645 | // std::cout << "for j " << j << " raw index is " << alignment[j].i-1 << " c is '" << c << "'" << std::endl; |
| 646 | if (c != '=') { |
| 647 | stdcxx . . $ std/::stringcxx . . $ std/string# new_res_name = coot_util_single_letter_to_3_letter_codecxx . . $ coot_util_single_letter_to_3_letter_code(19fb849b05fb51c6).(c); |
| 648 | if (false) |
| 649 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "deubg:: mutate " <<cxx . . $ coot/`operator<<`(864abc555d23019c). cootcxx . . $ coot/::residue_spec_tcxx . . $ coot/residue_spec_t#(residue_p) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). current_res_type <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " to " |
| 650 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\"" <<cxx . . $ std/`operator<<`(88df5bef833f7f83). new_res_name <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\" from char c " <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). c <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 651 | cootcxx . . $ coot/::utilcxx . . $ coot/util/::mutatecxx . . $ coot/util/mutate(6f7004df6b3ecaf0).(residue_p, new_res_name); |
| 652 | mutated_this = true; |
| 653 | break; |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | if (mutated_this == false) { |
| 659 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Missed mutation for residue " <<cxx . . $ coot/`operator<<`(864abc555d23019c). cootcxx . . $ coot/::residue_spec_tcxx . . $ coot/residue_spec_t#(residue_p) <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | #include <coot-utils/fragment-container.hh>cxx . . $ `<file>/coot-utils/fragment-container.hh`/ |
| 665 | #include <ligand/backrub-rotamer.hh>cxx . . $ `<file>/ligand/backrub-rotamer.hh`/ |
| 666 | |
| 667 | void |
| 668 | sm_watcxx . . $ sm_wat/::align_and_mutate_and_backrubcxx . . $ sm_wat/align_and_mutate_and_backrub(ca7889116dd5b4e2).(mmdbcxx . . $ mmdb/::Managercxx . . $ mmdb/Manager# *mol, const stdcxx . . $ std/::stringcxx . . $ std/string# &seq, const clippercxx . . $ clipper/::Xmapcxx . . $ clipper/Xmap#<float> &xmap, |
| 669 | const cootcxx . . $ coot/::protein_geometrycxx . . $ coot/protein_geometry# &pg) { |
| 670 | |
| 671 | cootcxx . . $ coot/::fragment_container_tcxx . . $ coot/fragment_container_t# fragments = cootcxx . . $ coot/::make_fragmentscxx . . $ coot/make_fragments(7340aab50a04ae48).(mol); |
| 672 | fragments.print_fragmentscxx . . $ coot/fragment_container_t#print_fragments(83f5f38750778ac8).(); |
| 673 | |
| 674 | for (const auto &fragment : fragments.rangescxx . . $ coot/fragment_container_t#ranges.) { |
| 675 | |
| 676 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "----------------- fragment has " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). fragment.residuescxx . . $ coot/fragment_container_t#fragment_range_t#residues..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " residues " <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 677 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "----------------- fragment: " <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 678 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<mmdbcxx . . $ mmdb/::Residuecxx . . $ mmdb/Residue# *, stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, double> > > > scored_residues = |
| 679 | get_side_chain_density_scores_for_residuescxx . . $ sm_wat/get_side_chain_density_scores_for_residues(4b26bbad5e71e108).(fragment.residuescxx . . $ coot/fragment_container_t#fragment_range_t#residues., xmap); |
| 680 | |
| 681 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "-------------------- we got scored_residues of size " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). scored_residues.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 682 | |
| 683 | if (! scored_residues.emptycxx . . $ std/vector#empty(3482b152b9333168).()) { |
| 684 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<sm_watcxx . . $ sm_wat/::cell_tcxx . . $ sm_wat/cell_t#> &alignment = sm_watcxx . . $ sm_wat/::smith_watermancxx . . $ sm_wat/smith_waterman(5ab979c43a0bea5c).(seq, scored_residues); |
| 685 | apply_alignment_to_modelcxx . . $ sm_wat/apply_alignment_to_model(73ce7e7a11668a54).(alignment, seq, scored_residues); |
| 686 | cootcxx . . $ coot/::backrub_moleculecxx . . $ coot/backrub_molecule(8d9ab6f1a5e7ef7d).(mol, &xmap, pg); |
| 687 | } |
| 688 | } |
| 689 | } |