| 297 | |
| 298 | |
| 299 | void readFileWithGenomeInfo(const std::string &chrLenFileName, std::vector<std::string>& names, std::vector<int>& lengths) { |
| 300 | //reading the file with genome information |
| 301 | ifstream file(chrLenFileName.c_str()); |
| 302 | if (!file.is_open()) { |
| 303 | cerr << "Error: unable to open "+chrLenFileName+"\n" ; |
| 304 | exit(-1); |
| 305 | |
| 306 | } |
| 307 | string line; |
| 308 | string name; |
| 309 | int value = 0; |
| 310 | bool isFai=0; |
| 311 | if (chrLenFileName.substr(chrLenFileName.length()-3,3).compare("fai")==0) {isFai=1;} |
| 312 | while (std::getline(file,line)) { |
| 313 | |
| 314 | if (! line.length()) continue; |
| 315 | if (line[0] == '#') continue; |
| 316 | |
| 317 | std::vector<std::string> strs = split(line, '\t'); |
| 318 | if (strs.size()<2) { |
| 319 | cerr << "uncorrect file with chromosomes "<< chrLenFileName <<"\nUse tab-delimited format:\n1\tchr1\t249250621\nor\nchr1\t249250621\n"; |
| 320 | } |
| 321 | if (strs.size()==2 || strs[0].substr(0,3)=="chr" || isFai) { |
| 322 | name = strs[0]; |
| 323 | value = atoi(strs[1].c_str()); |
| 324 | } |
| 325 | if (strs.size()>=3 && strs[0].substr(0,3)!="chr" && !isFai) { |
| 326 | name = strs[1]; |
| 327 | value = atoi(strs[2].c_str()); |
| 328 | } |
| 329 | strs.clear(); |
| 330 | myReplace(name, " ", ""); |
| 331 | |
| 332 | //delete "Chr" |
| 333 | string::size_type pos = 0; |
| 334 | if ( (pos = name.find("chr", pos)) != string::npos ) |
| 335 | name.replace( pos, 3, "" ); |
| 336 | if (value>0) { |
| 337 | names.push_back(name); |
| 338 | lengths.push_back(value); |
| 339 | //cout << name << "\t" << value << "\n"; |
| 340 | } |
| 341 | |
| 342 | } |
| 343 | file.close(); |
| 344 | cout << "..File "<<chrLenFileName<<" was read\n"; |
| 345 | } |
| 346 | unsigned long sum(const std::vector<int>& data) { |
| 347 | unsigned long sum = 0; |
| 348 | for (int i=0; i< (int) data.size(); i++) { |
no test coverage detected