#include #include #include #include #include #include #include #include #include using namespace std; class Seg { public: int start; int end; double score; }; //searched region void make_Seg(const char* data_name, const char* vector_name, int dim, int M_L, int M_S, double threshold, const char* outfile_name, int chr, int window) { string line; ifstream fin; fin.open(data_name); if (!fin){ cout << "error : file not found" << endl; exit(1); } // if fin==0 file not exist ifstream fin2; fin2.open(vector_name); if (!fin2){ cout << "error : file not found" << endl; exit(1); } // if fin2==0 file not exist ofstream ofs; ofs.open(outfile_name, ios::out | ios::app); getline(fin2, line); vector v; //feature vector stringstream v_buf(line); for(int i=0; i> tmp; v.push_back(tmp); } // read vector file getline(fin, line); getline(fin, line); vector s_row;// score of each position //start calculating score of each position while(getline(fin, line)) //read data file { bool z = false; stringstream buf(line); double tmp; double score = 0; for(int i=0; i> tmp; if(tmp == 2) { z = true; } score += tmp*v[i]; } if(z) { s_row.push_back(-1); } else { s_row.push_back(score - threshold); } } //end calculating score of each position //start calculating weight sums vector s_0, l_0, s_1, l_1; //weight sums : w0_short, w0_long, w1_short, w1_long int L = 0; L = (int)s_row.size(); s_0.push_back(0); s_1.push_back(s_row[0]); l_0.push_back(-10000000); l_1.push_back(-10000000); for(int i=1; i l_1[i-1]) { s_0.push_back(s_0[i-1]); } else { s_0.push_back(l_1[i-1]); } if(s_1[i-1] > l_0[i-1]) { s_1.push_back(s_1[i-1] + s_row[i]); } else { s_1.push_back(l_0[i-1] + s_row[i]); } if(i >= M_S) { l_0.push_back(s_0[i-M_S+1]); } else { l_0.push_back(-10000000); } if(i >= M_L) { double tmp = 0; tmp = s_1[i-M_L+1]; for(int j=i-M_L + 2; j<=i; j++) { tmp += s_row[j]; } l_1.push_back(tmp); } else { l_1.push_back(-10000000); } } //end calculating weight sums //start tracing back and search regions vector Seg_row; //searched regions int tmp_n = -1; int type = 0; if(s_0[L-1] > l_1[L-1]) type = 1; else type = 4; int T = L-1; while(T > 0) { if(type == 1) { if(s_0[T-1] > l_1[T-1]) { type = 1; } else { type = 4; } T--; } else if(type == 2) { if(s_1[T-1] > l_0[T-1]) { Seg_row[tmp_n].score += s_row[T]; type = 2; } else { Seg_row[tmp_n].score += s_row[T]; Seg_row[tmp_n].start = T+1; type = 3; } T--; } else if(type == 3) { T = T - M_S + 1; type = 1; } else { Seg tmp_Seg; tmp_Seg.end = T+1; tmp_Seg.score = 0; for(int j = T; j> T-M_L+1; j--) { tmp_Seg.score += s_row[j]; } Seg_row.push_back(tmp_Seg); tmp_n++; type = 2; T = T - M_L+1; } } if(type == 2) { Seg_row[tmp_n].score += s_row[T]; Seg_row[tmp_n].start = 1; } //end tracing back and search regions for(int i=tmp_n; i>=0; i--) { ofs << chr << " " << (Seg_row[i].start-1)*window << " " << (Seg_row[i].end-1)*window << " " << Seg_row[i].score << endl; } return; } int main(int argc, char** argv) { int max = atoi(argv[3]); int window = 200; if(argc == 10) { window = atoi(argv[9]); } ofstream ofs; ofs.open(argv[8]); ofs.close(); for(int i=1; i