Changeset 138
- Timestamp:
- 11/08/09 20:30:15 (10 months ago)
- Location:
- current/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
current/src/align.cpp
r133 r138 44 44 double aligner::align(alignment &aln) 45 45 { 46 double d; 47 aln.data.clear(); 48 if(aln.seqA.dna.size() >= aln.seqB.dna.size()) 49 d = align_x(aln.seqA.dna, aln.seqB.dna, aln.data); 50 else 51 { 52 d = align_x(aln.seqB.dna, aln.seqA.dna, aln.data); 53 for(aln_data::iterator it = aln.data.begin(); it != aln.data.end(); ++it) 54 *it = -*it; 55 } 56 return d; 46 aln.data.clear(); 47 return align_x(aln.seqA.dna, aln.seqB.dna, aln.data); 57 48 } 58 49 -
current/src/align.h
r133 r138 40 40 41 41 template<class OS> 42 inline void print(OS &os, const char *msg=NULL ) const;42 inline void print(OS &os, const char *msg=NULL, int dir=0, bool swapped=false) const; 43 43 44 44 protected: … … 129 129 130 130 template<class OS> 131 inline void alignment::print(OS &os, const char *msg ) const131 inline void alignment::print(OS &os, const char *msg, int dir, bool swapped) const 132 132 { 133 std::string strA, strB, strC; 133 std::string strA, strB, strC, 134 nameA(seqA.name.substr(0, 14)), 135 nameB(seqB.name.substr(0, 14)); 136 //preallocate 137 strA.reserve(4048); 138 strB.reserve(4048); 139 strC.reserve(4048); 140 134 141 std::string::const_iterator ait = seqA.dna.begin(), bit = seqB.dna.begin(); 135 142 for(aln_data::const_iterator cit = data.begin(); cit != data.end(); ++cit) … … 154 161 } 155 162 } 156 163 if(swapped) { 164 swap(strA, strB); 165 swap(nameA, nameB); 166 } 167 seq_transform(strA, dir); 168 seq_transform(strB, dir); 169 seq_transform(strC, dir); 170 157 171 os << "CLUSTAL multiple sequence alignment (Created by " << PACKAGE_STRING; 158 172 if(msg != NULL) … … 169 183 ss = strA.substr(u, 60); 170 184 a += ss.length() - std::count(ss.begin(), ss.end(), chGap); 171 os << std::setw(14) << std::setiosflags(std::ios::left) << seqA.name.substr(0, 14)185 os << std::setw(14) << std::setiosflags(std::ios::left) << nameA 172 186 << " " << ss << " " << a << std::endl; 173 187 174 188 ss = strB.substr(u, 60); 175 189 b += ss.length() - std::count(ss.begin(), ss.end(), chGap); 176 os << std::setw(14) << std::setiosflags(std::ios::left) << seqA.name.substr(0, 14)190 os << std::setw(14) << std::setiosflags(std::ios::left) << nameB 177 191 << " " << ss << " " << b << std::endl; 178 192 … … 183 197 184 198 #endif 185 -
current/src/ngila.cpp
r137 r138 126 126 } 127 127 128 mydb.unique_sort(seq_db::DIR_ORI | (arg.const_align & 7)); 129 128 int direction = 0; 129 if(arg.const_align != 0) { 130 direction = mydb.unique_sort(seq_db::DIR_ORI | (arg.const_align & 7)); 131 mydb.transform(direction); 132 cerr << direction << endl; 133 if(!(arg.const_align & 8)) { // return to original order 134 mydb.rearrange(mydb.db().get<id>().begin()); 135 } 136 } 137 130 138 cost_model *pmod = NULL; 131 139 string model_keys[] = { string("zeta"), string("geo"), string("cost") }; … … 182 190 if(cit != pvec.begin()) 183 191 cout << "//" << endl; 184 alignment aln(mydb[cit->first], mydb[cit->second]); 192 // swap a and b so that a's hashed position is lower 193 size_t a = cit->first; 194 size_t b = cit->second; 195 bool swapped = false; 196 if(!(arg.const_align & 8) && mydb.db().project<hashid>(mydb.db().begin()+a) > 197 mydb.db().project<hashid>(mydb.db().begin()+b) ) { 198 swap(a,b); 199 swapped = true; 200 } 201 202 alignment aln(mydb[a], mydb[b]); 185 203 double dcost = alner.align(aln); 186 dcost += pmod->offset(mydb[ cit->first].dna,187 mydb[ cit->second].dna);204 dcost += pmod->offset(mydb[a].dna, 205 mydb[b].dna); 188 206 ostringstream msg; 189 207 msg << "Cost = " << setprecision(10) << dcost; 190 208 191 aln.print(cout, msg.str().c_str() );209 aln.print(cout, msg.str().c_str(), ((arg.const_align & 16) ? 0 : direction), swapped); 192 210 } 193 211 -
current/src/seqdb.cpp
r137 r138 115 115 complementer(sd.dna.rend())), DIR_RVC, sd)); 116 116 } 117 foreach(const hash_data &h, hc) {118 cerr << h.ref.get().name << "\t" << h.dir << "\t" << h.hashed << endl;119 }120 117 size_t hh = hc.begin()->hashed; 121 118 int dd = hc.begin()->dir, mask = -1; … … 142 139 static const int ties[] = { 8,1,2,1,4,1,2,1,8,8,8,8,8,8,8,8 }; 143 140 dd = ties[dd&15]; 144 // sort141 // sort 145 142 cont.rearrange(hc.get<1>().find(dd)); 143 // store this order 144 cont.get<hashid>().rearrange(cont.begin()); 146 145 return dd; 147 146 } 148 -
current/src/seqdb.h
r137 r138 35 35 #include <boost/functional/hash.hpp> 36 36 37 38 inline char complement(char x) { 39 static char dnac[] = "\0\x01\x02\x03\x04\x05\x06\a\b\t\n\x0b\f\r\x0e\x0f" 40 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" 41 " !\"#$%&'()*+,-./0123456789:;<=>?@" 42 "TVGHEFCDIJMLKNOPQYSAABWXRZ" "[\\]^_`" 43 "tvghefcdijmlknopqysaabwxrz" "{|}~\x7f"; 44 45 return dnac[x]; 46 } 47 37 48 template<class _Iterator> 38 49 class _complementer : public _Iterator { … … 42 53 43 54 value_type operator*() const { 44 static char dnac[] = "\0\x01\x02\x03\x04\x05\x06\a\b\t\n\x0b\f\r\x0e\x0f" 45 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" 46 " !\"#$%&'()*+,-./0123456789:;<=>?@" 47 "TVGHEFCDIJMLKNOPQYSAABWXRZ" "[\\]^_`" 48 "tvghefcdijmlknopqysaabwxrz" "{|}~\x7f"; 49 return value_type(dnac[**static_cast<const base_type*>(this)]); 55 return value_type(complement(**static_cast<const base_type*>(this))); 50 56 } 51 57 … … 57 63 return _complementer<_Iterator>(it); 58 64 } 65 66 class seq_db; 59 67 60 68 struct seq_data { … … 78 86 boost::bind(gf, g, _1, 0) != std::string::npos), 79 87 dna.end()); 88 return *this; 80 89 } 81 90 … … 85 94 std::transform(dna.begin(), dna.end(), dna.begin(), std::ptr_fun(::toupper)); 86 95 } 96 97 inline void transform(int dir); 87 98 }; 88 99 … … 95 106 public: 96 107 typedef boost::multi_index_container< seq_data, boost::multi_index::indexed_by< 97 boost::multi_index::random_access<>, 98 boost::multi_index::random_access<boost::multi_index::tag<id> >, 108 boost::multi_index::random_access<>, // current order 109 boost::multi_index::random_access<boost::multi_index::tag<id> >, // original order 110 boost::multi_index::random_access<boost::multi_index::tag<hashid> >, // hashed order 99 111 boost::multi_index::ordered_unique< 100 112 boost::multi_index::tag<name>, … … 137 149 cont.rearrange(it); 138 150 } 139 140 int unique_sort(int directions=DIR_ORI); 141 142 // void create_hashes(int directions=seq_data::DIR_ORI) { 143 // for(container::iterator it = cont.begin(); it != cont.end(); ++it) 144 // cont.modify(it, bind(&seq_data::create_hash, _1, directions)); 145 // } 151 152 void transform(int dir) { 153 for(container::iterator it = cont.begin(); it != cont.end(); ++it) 154 cont.modify(it, bind(&seq_data::transform, _1, dir)); 155 } 146 156 147 157 bool parse_file(const char *csfile, bool bappend=false, bool bi=false); 158 int unique_sort(int directions=DIR_ORI); 148 159 149 160 seq_db() : ss_gaps("-") { } … … 156 167 }; 157 168 169 inline void seq_transform(std::string& dna, int dir) { 170 switch(dir&7) { 171 default: 172 case 0: 173 break; 174 case seq_db::DIR_COM: 175 std::transform(dna.begin(), dna.end(), dna.begin(), complement); 176 break; 177 case seq_db::DIR_RVC: 178 case (seq_db::DIR_REV|seq_db::DIR_COM): 179 std::transform(dna.begin(), dna.end(), dna.begin(), complement); 180 case seq_db::DIR_REV: 181 std::reverse(dna.begin(), dna.end()); 182 break; 183 }; 184 } 185 186 inline void seq_data::transform(int dir) { 187 seq_transform(dna, dir); 188 } 158 189 159 190 #endif
Note: See TracChangeset
for help on using the changeset viewer.
