| 60 | } |
| 61 | |
| 62 | float BAFpileup::calculateFlankLength(std::string const& mateFileName, std::string const& inputFormat_str, std::string const& matesOrientation_str, std::string pathToSamtools_, std::string pathToSambamba, std::string SambambaThreads) |
| 63 | { |
| 64 | if (matesOrientation_str=="0") return 0; // do not add anything in case of single end data |
| 65 | if (getInputFormat(inputFormat_str)!=SAM_INPUT_FORMAT) return 0; |
| 66 | std::ifstream fileMates (mateFileName.c_str()); |
| 67 | vector<float> insertSizeVector; |
| 68 | string line; |
| 69 | if (!fileMates.is_open()) { |
| 70 | cerr << "Error: unable to open "+mateFileName+"\n" ; |
| 71 | exit(-1); |
| 72 | } |
| 73 | fileMates.close(); |
| 74 | |
| 75 | #ifdef PROFILE_TRACE |
| 76 | time_t t0 = time(NULL); |
| 77 | #endif |
| 78 | |
| 79 | // MateOrientation matesOrientation = getMateOrientation(matesOrientation_str); // will not consider read orientation to increase speed |
| 80 | char* line_buffer; |
| 81 | FILE *stream; |
| 82 | char buffer[MAX_BUFFER]; |
| 83 | bool zgOrbam=0; |
| 84 | |
| 85 | int numberOfReadsToCheck=3000000; |
| 86 | int j = 0; |
| 87 | int fragmentLength=0; |
| 88 | if(mateFileName.substr(mateFileName.size()-3,3).compare("bam")==0 || mateFileName.substr(mateFileName.size()-3,3).compare(".gz")==0) { |
| 89 | string command; |
| 90 | if (mateFileName.substr(mateFileName.size()-3,3).compare("bam")==0) { |
| 91 | if (pathToSambamba != "") { |
| 92 | command = pathToSambamba + " view -t " + SambambaThreads + " " + mateFileName; |
| 93 | } else { |
| 94 | command = pathToSamtools_ + " view "+mateFileName; |
| 95 | } |
| 96 | } |
| 97 | if (mateFileName.substr(mateFileName.size()-3,3).compare(".gz")==0) { |
| 98 | command = "gzip -c -d "+mateFileName; |
| 99 | } |
| 100 | stream = |
| 101 | #if defined(_WIN32) |
| 102 | _popen(command.c_str(), "r"); |
| 103 | #else |
| 104 | popen(command.c_str(), "r"); |
| 105 | #endif |
| 106 | zgOrbam=1; |
| 107 | |
| 108 | while (((line_buffer = getLine(buffer, MAX_BUFFER, stream, line)) != NULL) && j<numberOfReadsToCheck) { |
| 109 | if (line_buffer[0] == '@') |
| 110 | continue; |
| 111 | |
| 112 | char* strs[32]; |
| 113 | unsigned int strs_cnt = split((char*)line_buffer, '\t', strs); |
| 114 | |
| 115 | if (strs_cnt > 8 && strs[6][0]=='=') { |
| 116 | int frLen=atoi(strs[8]); |
| 117 | if(frLen>0 && frLen< 10000) { |
| 118 | fragmentLength+=frLen; |
| 119 | j++; |
nothing calls this directly
no test coverage detected