]> git.donarmstrong.com Git - rsem.git/blobdiff - parseIt.cpp
Allowed > 2^31 hits
[rsem.git] / parseIt.cpp
index 55dd954d3d1e2059911987ed5a8521748b16e9a1..c760c79f879775450e4677951d3ee25774a7ffcc 100644 (file)
@@ -13,8 +13,6 @@
 #include "utils.h"
 
 #include "GroupInfo.h"
-
-#include "Transcript.h"
 #include "Transcripts.h"
 
 #include "SingleRead.h"
@@ -30,9 +28,9 @@
 using namespace std;
 
 int read_type; // 0 SingleRead, 1 SingleReadQ, 2 PairedEndRead, 3 PairedEndReadQ
-int N[3]; // note, N = N0 + N1 + N2 , but may not be equal to the total number of reads in data
-int nHits; // # of hits
-int nUnique, nMulti, nIsoMulti;
+READ_INT_TYPE N[3]; // note, N = N0 + N1 + N2 , but may not be equal to the total number of reads in data
+HIT_INT_TYPE nHits; // # of hits
+READ_INT_TYPE nUnique, nMulti, nIsoMulti;
 char fn_list[STRLEN];
 char groupF[STRLEN], tiF[STRLEN];
 char imdName[STRLEN];
@@ -48,8 +46,8 @@ int n_os; // number of ostreams
 ostream *cat[3][2]; // cat : category  1-dim 0 N0 1 N1 2 N2; 2-dim  0 mate1 1 mate2
 char readOutFs[3][2][STRLEN];
 
-map<int, int> counter;
-map<int, int>::iterator iter;
+map<int, READ_INT_TYPE> counter;
+map<int, READ_INT_TYPE>::iterator iter;
 
 void init(const char* imdName, char alignFType, const char* alignF) {
 
@@ -87,7 +85,7 @@ void parseIt(SamParser *parser) {
        nUnique = nMulti = nIsoMulti = 0;
        memset(N, 0, sizeof(N));
 
-       long long cnt = 0;
+       READ_INT_TYPE cnt = 0;
 
        record_val = -2; //indicate no recorded read now
        while ((val = parser->parseNext(read, hit)) >= 0) {
@@ -96,6 +94,9 @@ void parseIt(SamParser *parser) {
                        if (record_val >= 0) {
                                record_read.write(n_os, cat[record_val]);
                                ++N[record_val];
+                       }
+                       // flush out previous read's hits if the read is alignable reads
+                       if (record_val == 1) {
                                hits.updateRI();
                                nHits += hits.getNHits();
                                nMulti += hits.calcNumGeneMultiReads(gi);
@@ -121,12 +122,15 @@ void parseIt(SamParser *parser) {
                }
 
                ++cnt;
-               if (verbose && (cnt % 1000000 == 0)) { printf("Parsed %lld entries\n", cnt); }
+               if (verbose && (cnt % 1000000 == 0)) { cout<< "Parsed "<< cnt<< " entries"<< endl; }
        }
 
        if (record_val >= 0) {
                record_read.write(n_os, cat[record_val]);
                ++N[record_val];
+       }
+
+       if (record_val == 1) {
                hits.updateRI();
                nHits += hits.getNHits();
                nMulti += hits.calcNumGeneMultiReads(gi);
@@ -199,7 +203,7 @@ int main(int argc, char* argv[]) {
 
        hit_out.open(datF);
 
-       string firstLine(59, ' ');
+       string firstLine(99, ' ');
        firstLine.append(1, '\n');              //May be dangerous!
        hit_out<<firstLine;
 
@@ -220,9 +224,11 @@ int main(int argc, char* argv[]) {
        fout<<N[0]<<" "<<N[1]<<" "<<N[2]<<" "<<(N[0] + N[1] + N[2])<<endl;
        fout<<nUnique<<" "<<nMulti<<" "<<nIsoMulti<<endl;
        fout<<nHits<<" "<<read_type<<endl;
+       fout<<"0\t"<<N[0]<<endl;
        for (iter = counter.begin(); iter != counter.end(); iter++) {
                fout<<iter->first<<'\t'<<iter->second<<endl;
        }
+       fout<<"Inf\t"<<N[2]<<endl;
        fout.close();
 
        release();