X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=extractRef.cpp;h=fb7d3ecb586d36e586d8698a9f4c94bc0ec4cc46;hb=dbcf1cfb8ad1086c21d64e249f012809403e7ddc;hp=da0effc70e3c3fe25925c615d30e40f2c15b55eb;hpb=64cbcf77f3d0a6d8dea12d4c2a6500399d9bd2a2;p=rsem.git diff --git a/extractRef.cpp b/extractRef.cpp index da0effc..fb7d3ec 100644 --- a/extractRef.cpp +++ b/extractRef.cpp @@ -50,24 +50,24 @@ map mi_table; // mapping info table map::iterator mi_iter; //mapping info table's iterator void loadMappingInfo(char* mappingF) { - ifstream fin(mappingF); - string line, key, value; - - if (!fin.is_open()) { - fprintf(stderr, "Cannot open %s! It may not exist.\n", mappingF); - exit(-1); - } - - mi_table.clear(); - while (getline(fin, line)) { - line = cleanStr(line); - if (line[0] == '#') continue; - istringstream strin(line); - strin>>value>>key; - mi_table[key] = value; - } - - fin.close(); + ifstream fin(mappingF); + string line, key, value; + + if (!fin.is_open()) { + fprintf(stderr, "Cannot open %s! It may not exist.\n", mappingF); + exit(-1); + } + + mi_table.clear(); + while (getline(fin, line)) { + line = cleanStr(line); + if (line[0] == '#') continue; + istringstream strin(line); + strin>>value>>key; + mi_table[key] = value; + } + + fin.close(); } bool buildTranscript(int sp, int ep) { @@ -134,14 +134,14 @@ void parse_gtf_file(char* gtfF) { else { if (hasMappingFile) { tid = item.getTranscriptID(); - mi_iter = mi_table.find(tid); - if (mi_iter == mi_table.end()) { - fprintf(stderr, "Mapping Info is not correct, cannot find %s's gene_id!\n", tid.c_str()); - exit(-1); - } - //assert(iter != table.end()); - gid = mi_iter->second; - item.setGeneID(gid); + mi_iter = mi_table.find(tid); + if (mi_iter == mi_table.end()) { + fprintf(stderr, "Mapping Info is not correct, cannot find %s's gene_id!\n", tid.c_str()); + exit(-1); + } + //assert(iter != table.end()); + gid = mi_iter->second; + item.setGeneID(gid); } items.push_back(item); } @@ -260,7 +260,6 @@ int main(int argc, char* argv[]) { ifstream fin; string line, gseq, seqname; - void* pt; chrvec.clear(); @@ -270,31 +269,31 @@ int main(int argc, char* argv[]) { for (int i = start; i < argc; i++) { fin.open(argv[i]); if (!fin.is_open()) { fprintf(stderr, "Cannot open %s! It may not exist.\n", argv[i]); exit(-1); } - pt = getline(fin, line); - while (pt != 0 && line[0] == '>') { + getline(fin, line); + while ((fin) && (line[0] == '>')) { istringstream strin(line.substr(1)); strin>>seqname; gseq = ""; - while((pt = getline(fin, line)) && line[0] != '>') { - gseq += line; - } - - size_t len = gseq.length(); - assert(len > 0); - for (size_t j = 0; j < len; j++) gseq[j] = check(gseq[j]); - - iter = sn2tr.find(seqname); - if (iter == sn2tr.end()) continue; - - chrvec.push_back(ChrInfo(seqname, len)); - - vector& vec = iter->second; - int s = vec.size(); - for (int j = 0; j < s; j++) { - assert(vec[j] > 0 && vec[j] <= M); - transcripts.getTranscriptAt(vec[j]).extractSeq(gseq, seqs[vec[j]]); - } + while((getline(fin, line)) && (line[0] != '>')) { + gseq += line; + } + + size_t len = gseq.length(); + assert(len > 0); + for (size_t j = 0; j < len; j++) gseq[j] = check(gseq[j]); + + iter = sn2tr.find(seqname); + if (iter == sn2tr.end()) continue; + + chrvec.push_back(ChrInfo(seqname, len)); + + vector& vec = iter->second; + int s = vec.size(); + for (int j = 0; j < s; j++) { + assert(vec[j] > 0 && vec[j] <= M); + transcripts.getTranscriptAt(vec[j]).extractSeq(gseq, seqs[vec[j]]); + } } fin.close(); @@ -305,7 +304,7 @@ int main(int argc, char* argv[]) { if (seqs[i] == "") { const Transcript& transcript = transcripts.getTranscriptAt(i); fprintf(stderr, "Cannot extract transcript %s's sequence from chromosome %s, whose information might not be provided! Please check if the chromosome directory is set correctly or the list of chromosome files is complete.\n", \ - transcript.getTranscriptID().c_str(), transcript.getGeneID().c_str()); + transcript.getTranscriptID().c_str(), transcript.getSeqName().c_str()); exit(-1); } }