| 78 | |
| 79 | |
| 80 | void SNPinGenome::readSNPs(std::string const& inFile) |
| 81 | { |
| 82 | cout << "..Starting reading "<< inFile << " to get SNP positions" << std::endl; |
| 83 | |
| 84 | std::ifstream fileSNP (inFile.c_str()); |
| 85 | |
| 86 | if (!fileSNP.is_open()) { |
| 87 | cerr << "Error: unable to open "+inFile+"\n" ; |
| 88 | exit(-1); |
| 89 | } |
| 90 | SNP_atChr_ = new std::vector <SNPatChr>(); |
| 91 | |
| 92 | int count = 0; |
| 93 | string line; |
| 94 | |
| 95 | int index = 0; |
| 96 | string myChr = "1"; |
| 97 | SNP_atChr_->push_back(SNPatChr("1")); |
| 98 | |
| 99 | int previousPos = NA; |
| 100 | |
| 101 | #ifdef PROFILE_TRACE |
| 102 | time_t t0 = time(NULL); |
| 103 | #endif |
| 104 | |
| 105 | /*if (makingpileup != true)*/ |
| 106 | { |
| 107 | //check whether the file is compressed: |
| 108 | bool ifGZ = 0; |
| 109 | if (inFile.substr(inFile.size()-3,3).compare(".gz")==0){ifGZ=1;} |
| 110 | //check whether the file is in VCF format: |
| 111 | bool ifVCF = 0; |
| 112 | std::size_t found = inFile.find(".vcf"); |
| 113 | if (found!=std::string::npos) {ifVCF=1;} |
| 114 | |
| 115 | if (ifGZ) { |
| 116 | fileSNP.close(); |
| 117 | FILE *stream; |
| 118 | char buffer[MAX_BUFFER]; |
| 119 | string command = "gzip -cd "+inFile; |
| 120 | stream = |
| 121 | #if defined(_WIN32) |
| 122 | _popen(command.c_str(), "r"); |
| 123 | #else |
| 124 | popen(command.c_str(), "r"); |
| 125 | #endif |
| 126 | char *line_buffer; |
| 127 | while ((line_buffer = getLine(buffer, MAX_BUFFER, stream, line)) != NULL) { |
| 128 | if (line_buffer[0] == '#') continue; |
| 129 | count+=processSNPLine(ifVCF,line_buffer,myChr,index,previousPos); |
| 130 | } |
| 131 | #if defined(_WIN32) |
| 132 | _pclose(stream); |
| 133 | #else |
| 134 | pclose(stream); |
| 135 | #endif |
| 136 | } else { |
| 137 | while (std::getline(fileSNP,line)) { |