Changeset 568
- Timestamp:
- 04/21/10 17:25:16 (5 months ago)
- Location:
- current/src
- Files:
-
- 7 edited
-
include/dawg/details/subst_aa.h (modified) (6 diffs)
-
include/dawg/details/subst_dna.h (modified) (11 diffs)
-
include/dawg/indel.h (modified) (2 diffs)
-
include/dawg/subst.h (modified) (3 diffs)
-
include/dawg/utils.h (modified) (2 diffs)
-
lib/matic.cpp (modified) (2 diffs)
-
lib/output.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
current/src/include/dawg/details/subst_aa.h
r567 r568 10 10 // name, followed by params, then freqs 11 11 template<typename It1, typename It2> 12 bool subst_model::create_aagtr(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2) {12 bool subst_model::create_aagtr(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2) { 13 13 double d = 0.0; 14 14 int u = 0; 15 15 _model = residue_exchange::AA; 16 16 // do freqs first 17 if(!create_freqs( rname, first2, last2, &freqs[0], &freqs[20]))17 if(!create_freqs(mod_name, first2, last2, &freqs[0], &freqs[20])) 18 18 return false; 19 19 … … 72 72 freqs[i] = d; 73 73 } 74 // we will include 32 sites in our binary search 75 // so fill them with 1.0 76 std::fill(&freqs[19],&freqs[31], 1.0); 74 77 freqs[19] = 1.0; 75 78 for(int i=0;i<20;++i) { … … 79 82 table[i][j] = d; 80 83 } 81 table[i][19] = 1.0; 84 // we will include 32 sites in our binary search 85 // so fill them with 1.0 86 std::fill(&table[i][19],&table[i][31], 1.0); 82 87 } 83 name = rname;88 name = mod_name; 84 89 do_op_f = &subst_model::do_aagtr_f; 85 90 do_op_s = &subst_model::do_aagtr_s; … … 89 94 90 95 template<typename It1, typename It2> 91 bool subst_model::create_wag(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2) {92 static const floats[190] = {96 bool subst_model::create_wag(const char *, It1 first1, It1 last1, It2 first2, It2 last2) { 97 static const double s[190] = { 93 98 1.02704, 0.738998, 0.0302949, 1.58285, 0.021352, 6.17416, 0.210494, 0.39802, 94 99 0.0467304, 0.0811339, 1.41672, 0.306674, 0.865584, 0.567717, 0.049931, 0.316954, … … 115 120 0.428437, 1.086, 0.216046, 0.22771, 0.381533, 0.786993, 0.291148, 0.31473, 2.48539 116 121 }; 117 static const floatp[20] = {122 static const double p[20] = { 118 123 0.0866279, 0.0193078, 0.0570451, 0.0580589, 0.0384319, 0.0832518, 0.0244313, 0.048466, 119 124 0.0620286, 0.086209, 0.0195027, 0.0390894, 0.0457631, 0.0367281, 0.043972, 0.0695179, … … 121 126 }; 122 127 if(first2 != last2) { //+F model 123 std::string a(rname); 124 a += "+F"; 125 return create_aagtr(a, &s[0], &s[190], first2, last2); 128 return create_aagtr("wag+f", &s[0], &s[190], first2, last2); 126 129 } 127 return create_aagtr( rname, &s[0], &s[190], &p[0], &p[20]);130 return create_aagtr("wag", &s[0], &s[190], &p[0], &p[20]); 128 131 } 129 132 133 template<typename It1, typename It2> 134 bool subst_model::create_wagstar(const char *, It1 first1, It1 last1, It2 first2, It2 last2) { 135 static const double s[190] = { 136 1.21324, 0.731152, 0.0379056, 1.55788, 0.0284956, 6.04299, 0.213179, 0.485001, 137 0.0458258, 0.0873936, 1.41993, 0.312544, 0.88357, 0.588609, 0.0552962, 0.317684, 138 0.341479, 0.958529, 0.599188, 0.631713, 0.279542, 0.214596, 0.198958, 0.0390513, 139 0.124553, 1.06458, 0.0310522, 0.162975, 0.881639, 0.0719929, 0.480308, 2.45392, 140 0.0832422, 0.381514, 0.854485, 0.320597, 0.400822, 0.451124, 0.0869637, 0.154936, 141 2.10414, 0.067443, 0.508952, 3.1554, 0.255092, 0.887458, 0.428648, 0.0992829, 142 0.294481, 1.14516, 0.184545, 0.40117, 3.94646, 0.877057, 4.81956, 0.514347, 0.233527, 143 5.30821, 1.00122, 0.0848492, 1.12717, 3.9337, 0.527321, 2.88102, 0.144354, 0.198404, 144 1.51861, 0.109081, 0.444152, 0.720567, 0.165205, 0.254626, 0.722123, 0.111722, 0.588203, 145 0.422851, 0.179858, 0.204905, 1.03344, 0.0999068, 0.657364, 5.6037, 0.109241, 0.346823, 146 4.87366, 0.125999, 4.19125, 0.873266, 1.64018, 1.62299, 0.913179, 0.589718, 0.568449, 147 0.159054, 0.443685, 0.122792, 0.629768, 2.31211, 0.187262, 5.74119, 0.51821, 0.660816, 148 0.67416, 0.711498, 3.02808, 3.52499, 1.35221, 1.09965, 0.822025, 0.563999, 1.33618, 149 0.876688, 0.321774, 1.05314, 0.351913, 0.554077, 3.90127, 1.54694, 0.87908, 1.35611, 150 2.24161, 0.522957, 0.395176, 0.889765, 0.188237, 0.236489, 0.54992, 1.48876, 1.45173, 151 0.351564, 1.56873, 2.06787, 0.802531, 0.829315, 0.594177, 4.02507, 1.92496, 1.10899, 152 0.155419, 0.588443, 0.653015, 0.190095, 0.119749, 7.48376, 0.300343, 1.82105, 2.03324, 153 0.193323, 0.325745, 0.32893, 0.282892, 0.23769, 1.4088, 0.135395, 0.728065, 0.142159, 154 0.176397, 1.58681, 0.366467, 0.261223, 0.259584, 0.159261, 0.706082, 0.565299, 0.0746093, 155 0.135024, 0.208163, 1.24086, 0.528249, 0.118584, 0.396884, 0.270321, 0.481954, 0.326191, 156 0.209621, 6.49269, 0.108982, 4.31772, 0.44009, 0.155623, 0.427718, 0.437069, 1.05269, 157 0.212945, 0.210494, 0.386714, 0.742154, 0.286443, 0.353358, 2.42261 158 }; 159 static const double p[20] = { 160 0.0866279, 0.0193078, 0.0570451, 0.0580589, 0.0384319, 0.0832518, 0.0244313, 0.048466, 161 0.0620286, 0.086209, 0.0195027, 0.0390894, 0.0457631, 0.0367281, 0.043972, 0.0695179, 162 0.0610127, 0.0708956, 0.0143859, 0.0352742 163 }; 164 if(first2 != last2) { //+F model 165 return create_aagtr("wagstar+f", &s[0], &s[190], first2, last2); 166 } 167 return create_aagtr("wagstar", &s[0], &s[190], &p[0], &p[20]); 168 } 130 169 131 170 } // namespace dawg -
current/src/include/dawg/details/subst_dna.h
r564 r568 10 10 // name, followed by params, then freqs 11 11 template<typename It1, typename It2> 12 bool subst_model::create_gtr(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2) {12 bool subst_model::create_gtr(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2) { 13 13 double d = 0.0; 14 14 int u = 0; 15 15 _model = residue_exchange::DNA; 16 16 // do freqs first 17 if(!create_freqs( rname, first2, last2, &freqs[0], &freqs[4]))17 if(!create_freqs(mod_name, first2, last2, &freqs[0], &freqs[4])) 18 18 return false; 19 19 … … 81 81 table[i][3] = 1.0; 82 82 } 83 name = rname;83 name = mod_name; 84 84 do_op_f = &subst_model::do_gtr_f; 85 85 do_op_s = &subst_model::do_gtr_s; … … 89 89 90 90 template<typename It1, typename It2> 91 bool subst_model::create_jc(const std::string &, It1 first1, It1 last1, It2 first2, It2 last2) {91 bool subst_model::create_jc(const char *, It1 first1, It1 last1, It2 first2, It2 last2) { 92 92 // equal rates and frequencies 93 93 static const double ones[6] = {1.0,1.0,1.0,1.0,1.0,1.0}; … … 95 95 } 96 96 template<typename It1, typename It2> 97 bool subst_model::create_f81(const std::string &, It1 first1, It1 last1, It2 first2, It2 last2) {97 bool subst_model::create_f81(const char *, It1 first1, It1 last1, It2 first2, It2 last2) { 98 98 // equal rates and frequencies 99 99 static const double ones[6] = {1.0,1.0,1.0,1.0,1.0,1.0}; … … 101 101 } 102 102 template<typename It1, typename It2> 103 bool subst_model::create_k2p(const std::string &, It1 first1, It1 last1, It2 first2, It2 last2) {103 bool subst_model::create_k2p(const char *, It1 first1, It1 last1, It2 first2, It2 last2) { 104 104 // equal rates and frequencies 105 105 static const double ones[4] = {1.0,1.0,1.0,1.0}; … … 115 115 } 116 116 template<typename It1, typename It2> 117 bool subst_model::create_tn(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2) {117 bool subst_model::create_tn(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2) { 118 118 double p[6], f[4], fr, fy, d, ay, ar, b; 119 119 int u; … … 121 121 d = 0.0; 122 122 // read frequencies 123 if(!create_freqs( rname, first2, last2, &f[0], &f[4]))123 if(!create_freqs(mod_name, first2, last2, &f[0], &f[4])) 124 124 return false; 125 125 fr = f[0]+f[2]; 126 126 fy = f[1]+f[3]; 127 127 if(first1 == last1) 128 return DAWG_ERROR("Invalid subst model; tn requires two or three parameters.");128 return DAWG_ERROR("Invalid subst model; " << mod_name << " tn requires two or three parameters."); 129 129 ay = *first1++; 130 130 if(first1 == last1) 131 return DAWG_ERROR("Invalid subst model; tn requires two or three parameters.");131 return DAWG_ERROR("Invalid subst model; " << mod_name << " tn requires two or three parameters."); 132 132 ar = *first1++; 133 133 if(first1 == last1) { … … 148 148 p[4] = ay; 149 149 p[0] = p[2] = p[3] = p[5] = b; 150 return create_gtr( rname, &p[0], &p[6], &f[0], &f[4]);151 } 152 153 template<typename It1, typename It2> 154 bool subst_model::create_tn_f04(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2) {150 return create_gtr(mod_name, &p[0], &p[6], &f[0], &f[4]); 151 } 152 153 template<typename It1, typename It2> 154 bool subst_model::create_tn_f04(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2) { 155 155 double p[6], f[4], fr, fy, d, ay, ar, b; 156 156 int u; … … 158 158 d = 0.0; 159 159 // read frequencies 160 if(!create_freqs( rname, first2, last2, &f[0], &f[4]))160 if(!create_freqs(mod_name, first2, last2, &f[0], &f[4])) 161 161 return false; 162 162 fr = f[0]+f[2]; 163 163 fy = f[1]+f[3]; 164 164 if(first1 == last1) 165 return DAWG_ERROR("Invalid subst model; tn-f04requires two or three parameters.");165 return DAWG_ERROR("Invalid subst model; " << mod_name << " requires two or three parameters."); 166 166 ay = *first1++; 167 167 if(first1 == last1) 168 return DAWG_ERROR("Invalid subst model; tn-f04requires two or three parameters.");168 return DAWG_ERROR("Invalid subst model; " << mod_name << " requires two or three parameters."); 169 169 ar = *first1++; 170 170 if(first1 == last1) { … … 182 182 p[4] = ay/fy+b; 183 183 p[0] = p[2] = p[3] = p[5] = b; 184 return create_gtr( rname, &p[0], &p[6], &f[0], &f[4]);185 } 186 187 template<typename It1, typename It2> 188 bool subst_model::create_f84(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2) {184 return create_gtr(mod_name, &p[0], &p[6], &f[0], &f[4]); 185 } 186 187 template<typename It1, typename It2> 188 bool subst_model::create_f84(const char *, It1 first1, It1 last1, It2 first2, It2 last2) { 189 189 double p[3]; 190 190 if(first1 == last1) … … 203 203 204 204 template<typename It1, typename It2> 205 bool subst_model::create_hky(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2) {205 bool subst_model::create_hky(const char *, It1 first1, It1 last1, It2 first2, It2 last2) { 206 206 double p[3]; 207 207 if(first1 == last1) -
current/src/include/dawg/indel.h
r520 r568 75 75 } 76 76 boost::uint32_t do_user(mutt &m) const { 77 return std::distance(udata.begin(), std::lower_bound( 78 udata.begin(), udata.end(), m())); 77 return search_binary_cont(udata.begin(), udata.end(), m()); 79 78 } 80 79 … … 156 155 p /= d; 157 156 } 157 udata.back() = 1.0; 158 udata.resize(upper_binary(udata.size()), 1.0); 159 158 160 name = "user"; 159 udata.back() = 1.0;160 161 do_op = &dawg::indel_model::do_user; 161 mean = n / d; 162 return true; 163 } 164 165 162 mean = m / d; 163 return true; 164 } 165 166 166 std::string name; 167 167 double qorz, mean; -
current/src/include/dawg/subst.h
r567 r568 34 34 35 35 template<typename It1, typename It2> 36 bool create(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2);36 bool create(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2); 37 37 38 38 private: … … 55 55 } 56 56 inline base_type do_aagtr_f(mutt &m) const { 57 return search_binary_cont(&freqs[0], &freqs[ 20], m());57 return search_binary_cont(&freqs[0], &freqs[32], m()); 58 58 } 59 59 inline base_type do_aagtr_s(mutt &m, base_type n) const { 60 return search_binary_cont(&table[n][0], &table[n][ 20], m());60 return search_binary_cont(&table[n][0], &table[n][32], m()); 61 61 } 62 62 63 // DNA Models 63 64 template<typename It1, typename It2> 64 bool create_freqs(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2) const;65 bool create_freqs(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2) const; 65 66 66 67 template<typename It1, typename It2> 67 bool create_gtr(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2);68 bool create_gtr(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2); 68 69 69 70 template<typename It1, typename It2> 70 bool create_jc(const std::string &, It1 first1, It1 last1, It2 first2, It2 last2);71 bool create_jc(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2); 71 72 72 73 template<typename It1, typename It2> 73 bool create_f81(const std::string &, It1 first1, It1 last1, It2 first2, It2 last2);74 bool create_f81(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2); 74 75 75 76 template<typename It1, typename It2> 76 bool create_k2p(const std::string &, It1 first1, It1 last1, It2 first2, It2 last2);77 bool create_k2p(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2); 77 78 78 79 template<typename It1, typename It2> 79 bool create_tn(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2);80 bool create_tn(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2); 80 81 81 82 template<typename It1, typename It2> 82 bool create_tn_f04(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2);83 bool create_tn_f04(const char *mod_namee, It1 first1, It1 last1, It2 first2, It2 last2); 83 84 84 85 template<typename It1, typename It2> 85 bool create_f84(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2);86 bool create_f84(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2); 86 87 87 88 template<typename It1, typename It2> 88 bool create_hky(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2); 89 bool create_hky(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2); 90 91 // Protein Models 92 template<typename It1, typename It2> 93 bool create_aagtr(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2); 89 94 90 95 template<typename It1, typename It2> 91 bool create_ aagtr(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2);96 bool create_wag(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2); 92 97 93 98 template<typename It1, typename It2> 94 bool create_wag(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2); 95 96 template<typename It1, typename It2> 97 bool create_wagstar(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2); 99 bool create_wagstar(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2); 98 100 }; 99 101 100 102 template<typename It1, typename It2> 101 bool subst_model::create(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2) { 102 static std::string name_keys[] = { 103 std::string("jc"), std::string("gtr"), 104 std::string("k2p"), std::string("hky"), 105 std::string("f84"), std::string("f81"), 106 std::string("tn"), std::string("tn-f04"), 107 std::string("wag"), std::string("wagstar") 103 bool subst_model::create(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2) { 104 static const char name_keys[][10] = { 105 "jc", "gtr", "k2p", "hky", "f84", "f81", "tn", "tn-f04", 106 "aagtr", "wag", "wagstar" 108 107 }; 109 switch(key_switch(rname, name_keys)) { 110 case 0: 111 return create_jc("jc", first1, last1, first2, last2); 112 case 1: 113 return create_gtr("gtr", first1, last1, first2, last2); 114 case 2: 115 return create_k2p("k2p", first1, last1, first2, last2); 116 case 3: 117 return create_hky("hky", first1, last1, first2, last2); 118 case 4: 119 return create_f84("f84", first1, last1, first2, last2); 120 case 5: 121 return create_f81("f81", first1, last1, first2, last2); 122 case 6: 123 return create_tn("tn", first1, last1, first2, last2); 124 case 7: 125 return create_tn_f04("tn-f04", first1, last1, first2, last2); 126 case 8: 127 return create_wag("wag", first1, last1, first2, last2); 108 109 static bool (subst_model::*create_ops[])(const char *, It1, It1, It2, It2) = { 110 &subst_model::create_jc, &subst_model::create_gtr, &subst_model::create_k2p, 111 &subst_model::create_hky, &subst_model::create_f84, &subst_model::create_f81, 112 &subst_model::create_tn, &subst_model::create_tn_f04, 113 &subst_model::create_aagtr, &subst_model::create_wag, &subst_model::create_wagstar, 128 114 }; 129 return DAWG_ERROR("Invalid subst model; no model named '" << rname << "'"); 115 std::size_t pos = key_switch(mod_name, name_keys); 116 if(pos == (std::size_t)-1) 117 return DAWG_ERROR("Invalid subst model; no model named '" << mod_name << "'"); 118 return (this->*create_ops[pos])(name_keys[pos], first1, last1, first2, last2); 130 119 } 131 120 132 121 template<typename It1, typename It2> 133 bool subst_model::create_freqs(const std::string &rname, It1 first1, It1 last1, It2 first2, It2 last2) const {122 bool subst_model::create_freqs(const char *mod_name, It1 first1, It1 last1, It2 first2, It2 last2) const { 134 123 It2 result = first2; 135 124 double d=0.0; 136 125 for(int u=0;first1 != last1 && result != last2;++first1,++result,++u) { 137 126 if(*first1 < 0) 138 return DAWG_ERROR("Invalid subst model; " << rname << "frequency #" << u127 return DAWG_ERROR("Invalid subst model; " << mod_name << "frequency #" << u 139 128 << " '" << *first1 << "' is not >= 0."); 140 129 d += *first1; … … 142 131 } 143 132 if(result != last2) 144 return DAWG_ERROR("Invalid subst model; " << rname << " requires "133 return DAWG_ERROR("Invalid subst model; " << mod_name << " requires " 145 134 << std::distance(first2, last2) << " frequencies."); 146 135 for(;first2 != last2;++first2) -
current/src/include/dawg/utils.h
r558 r568 7 7 8 8 #include <boost/algorithm/string/predicate.hpp> 9 #include <boost/cstdint.hpp> 9 10 10 11 namespace dawg { 11 12 /*13 template<std::size_t _N>14 std::size_t key_switch(const std::string &ss, const std::string (&key)[_N]) {15 using boost::algorithm::starts_with;16 for(std::size_t i=0;i<_N;++i) {17 if(starts_with(key[i], ss))18 return i;19 }20 return (std::size_t)-1;21 }22 */23 12 24 13 template<class A, class B, std::size_t _N> … … 47 36 } 48 37 38 inline boost::uint32_t upper_binary(boost::uint32_t u) { 39 u--; 40 u |= u >> 1; 41 u |= u >> 2; 42 u |= u >> 4; 43 u |= u >> 8; 44 u |= u >> 16; 45 u++; 46 return u; 47 } 48 49 inline boost::uint64_t upper_binary(boost::uint64_t u) { 50 u--; 51 u |= u >> 1; 52 u |= u >> 2; 53 u |= u >> 4; 54 u |= u >> 8; 55 u |= u >> 16; 56 u |= u >> 32; 57 u++; 58 return u; 59 } 60 49 61 } /* namespace dawg */ 50 62 -
current/src/lib/matic.cpp
r563 r568 38 38 39 39 // construct models 40 if(!info->sub_mod.create(ma.subst_model ,40 if(!info->sub_mod.create(ma.subst_model.c_str(), 41 41 ma.subst_params.begin(), ma.subst_params.end(), 42 42 ma.subst_freqs.begin(), ma.subst_freqs.end())) … … 193 193 align(aln, seqs, configs[0].rex); 194 194 } 195 195 196 196 foreach(const segment &seg, configs) { 197 197 if(seg.empty()) -
current/src/lib/output.cpp
r562 r568 20 20 typedef boost::iterator_range<const char*> cs_range; 21 21 22 format_id = 0;22 set_format("aln"); 23 23 cs_range format(file_name, file_name); 24 24 if(file_name != NULL && file_name[0] != '\0') { … … 40 40 << std::string(format.begin(), format.end()) << "\'."); 41 41 } 42 } 42 }; 43 43 if(file_name != NULL && file_name[0] != '\0' 44 44 && strcmp(file_name, "-") != 0) {
Note: See TracChangeset
for help on using the changeset viewer.
