/*************************************************************************** nevermind_mod.cpp - description ------------------- begin : Tue Feb 10 09:39:51 2009 copyright : (C) 1999-2008 by Cavalli Andrea email : cavalli@bioc.unizh.ch **************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include using namespace Almost; typedef map cs_map; typedef map::iterator cs_map_iter; typedef pair int_p; struct ConnType { int first; int second; int spect; int peak; int kind; enum { ONE_TWO, ONE_THREE, ONE_FOUR, NOE}; ConnType(int f, int s, int sp, int p): first(f),second(s),spect(sp),peak(p),kind(NOE){} ConnType(int f, int s,int k): first(f),second(s),spect(-1),peak(-1),kind(k){} }; bool operator<(const ConnType &t1 , const ConnType & t2){ if(t1.kindt2.kind) return false; if(t1.spectt2.spect) return false; if(t1.peakt2.peak) return false; if(t1.firstt2.first) return false; if(t1.secondt2.second) return false; return false; } struct Peak2D { double Vol; double Vol2; double W[2]; map cs_a; map cs_b; //Flat assignment vector a; vector b; void generate_assignments(){ a.clear(); b.clear(); for(cs_map_iter a_iter = cs_a.begin(); a_iter!= cs_a.end(); ++a_iter){ for(cs_map_iter b_iter = cs_b.begin(); b_iter!=cs_b.end(); ++b_iter){ a.push_back(a_iter->first); b.push_back(b_iter->first); } } cout<<">> Generated "<> "< peak; }; struct NeverMind { vector spect; int mode; Protein p; vector seq; Protein p_ref; vector > mat_12; vector > mat_13; vector > mat_14; //Dist rest map, double> Upper; map, double> Lower; enum { C19, C22, IUPAC }; NeverMind(string name,int m):mode(m),p(name),p_ref(name){} void read_sequence(const char * file){ seq.clear(); ifstream in(file); if(!in){ string error = string("\t>> FATAL ERROR: unable to open file: ")+file +string("\n"); cout<>s; if(s.size()<3) continue; ss>>n; n="_"+n; if(s.size()==3) seq.push_back(s+n); else if(s.size()>3) seq.push_back(string(s.begin(),s.begin()+3)+n); else { cout<<"\t>> Error in reading sequence file: "<> Error in reading sequence"; } } string mdb_file; if(mode==C19) mdb_file = "all19_eef1.mdb"; if(mode==C22) mdb_file = "all22.mdb"; if(mode==IUPAC) mdb_file = "a03.mdb"; MDB mdb(mdb_file.c_str()); p.build_sequ(seq,mdb,"DEFAULT","DEFAULT"); // mat_12.resize(pp.atom_size()); for(int i=0;i> Read "< > cmap; map > nw; map,set > > > ind_nw; //1-2 bonds for(int a = 0; a >::iterator a_iter = cmap.begin(), a_end = cmap.end(); while(a_iter!=a_end){ int a = a_iter->first; set::iterator b_iter = a_iter->second.begin(), b_end = a_iter->second.end(); while(b_iter!=b_end){ int b = *b_iter; //now thak set::iterator c_iter = cmap[b].begin(), c_end = cmap[b].end(); while(c_iter!=c_end){ int c = *c_iter; if(c==a){ ++c_iter; continue;} if(c==b){ ++c_iter; continue;} pair,set > pp(nw[int_p(a,b)],nw[int_p(b,c)]); ind_nw[int_p(a,c)].insert(pp); ++c_iter; } ++b_iter; } ++a_iter; } } //Dump ofstream out; out.open("nevermind.dump"); { for(int s = 0; s::iterator iter = nw[ab].begin(), end = nw[ab].end(); out<<"\t"<first<<" "<second<<" "; out<kind<<" "; out<peak<<" "<spect<<" "; out<<") "; ++iter; } // out<<"\n"; //Indirect { set,set > >::iterator ind_iter = ind_nw[ab].begin(), ind_end = ind_nw[ab].end(); double P = 1; while(ind_iter!=ind_end){ // cout<<"Indirect "<first.begin()->kind==ConnType::NOE) pp = 0.01; else pp = 0.5; if(ind_iter->second.begin()->kind==ConnType::NOE) pp *= 0.01; else pp *=0.5; P *= (1-pp); // out<<"( "<first.begin()->first<<" " // <first.begin()->second<<" " // <first.begin()->kind<<") " // ; // out<<"( "<second.begin()->first<<" " // <second.begin()->second<<" " // <second.begin()->kind<<") " // ; // out<> Prob: "<<1-P<<" "<first.begin()->first<<" " <first.begin()->second<<" " <first.begin()->kind<<") " ; out<<"( "<second.begin()->first<<" " <second.begin()->second<<" " <second.begin()->kind<<") " ; out<<"\n"; ++ind_iter; } } } } } } } } private: void read_shifts(const char * file, cs_map &cs){ ifstream in(file); if(!in){ string error = string("\t>> FATAL ERROR: unable to open file: ")+file +string("\n"); cout< lseq = p.sequence(Protein::LONG); while(in.good()){ char line[256]; in.getline(line,256); if(line[0]=='#'||in.gcount()<10) continue; stringstream ss(line); int id; double w; double err; string atm; int nres; ss>>id; ss>>w; ss>>err; ss>>atm; ss>>nres; --nres; cout<<"\t>> Chemical shift for atom "<> Atom not in protein\n"; } if(natm!=-1){ cs[natm] = w; cout<<"\t>> CS assignment "< & peak){ ifstream in(file); if(!in){ string error = string("\t>> FATAL ERROR: unable to open file: ")+file +string("\n"); cout<>id; ss>> p.W[0]; ss>> p.W[1]; ss>>id; ss>> c; ss>> p.Vol; ss>> p.Vol2; peak.push_back(p); } } void assign_peaks(Spect & s, double tol){ s.tol = tol; cs_map_iter iter= s.cs.begin(), end = s.cs.end(); while(iter!=end){ for(int i=0;isecond)first] = iter->second; if(abs(s.peak[i].W[1]-iter->second)first] = iter->second; } ++iter; } for(int i=0;i::iterator iter= s.peak.begin(), end = s.peak.end(); } } }; ZETATOSTRING(NeverMind); extern "C" { void init_nevermind(){ //declarations here Module mod = Module("nevermind","Nevermind"); Class >(mod.self(),"nevermind") .def_method("read_sequence",&NeverMind::read_sequence) .def_method("read_spect",&NeverMind::read_spect) .def_method("mk_pref",&NeverMind::mk_pref) .def_method("network",&NeverMind::network) ; mod .def_const("C19",(int)NeverMind::C19) .def_const("C22",(int)NeverMind::C22) .def_const("IUPAC",(int)NeverMind::IUPAC) ; } }