]> git.donarmstrong.com Git - rsem.git/blobdiff - SingleModel.h
rsem v1.1.11, allow spaces appear in field seqname and attributes gene_id, transcript...
[rsem.git] / SingleModel.h
index 76c54f1489e15cc87123ef0f3bb3d142c10062db..bdf920ff271c133c749214244604fa319eac80c4 100644 (file)
@@ -61,7 +61,6 @@ public:
                mw = NULL;
 
                if (isMaster) {
-                       ori = new Orientation(params.probF);
                        gld = new LenDist(params.minL, params.maxL);
                        if (mean >= EPSILON) {
                                mld = new LenDist(params.mate_minL, params.mate_maxL);
@@ -69,6 +68,7 @@ public:
                        if (!estRSPD) { rspd = new RSPD(estRSPD); }
                }
 
+               ori = new Orientation(params.probF);
                if (estRSPD) { rspd = new RSPD(estRSPD, params.B); }
                pro = new Profile(params.maxL);
                npro = new NoiseProfile();
@@ -315,17 +315,18 @@ void SingleModel::collect(const SingleModel& o) {
        npro->collect(*(o.npro));
 }
 
+//Only master node can call
 void SingleModel::read(const char* inpF) {
        int val;
        FILE *fi = fopen(inpF, "r");
        if (fi == NULL) { fprintf(stderr, "Cannot open %s! It may not exist.\n", inpF); exit(-1); }
 
-       fscanf(fi, "%d", &val);
+       assert(fscanf(fi, "%d", &val) == 1);
        assert(val == model_type);
 
        ori->read(fi);
        gld->read(fi);
-       fscanf(fi, "%d", &val);
+       assert(fscanf(fi, "%d", &val) == 1);
        if (val > 0) {
                if (mld == NULL) mld = new LenDist();
                mld->read(fi);
@@ -334,16 +335,18 @@ void SingleModel::read(const char* inpF) {
        pro->read(fi);
        npro->read(fi);
 
-       fclose(fi);
-
-       if (fscanf(fi, "%d", &M) == 1) {
-         mw = new double[M + 1];
-         for (int i = 0; i <= M; i++) fscanf(fi, "%lf", &mw[i]);
+       if (fscanf(fi, "%d", &val) == 1) {
+               if (M == 0) M = val;
+               if (M == val) {
+                       mw = new double[M + 1];
+                       for (int i = 0; i <= M; i++) assert(fscanf(fi, "%lf", &mw[i]) == 1);
+               }
        }
 
        fclose(fi);
 }
 
+//Only master node can call. Only be called at EM.cpp
 void SingleModel::write(const char* outF) {
        FILE *fo = fopen(outF, "w");
 
@@ -363,7 +366,7 @@ void SingleModel::write(const char* outF) {
        npro->write(fo);
 
        if (mw != NULL) {
-         fprintf(fo, "%d\n", M);
+         fprintf(fo, "\n%d\n", M);
          for (int i = 0; i < M; i++) {
            fprintf(fo, "%.15g ", mw[i]);
          }
@@ -420,9 +423,8 @@ bool SingleModel::simulate(int rid, SingleRead& read, int& sid) {
                }
        }
 
-       std::ostringstream stdout;
-       stdout<<rid<<"_"<<dir<<"_"<<sid<<"_"<<pos;
-       name = stdout.str();
+       strout<<rid<<"_"<<dir<<"_"<<sid<<"_"<<pos;
+       name = strout.str();
 
        read = SingleRead(name, readseq);