Exemplo n.º 1
0
// FORMAT : filename path version\n
bool Client::addToFileLog(string uid, string fname , string fname_withpath , int version) {
    //Add fname to the file called uid.
    string olfile = uid + "/" + CLIENT_SYNC_DIR + "/" + uid + CLIENT_SYNC_DIR;
    string newfile = uid + "/" + CLIENT_SYNC_DIR + "/" + uid + CLIENT_SYNC_DIR + LOG_FILE_SUFFIX;
    fstream reader(olfile , ios::in);
    bool found = true;
    fstream writer(newfile , ios::out);
    while( !reader.eof() ) {
        string file , path , v;

        reader >> file;
        reader >> path;
        reader >> v;
        if ( fname == file ) { //FILE FOUND!
            writer << fname << " " <<  fname_withpath << " " ;
            writer << " " << to_string(version) << "\n";
            found = false;
        } else {
            writer << file << " " <<  path << " ";
            writer << " " << v << "\n";
        }
    }
    if ( found ) {
        writer << fname << " " << fname_withpath << " " << to_string(version) << "\n";
    }
    reader.close();
    writer.close();
    //rename tuid to uid.
    boost::filesystem::path p(olfile);
    boost::filesystem::path ptemp(newfile);
    boost::filesystem::rename(ptemp , p);

    return true;
}
Exemplo n.º 2
0
void PCRProcessor::removePCR(std::shared_ptr<BarcodeCluster>& c,
                             std::shared_ptr<BarcodePool>& pool) {
    unordered_map<string, list<size_t>> u_2_b;
    unordered_map<size_t, size_t> b_2_freq;
    std::shared_ptr<BarcodeCluster> updated_result;

    for (const auto& b : c->barcodes()) {
        for (const auto& u : pool->primers(b)) {
            if (u_2_b.find(u) == u_2_b.end()) {
                u_2_b.insert({u,{b}});
            } else {
                u_2_b[u].push_back(b);
            }
        }
        b_2_freq[b] = pool->barcodeFrequency(b);
    }

    // ONLY keep one barcode for each UMI
    for (auto& u_b : u_2_b) {
        size_t max = 0;
        size_t max_size = 0;
        // find the barcode that has the largest frequency.
        for (const auto& b : u_b.second) {
            if (pool->barcodeFrequency(b) > max_size) {
                max = b;
                max_size = pool->barcodeFrequency(b);
            }
        }
        // Remove all the barcode except the most frequent barcode for this UMI
        for (const auto& b : u_b.second) {
            if (b != max) {
                assert(b_2_freq[b] > 0);
                --b_2_freq[b];
            }
        }
        u_b.second.assign(1,max);
    }

    // Now get the updated barcode frequency and form a new cluster.
    for (const auto& b_f : b_2_freq) {
        if (b_f.second > 0) {
            vector<string> my_primes;
            for (const auto& p : pool->primers(b_f.first)) {
                if (u_2_b[p].front() == b_f.first) {
                    my_primes.push_back(p);
                }
            }
            std::swap(pool->primers(b_f.first), my_primes);
            std::shared_ptr<BarcodeCluster> ptemp(new BarcodeCluster(b_f.first));
            if (updated_result.get()) {
                updated_result->merge(ptemp);
            } else {
                updated_result = ptemp;
            }
        } else {
            pool->primers(b_f.first).clear();
        }
    }
    c = updated_result;
}
Exemplo n.º 3
0
float SolidNoise::dturbulence(const Vector3& p, int depth, float d) const {
    float sum = 0.0f;
    float weight = 1.0f;
    Vector3 ptemp(p);
    sum += fabs(noise(ptemp)) / d;
    
    for (int i = 1; i < depth; i++) {
        weight *= d;
        ptemp.setX(p.x() * weight);
        ptemp.setY(p.y() * weight);
        ptemp.setZ(p.z() * weight);
        sum +=fabs(noise(ptemp)) / weight;
    }
    return sum;
}
Exemplo n.º 4
0
        void sturm_functions(std::vector< polynomial<data__> > &sturm_fun, const polynomial<data__> &f)
        {
          size_t i, n;

          // resize the Sturm function vector
          n=f.degree()+1;
          sturm_fun.resize(n);

          polynomial<data__> *ptemp(f.fp()), pjunk;

          // initialize the Sturm functions
          sturm_fun[0]=f;
          ptemp=f.fp();
          sturm_fun[1]=*ptemp;
          delete ptemp;

          // build the Sturm functions
          sturm_fun[0].divide(std::abs(sturm_fun[0].coefficient(sturm_fun[0].degree())));
          sturm_fun[1].divide(std::abs(sturm_fun[1].coefficient(sturm_fun[1].degree())));
          for (i=2; i<n; ++i)
          {
            if (sturm_fun[i-1].degree()>0)
            {
              data__ small_no, max_c(0);
              typename polynomial<data__>::coefficient_type c;

              sturm_fun[i-1].get_coefficients(c);
              for (typename polynomial<data__>::index_type j=0; j<=sturm_fun[i-1].degree(); ++j)
              {
                if (std::abs(c(j))>max_c)
                  max_c=std::abs(c(j));
              }
              small_no=max_c*std::sqrt(std::numeric_limits<data__>::epsilon());

              pjunk.divide(sturm_fun[i], sturm_fun[i-2], sturm_fun[i-1]);
              sturm_fun[i].negative();
              if (std::abs(sturm_fun[i].coefficient(sturm_fun[i].degree()))>small_no)
                sturm_fun[i].divide(std::abs(sturm_fun[i].coefficient(sturm_fun[i].degree())));
              sturm_fun[i].adjust_zero(small_no);
            }
            else
            {
              sturm_fun[i]=0;
            }
          }
        }
Exemplo n.º 5
0
bool Box::updateProgram(const string& name, const string& type, int duration, const Date& date, const Program& program)
{
	Program ptemp(name, type, program.getChannel(), duration, date.getDay(), date.getHour(), date.getMinutes());
	string channel = program.getChannel();
	int i = 0;
	for (; i < channels.size(); i++)
	{
	if (channel == channels[i].getName())
		break;
	}
	for (int j = 0; j < channels[i].programs.size(); j++)
	{
	if (ptemp.overlaps(channels[i].programs[j]) && !(channels[i].programs[j]== program))
		return false;
	}
	bool changedname = !(name == program.getName());
	if (changedname)
	for (int j = 0; j < channels[i].programs.size(); j++)
	if (channels[i].programs[j].getName() == name)
		return false;
	for (int j = 0; j < channels[i].programs.size(); j++)
		if (channels[i].programs[j] == program)
	{
		channels[i].programs[j].setname(name).settype(type).setduration(duration).setdate(date);
		break;
	}
	sort(channels[i].programs.begin(), channels[i].programs.end());
	for (int n = 0; n < toBeRecorded.size(); n++)
	{
		if (toBeRecorded[n] == program)
		{
			toBeRecorded[n].setname(name).settype(type).setduration(duration).setdate(date);
			sort(toBeRecorded.begin(), toBeRecorded.end());
			break;
		}
	}
	return true;
}
Exemplo n.º 6
0
int NanoShaperInterface::compute_from_file(int surftype, float gspacing,
                                           float probe_radius,
                                           float skin_parm,
                                           float blob_parm, 
                                           int n, int *ids, float *xyzr, 
                                           int *flgs) {
  const char *nsbin = "NanoShaper";

  // generate output file name and try to create
  char *dirname = vmd_tempfile("");

  int uid = vmd_getuid();
  int rnd = vmd_random() % 999;

  char *filebase = new char[strlen(dirname) + 100];
  sprintf(filebase, "%svmdns.u%d.%d.", dirname, uid, rnd);
  delete [] dirname;

  char *pfilename = new char[strlen(filebase) + 100];
  char *ofilename = new char[strlen(filebase) + 100];
  sprintf(pfilename, "%sprm", filebase);
  sprintf(ofilename, "%sxyzr", filebase);

  FILE *pfile = fopen(pfilename, "wt");
  if (!pfile) {
    delete [] filebase;
    delete [] pfilename;
    delete [] ofilename;
    msgErr << "Failed to create NanoShaper parameter input file" << sendmsg;
    return 0;  // failure
  }

  const char *surfstr = "ses";
  const char *modestr = "normal";
  switch(surftype) {
    case NS_SURF_SES:
      surfstr = "ses";
      modestr = "normal";
      break;

    case NS_SURF_SKIN:
      surfstr = "skin";
      modestr = "normal";
      break;

    case NS_SURF_BLOBBY:
      surfstr = "blobby";
      modestr = "normal";
      break;

    case NS_SURF_POCKETS:
      surfstr = "pockets";
      modestr = "pockets";
      break;
  }

  //
  // Emit surface calculation configuration into NS input file
  // 
  fprintf(pfile, "Operative_Mode = %s\n", modestr);
  fprintf(pfile, "Pocket_Radius_Small = %.1f\n", 1.4);
  fprintf(pfile, "Pocket_Radius_Big = %.1f\n", 3.0);
  fprintf(pfile, "Surface = %s\n", surfstr);

  if (gspacing < 0.05f)
    gspacing = 0.05f;
  fprintf(pfile, "Grid_scale = %.1f\n", 1.0f/gspacing);

  fprintf(pfile, "XYZR_FileName = %s\n", ofilename);
  fprintf(pfile, "Probe_Radius = %.1f\n", probe_radius);
  fprintf(pfile, "Skin_Surface_Parameter = %.2f\n", skin_parm);
  fprintf(pfile, "Blobbyness = %.1f\n", blob_parm);

  // enable all to emulate MSMS
  fprintf(pfile, "Compute_Vertex_Normals = true\n");
  fprintf(pfile, "Save_Mesh_MSMS_Format = true\n");
  fprintf(pfile, "Vertex_Atom_Info = true\n");
 
  // various parameters copied from example input file
  fprintf(pfile, "Grid_perfil = %.1f\n", 70.0);
  fprintf(pfile, "Build_epsilon_maps = false\n");
  fprintf(pfile, "Build_status_map = true\n");
  fprintf(pfile, "Smooth_Mesh = true\n");
  fprintf(pfile, "Triangulation = true\n");

  // SD: optimized value for big structures
  fprintf(pfile, "Max_Probes_Self_Intersections = 5000\n");

  fprintf(pfile, "Self_Intersections_Grid_Coefficient = 5.0\n");
  fprintf(pfile, "Accurate_Triangulation = true\n");

  // Tell NS to store all files by appending to a base filename provided
  // by the caller, so we don't end up with problems on multi-user systems
  // or when multiple VMD sessions are running concurrently on the same
  // machine.  VMD chooses the base filename via OS temp file APIs.
  fprintf(pfile, "Root_FileName = %s\n", filebase);

  // SD: optimized value for big structures
  fprintf(pfile, "Max_skin_patches_per_auxiliary_grid_2d_cell = 2000\n");

  fclose(pfile);

  FILE *ofile = fopen(ofilename, "wt");
  if (!ofile) {
    delete [] ofilename;
    msgErr << "Failed to create NanoShaper atom xyzr input file" << sendmsg;
    return 0;  // failure
  }

  char *facetfilename = new char[strlen(filebase) + 100];
  char *vertfilename = new char[strlen(filebase) + 100];
  char *errfilename = new char[strlen(filebase) + 100];
  char *expfilename = new char[strlen(filebase) + 100];
  char *expindfilename = new char[strlen(filebase) + 100];
  char *areafilename = new char[strlen(filebase) + 100];
  sprintf(facetfilename, "%striangulatedSurf.face", filebase);
  sprintf(vertfilename, "%striangulatedSurf.vert", filebase);
  sprintf(errfilename, "%sstderror.txt", filebase);
  sprintf(expfilename, "%sexposed.xyz", filebase);
  sprintf(expindfilename, "%sexposedIndices.txt", filebase);
  sprintf(areafilename, "%striangleAreas.txt", filebase);

  // temporary files we want to make sure to clean up
  VMDTempFile ptemp(pfilename);
  VMDTempFile otemp(ofilename);
  VMDTempFile ftemp(facetfilename);
  VMDTempFile vtemp(vertfilename);
  VMDTempFile errtemp(errfilename);
  VMDTempFile exptemp(expfilename);
  VMDTempFile expindtemp(expindfilename);
  VMDTempFile areatemp(areafilename);

  //
  // write atom coordinates and radii to the file we send to NanoShaper 
  //
  for (int i=0; i<n; i++) {
    fprintf(ofile, "%f %f %f %f\n", 
            xyzr[4L*i], xyzr[4L*i+1], xyzr[4L*i+2], xyzr[4L*i+3]);
  }
  fclose(ofile);

  //
  // call NanoShaper to calculate the surface for the given atoms
  //
  char *nscmd = new char[2*strlen(ofilename) + strlen(nsbin) + 100];
  sprintf(nscmd, "\"%s\" %s", nsbin, pfilename);
  vmd_system(nscmd);    
  delete [] nscmd;
  delete [] pfilename;

  // 
  // read NanoShaper output files
  //
  if (surftype == NS_SURF_POCKETS) {
    // XXX pockets feature not complete yet
    msgErr << "NanoShaper pockets mode currently unimplemented" << sendmsg;
    return 0;
  } else {
    // Read output files for one of the normal surface modes

    // read facets
    FILE *facetfile = fopen(facetfilename, "r");
    if (!facetfile) {
      msgErr << "Cannot read NanoShaper facet file: " << facetfilename << sendmsg;
      return 0;  // failed
    }
    NanoShaperFace face;

    char trash[256];
    fgets(trash, sizeof(trash), facetfile); // eat text comments and counts
    fgets(trash, sizeof(trash), facetfile);
    fgets(trash, sizeof(trash), facetfile);
    while (fscanf(facetfile, "%d %d %d %d %d",
          face.vertex+0, face.vertex+1, face.vertex+2, &face.surface_type,
          &face.anaface) == 5) {
      face.component = 0;  // XXX Unused by VMD, so why store?
      face.vertex[0]--;
      face.vertex[1]--;
      face.vertex[2]--;
      faces.append(face);
    }
    fclose(facetfile);

    msgInfo << "NanoShaper face count: " << faces.num() << sendmsg;

    // read verts
    FILE *vertfile = fopen(vertfilename, "r");
    if (!vertfile) {
      msgErr << "Cannot read NanoShaper vertex file: " << vertfilename << sendmsg;
      return 0;  // failed
    }
    NanoShaperCoord norm, coord;
    int atomid;  // 1-based atom index
    int l0fa;    // number of of the level 0 SES face
    int l;       // SES face level? (1/2/3)
    fgets(trash, sizeof(trash), vertfile);
    fgets(trash, sizeof(trash), vertfile);
    fgets(trash, sizeof(trash), vertfile);
    while (fscanf(vertfile, "%f %f %f %f %f %f %d %d %d",
          coord.x+0, coord.x+1, coord.x+2, 
          norm.x+0, norm.x+1, norm.x+2, 
          &l0fa, &atomid, &l) == 9) {
      norms.append(norm);
      coords.append(coord);
      atomids.append(atomid-1);
    }
    fclose(vertfile);

    msgInfo << "NanoShaper vert count: " << norms.num() << sendmsg;

    if (ids) {
      for (int i=0; i<atomids.num(); i++) {
        atomids[i] = ids[atomids[i]];
      }
    }
  } 


  return 1; // success
}
Exemplo n.º 7
0
void vpTemplateTracker::trackPyr(const vpImage<unsigned char> &I)
{
  //vpTRACE("trackPyr");
  vpImage<unsigned char> *pyr_I;
//  pyr_I=new vpImage<unsigned char>[nbLvlPyr+1]; // Why +1 ?
  pyr_I=new vpImage<unsigned char>[nbLvlPyr]; // Why +1 ?
  pyr_I[0]=I;

  try
  {
      vpColVector ptemp(nbParam);
      if(nbLvlPyr>1)
      {
    //    vpColVector *p_sauv=new vpColVector[nbLvlPyr];
    //    for(unsigned int i=0;i<nbLvlPyr;i++)p_sauv[i].resize(nbParam);

    //    p_sauv[0]=p;
        for(unsigned int i=1;i<nbLvlPyr;i++)
        {
          vpImageFilter::getGaussPyramidal(pyr_I[i-1],pyr_I[i]);
          //test getParamPyramidDown
          /*vpColVector vX_test(2);vX_test[0]=15.;vX_test[1]=30.;
          vpColVector vX_test2(2);
          Warp->computeCoeff(p);
          Warp->computeDenom(vX_test,p);
          Warp->warpX(vX_test,vX_test2,p);
          std::cout<<"p = "<<p.t()<<std::endl;*/
          //std::cout<<"get p down"<<std::endl;
          Warp->getParamPyramidDown(p,ptemp);
          p=ptemp;
          zoneTracked=&zoneTrackedPyr[i];

    //      p_sauv[i]=p;
          /*std::cout<<"p_down = "<<p.t()<<std::endl;

          vpColVector vX_testd(2);vX_testd[0]=15./2.;vX_testd[1]=30./2.;
          vpColVector vX_testd2(2);
          Warp->computeCoeff(p);
          Warp->computeDenom(vX_testd,p);
          Warp->warpX(vX_testd,vX_testd2,p);
          std::cout<<2.*vX_testd2[0]<<","<<2.*vX_testd2[1]<<" <=> "<<vX_test2[0]<<","<<vX_test2[1]<<std::endl;*/

        }

        for(int i=(int)nbLvlPyr-1;i>=0;i--)
        {
          if(i>=(int)l0Pyr)
          {
            templateSize=templateSizePyr[i];
            ptTemplate=ptTemplatePyr[i];
            ptTemplateSelect=ptTemplateSelectPyr[i];
            ptTemplateSupp=ptTemplateSuppPyr[i];
            ptTemplateCompo=ptTemplateCompoPyr[i];
            H=HdesirePyr[i];
            HLM=HLMdesirePyr[i];
            HLMdesireInverse=HLMdesireInversePyr[i];
    //        zoneTracked=&zoneTrackedPyr[i];
            trackRobust(pyr_I[i]);
          }
          //std::cout<<"get p up"<<std::endl;
    //      ptemp=p_sauv[i-1];
          if (i > 0) {
            Warp->getParamPyramidUp(p,ptemp);
            p=ptemp;
            zoneTracked=&zoneTrackedPyr[i-1];
          }
        }
    #if 0
        if(l0Pyr==0)
        {
          templateSize=templateSizePyr[0];
          ptTemplate=ptTemplatePyr[0];
          ptTemplateSelect=ptTemplateSelectPyr[0];
          ptTemplateSupp=ptTemplateSuppPyr[0];
          ptTemplateCompo=ptTemplateCompoPyr[0];
          H=HdesirePyr[0];
          HLM=HLMdesirePyr[0];
          HLMdesireInverse=HLMdesireInversePyr[0];
          zoneTracked=&zoneTrackedPyr[0];
          trackRobust(pyr_I[0]);
        }

        if (l0Pyr > 0) {
    //      for (int l=(int)l0Pyr; l >=0; l--) {
    //        Warp->getParamPyramidUp(p,ptemp);
    //        p=ptemp;
    //      }
          zoneTracked=&zoneTrackedPyr[0];
        }
    #endif
        //    delete [] p_sauv;
      }
      else
      {
        //std::cout<<"reviens a tracker de base"<<std::endl;
        trackRobust(I);
      }
      delete[] pyr_I;
  }
  catch(vpException &e){
      delete[] pyr_I;
      throw(vpTrackingException(vpTrackingException::badValue, e.getMessage()));
  }
}