void simulateWorld(long tstart, long tend) {
    const static double DT_100MS = 100;
    timeTmp += tend - tstart;

    if (timeTmp >= DT_100MS) {
        for (long ts = timeTmp; timeTmp > 0; timeTmp -= DT_100MS) {

            stepSign(centerHansel, angleHansel, DT_100MS / 1000);
            stepSign(centerGreta, angleGreta, DT_100MS / 1000);

            calcCoverage();

            if (isCovered) {
                timeCovered += DT_100MS;
            }
        }
    }
}
Beispiel #2
0
int main(int argc, char *argv[]) {
  DBAdaptor *      dba;
  StatementHandle *sth;
  ResultRow *      row;
  Vector *         slices;
  int              nSlices;
  htsFile *      out;

  int   argNum = 1;

  char *inFName  = NULL;
  char *outFName = NULL;

  char *dbUser = "******";
  char *dbPass = NULL;
  int   dbPort = 3306;

  char *dbHost = "ens-staging.internal.sanger.ac.uk";
  char *dbName = "homo_sapiens_core_71_37";

  char *assName = "GRCh37";

  char *chrName = "1";


  int flags = 0;
  int   threads  = 1;

  initEnsC(argc, argv);

  while (argNum < argc) {
    char *arg = argv[argNum];
    char *val;

// Ones without a val go here
    if (!strcmp(arg, "-U") || !strcmp(arg,"--ucsc_naming")) {
      flags |= M_UCSC_NAMING;
    } else {
// Ones with a val go in this block
      if (argNum == argc-1) {
        Bamcov_usage();
      }

      val = argv[++argNum];
  
      if (!strcmp(arg, "-i") || !strcmp(arg,"--in_file")) {
        StrUtil_copyString(&inFName,val,0);
      } else if (!strcmp(arg, "-o") || !strcmp(arg,"--out_file")) {
        StrUtil_copyString(&outFName,val,0);
      } else if (!strcmp(arg, "-h") || !strcmp(arg,"--host")) {
        StrUtil_copyString(&dbHost,val,0);
      } else if (!strcmp(arg, "-p") || !strcmp(arg,"--password")) {
        StrUtil_copyString(&dbPass,val,0);
      } else if (!strcmp(arg, "-P") || !strcmp(arg,"--port")) {
        dbPort = atoi(val);
      } else if (!strcmp(arg, "-n") || !strcmp(arg,"--name")) {
        StrUtil_copyString(&dbName,val,0);
      } else if (!strcmp(arg, "-u") || !strcmp(arg,"--user")) {
        StrUtil_copyString(&dbUser,val,0);
      } else if (!strcmp(arg, "-t") || !strcmp(arg,"--threads")) {
        threads = atoi(val);
      } else if (!strcmp(arg, "-a") || !strcmp(arg,"--assembly")) {
        StrUtil_copyString(&assName,val,0);
      } else if (!strcmp(arg, "-v") || !strcmp(arg,"--verbosity")) {
        verbosity = atoi(val);
// Temporary
      } else if (!strcmp(arg, "-c") || !strcmp(arg,"--chromosome")) {
        StrUtil_copyString(&chrName,val,0);
      } else {
        fprintf(stderr,"Error in command line at %s\n\n",arg);
        Bamcov_usage();
      }
    }
    argNum++;
  }

  if (verbosity > 0) {
    printf("Program for calculating read coverage in a BAM file \n"
           "Steve M.J. Searle.  [email protected]  Last update April 2013.\n");
  }

  if (!inFName || !outFName) {
    Bamcov_usage();
  }

  dba = DBAdaptor_new(dbHost,dbUser,dbPass,dbName,dbPort,NULL);

  //nSlices = getSlices(dba, destName);
  nSlices = 1;

  slices = Vector_new();

  SliceAdaptor *sa = DBAdaptor_getSliceAdaptor(dba);

  Slice *slice = SliceAdaptor_fetchByRegion(sa,NULL,chrName,POS_UNDEF,POS_UNDEF,1,NULL, 0);

  Vector_addElement(slices,slice);

  if (Vector_getNumElement(slices) == 0) {
    fprintf(stderr, "Error: No slices.\n");
    exit(1);
  }

  htsFile *in = hts_open(inFName, "rb");
  if (in == 0) {
    fprintf(stderr, "Fail to open BAM file %s\n", inFName);
    return 1;
  }

  hts_set_threads(in, threads);
  hts_idx_t *idx;
  idx = bam_index_load(inFName); // load BAM index
  if (idx == 0) {
    fprintf(stderr, "BAM index file is not available.\n");
    return 1;
  }

  int i;
  for (i=0; i<Vector_getNumElement(slices); i++) {
    Slice *slice = Vector_getElementAt(slices,i);

    if (verbosity > 0) printf("Working on '%s'\n",Slice_getName(slice));

//    if (verbosity > 0) printf("Stage 1 - retrieving annotation from database\n");
//    Vector *genes = getGenes(slice, flags);

    if (verbosity > 0) printf("Stage 1 - calculating coverage\n");
    calcCoverage(inFName, slice, in, idx, flags);
  }


  hts_idx_destroy(idx);
  hts_close(in);

  if (verbosity > 0) printf("Done\n");
  return 0;
}
Beispiel #3
0
void findCannyCandidates( GradientChain& grad, CandidatePtrVector& cds ) {

  // Read canny edge stats from gradient image
  IplImage *canny = grad.cannyEdges;
  int width = canny->width;
  int height = canny->height;
  int wstep = canny->widthStep;
  float minRad = grad.minRad;
  float maxRad = grad.maxRad;

  // Single pass through image (sort of) linking edges
  vector<cp_circle> iden;
  const char EDGE_MARKER = (char)(255);
  const char USED_MARKER = (char)(254);
  //cout << width << " " << height << endl;
  for( int r = 1; r < height-1; r++ ) {
    for( int c = 1; c < width-1; c++ ) {

      // Check if new Contour exists
      if( (canny->imageData+wstep*r)[c] == EDGE_MARKER ) {

        stack<cp_point> sq;
        cp_point pt(r,c);
        vector<cp_point> seq;
        sq.push( pt );

        while( sq.size() != 0 ) {

          pt = sq.top();
          int ir = pt.r;
          int ic = pt.c;
          
          // Check boundary conditions
          if( ir < 1 || ic < 1 || ir > height-1 || ic > width-1 ) {
            sq.pop();
            continue;
          }

          // Check label
          char* pos = (canny->imageData + wstep*ir)+ic;
          if( *pos != EDGE_MARKER ) {
            sq.pop();
            continue;
          }
          
          *pos = USED_MARKER;
          seq.push_back( pt );
          sq.pop();

          // Check 8-connectedness
          sq.push( cp_point( ir+1, ic ) );
          sq.push( cp_point( ir, ic+1 ) );
          sq.push( cp_point( ir-1, ic ) );
          sq.push( cp_point( ir, ic-1 ) );
          sq.push( cp_point( ir-1, ic+1 ) );
          sq.push( cp_point( ir-1, ic-1 ) );
          sq.push( cp_point( ir+1, ic+1 ) );
          sq.push( cp_point( ir+1, ic-1 ) );
        }  

        // Quickly Analyze Contour
        int csize = seq.size();

        // Threshold size
        if( csize < 8 )
          continue;

        // If its a very small Contour
        if( csize < 16 ) {
          int i1 = 1;
          int i2 = csize / 2;
          int i3 = csize - 2;
          cp_circle c1;
          bool status = circleFrom3PointsInd( seq, i1, i2, i3, c1 );
          if( status && c1.rad > (1.5*minRad) && c1.rad < maxRad ) {
            calcMSE( c1, seq );
            calcCoverage( c1, seq );
            iden.push_back( c1 );
          }
          continue;
        }

        // Sampling Indecies
        int i1 = 0;
        int i2 = 0.2*csize;
        int i3 = 0.4*csize;
        int i4 = 0.6*csize;
        int i5 = 0.8*csize;
        int i6 = csize - 1;
        
        // Sample circles
        cp_circle c1, c2, c3;
        bool s1 = circleFrom3PointsInd( seq, i1, i4, i6, c1 );
        bool s2 = circleFrom3PointsInd( seq, i2, i4, i6, c2 );
        bool s3 = circleFrom3PointsInd( seq, i1, i3, i5, c3 );

        // Filter
        if( s1 && c1.rad > minRad && c1.rad < maxRad ) {
          calcMSE( c1, seq );
          calcCoverage( c1, seq );
          iden.push_back( c1 );
        }
        if( s2 && c2.rad > minRad && c2.rad < maxRad ) {
          calcMSE( c2, seq );
          calcCoverage( c2, seq );
          iden.push_back( c2 );
        }
        if( s3 && c3.rad > minRad && c3.rad < maxRad ) {
          calcMSE( c3, seq );
          calcCoverage( c3, seq );
          iden.push_back( c3 );
        }  
      }
    }
  }

  // Insert/Adjust IP for scale
  const int MAX_CP_IP = 40;
  sort( iden.begin(), iden.end(), compareCircles );
  for( unsigned int i = 0; i < iden.size(); i++ ) {

    // Check max
    if( i >= MAX_CP_IP )
      break;

    // Insert new Candidate point
    Candidate* cd1 = new Candidate;
    cd1->r = iden[i].r * grad.scale;
    cd1->c = iden[i].c * grad.scale;
    cd1->major = iden[i].rad * grad.scale;
    cd1->minor = iden[i].rad * grad.scale;
    cd1->angle = 0.0;
    cd1->method = CANNY;
    cd1->magnitude = iden[i].normMSE*iden[i].csize;
    cds.push_back( cd1 );
  }
}