| 379 | } |
| 380 | |
| 381 | void SNPinGenome::assignValues(std::string const& inFile, string inputFormat, int minimalTotalLetterCountPerPosition, int minimalQualityPerPosition, GenomeCopyNumber* p_genomeCopyNumber) { |
| 382 | // vector <float> heterozygousBAFs; |
| 383 | // vector <float> heterozygousBAFs05; |
| 384 | // vector <int> heterozygousBAFposition; |
| 385 | |
| 386 | if ((inputFormat.compare("pileup")==0 || inputFormat.compare("SAMtools pileup")==0)){ |
| 387 | //cout << "..will not proceed with BAF profiles: wrong inputFormat \n"; |
| 388 | cout << "..use \"pileup\" format of reads to calculate BAF profiles\n"; |
| 389 | |
| 390 | cout << "..Starting reading "<< inFile << " to calculate BAF profiles" << std::endl; |
| 391 | #ifdef PROFILE_TRACE |
| 392 | time_t t0 = time(NULL); |
| 393 | #endif |
| 394 | |
| 395 | if (inFile.substr(inFile.size()-3,3).compare(".gz")==0) { |
| 396 | string command = "gzip -cd "+inFile; |
| 397 | FILE* stream = |
| 398 | #if defined(_WIN32) |
| 399 | _popen(command.c_str(), "r"); |
| 400 | #else |
| 401 | popen(command.c_str(), "r"); |
| 402 | #endif |
| 403 | readPileUP(stream, minimalTotalLetterCountPerPosition, minimalQualityPerPosition, p_genomeCopyNumber); |
| 404 | |
| 405 | #if defined(_WIN32) |
| 406 | _pclose(stream); |
| 407 | #else |
| 408 | pclose(stream); |
| 409 | #endif |
| 410 | |
| 411 | } else { |
| 412 | FILE *stream = fopen(inFile.c_str(), "r"); |
| 413 | if (!stream) { |
| 414 | cerr << "Error: unable to open " + inFile + "\n" ; |
| 415 | exit(-1); |
| 416 | } |
| 417 | readPileUP(stream, minimalTotalLetterCountPerPosition, minimalQualityPerPosition, p_genomeCopyNumber); |
| 418 | fclose(stream); |
| 419 | } |
| 420 | |
| 421 | #ifdef PROFILE_TRACE |
| 422 | std::cout << "PROFILING [tid=" << pthread_self() << "]: " << inFile << " read in " << (time(NULL)-t0) << " seconds [assignValues]\n" << std::flush; |
| 423 | #endif |
| 424 | |
| 425 | |
| 426 | //BEGIN TMP: |
| 427 | // std::vector<int> bpfinal; |
| 428 | // int tmp = calculateBreakpoints_general(-0.0001, heterozygousBAFs05.size(), heterozygousBAFs05, bpfinal, 0, 4); |
| 429 | // bpfinal.push_back(heterozygousBAFs05.size()); |
| 430 | // std::vector<float> medians; |
| 431 | // std::vector<float> medianBAFs; |
| 432 | // |
| 433 | // int start = 0; |
| 434 | // for (int i = 0; i<bpfinal.size(); i++) { |
| 435 | // float localMedian = get_median(heterozygousBAFs05, start, bpfinal[i]); |
| 436 | // medians.push_back(localMedian); |
| 437 | // for (int j = start; j<bpfinal[i];j++) { |
| 438 | // medianBAFs.push_back(localMedian+0.5); |