| 243 | } |
| 244 | |
| 245 | std::string BAFpileup::intersectWithBedtools(std::string makeminipileup, std::string outputDir, std::string bedFileWithRegionsOfInterest, std::string chrLen) |
| 246 | { |
| 247 | FILE *stream; |
| 248 | std::string intersected = outputDir + "_SNPinNewCaptureRegions.bed"; |
| 249 | |
| 250 | if (makeminipileup.substr(makeminipileup.size()-3,3).compare("vcf")==0 || makeminipileup.substr(makeminipileup.size()-6,6).compare("vcf.gz")==0) { |
| 251 | intersected = outputDir + "_SNPinNewCaptureRegions.vcf"; |
| 252 | } |
| 253 | |
| 254 | string command = pathToBedtools_ +" intersect -a " + makeminipileup + " -b " + bedFileWithRegionsOfInterest + " > " + intersected; |
| 255 | |
| 256 | stream = |
| 257 | #if defined(_WIN32) |
| 258 | _popen(command.c_str(), "w"); |
| 259 | #else |
| 260 | popen(command.c_str(), "w"); |
| 261 | #endif |
| 262 | |
| 263 | #if defined(_WIN32) |
| 264 | _pclose(stream); |
| 265 | #else |
| 266 | pclose(stream); |
| 267 | #endif |
| 268 | |
| 269 | remove(bedFileWithRegionsOfInterest.c_str()); |
| 270 | |
| 271 | if (makeminipileup.substr(makeminipileup.size()-3,3).compare("bed")==0) { |
| 272 | return intersected; |
| 273 | } |
| 274 | |
| 275 | //else: VCF input format; need to transform into BED |
| 276 | ifstream file (intersected.c_str()); |
| 277 | ofstream myfile; |
| 278 | std::string intersectedBed = outputDir + "_SNPinNewCaptureRegions.bed"; |
| 279 | myfile.open(intersectedBed.c_str()); |
| 280 | std:: string line; |
| 281 | int nb_snp = 0; |
| 282 | while (std::getline(file,line)) { |
| 283 | nb_snp++; |
| 284 | std::vector<std::string> strs = split(line, '\t'); |
| 285 | myfile << strs[0] << "\t"<< atoi(strs[1].c_str()) -1 << "\t" << atoi(strs[1].c_str()) << "\t" << strs[3] << "\t" << strs[4]<<"\n"; |
| 286 | } |
| 287 | cout << "..will use "<<nb_snp<<" SNPs for calculation of the BAF profile\n"; |
| 288 | myfile.close(); |
| 289 | file.close(); |
| 290 | remove(intersected.c_str()); |
| 291 | return intersectedBed; |
| 292 | } |
| 293 | |
| 294 | std::string BAFpileup::createPileUpFile(std::string outputDir, std::string samtools_path, std::string pathToSambamba,std::string SambambaThreads , std::string control_MateFile, std::string intersected, std::string fastaFile, int minQualPerPos) |
| 295 | { |