Exemple #1
0
point triangle::calc_center( triangle* t )
{

	arma::vec Pa(3);
	Pa(0) = (t->m_vertex_list[0].x);
	Pa(1) = (t->m_vertex_list[0].y);
	Pa(2) = 0;

	arma::vec Pb(3);
	Pb(0) = (t->m_vertex_list[1].x);
	Pb(1) = (t->m_vertex_list[1].y);
	Pb(2) = 0;

	arma::vec Pc(3);
	Pc(0) = (t->m_vertex_list[2].x);
	Pc(1) = (t->m_vertex_list[2].y);
	Pc(2) = 0;

	arma::vec AB = Pb - Pa;
	arma::vec AC = Pc - Pa;
	arma::vec BC = Pc - Pb;

//circumcenter
// 	arma::vec N = arma::cross(AC,AB);
// 	arma::vec L1 = arma::cross(AB,N);
// 	arma::vec L2 = arma::cross(BC,N);
// 	arma::vec P21 = (Pc - Pa)/2;
// 	arma::vec P1 = (Pa + Pb)/2;

	
//incenter

	arma::vec uab  = AB / arma::norm(AB,1);
	arma::vec uac  = AC / arma::norm(AC,1);
	arma::vec ubc  = BC / arma::norm(BC,1);
	arma::vec uba = -uab;

	arma::vec L1 = uab + uac;
	arma::vec L2 = uba + ubc;
	arma::vec P21 = Pb-Pa;
	arma::vec P1 = Pa;
     
	arma::mat ML1(L1);
	arma::mat ML2(L2);

	arma::mat ML = arma::join_rows(ML1,-ML2);

	arma::vec lambda = arma::solve(ML,P21);

	arma::vec pos = P1+lambda(0)*L1;

	point p;
	p.x = pos(0);
	p.y = pos(1);
	return p;
}
this is unfinished crap



//  The below is the main from writing unmatched regions




int
main(int argc, char *argv[]) {
  FILE         *Aoutput = 0L;
  FILE         *Boutput = 0L;
  char         *matchesFile = 0L;

  int arg=1;
  while (arg < argc) {
    if        (strcmp(argv[arg], "-a") == 0) {
      errno = 0;
      Aoutput = fopen(argv[++arg], "w");
      if (errno)
        fprintf(stderr, "Failed to open '%s': %s\n", argv[arg], strerror(errno)), exit(1);
    } else if (strcmp(argv[arg], "-b") == 0) {
      errno = 0;
      Boutput = fopen(argv[++arg], "w");
      if (errno)
        fprintf(stderr, "Failed to open '%s': %s\n", argv[arg], strerror(errno)), exit(1);
    } else if (strcmp(argv[arg], "-m") == 0) {
      matchesFile = argv[++arg];
    } else {
      fprintf(stderr, "usage: %s -a Aunmatched.fasta -b B.unmatched.fasta < matches\n", argv[0]);
      exit(1);
    }
    arg++;
  }

  if ((Aoutput == 0L) || (Boutput == 0L) || (matchesFile == 0L)) {
    fprintf(stderr, "usage: %s -a Aunmatched.fasta -b B.unmatched.fasta < matches\n", argv[0]);
    exit(1);
  }

  atacMatchList  ML1(matchesFile, 'm', false);
  atacMatchList  ML2(matchesFile, 'm', false);

  ML1.sort1();  //  Sorted by first index
  ML2.sort2();  //  Sorted by second index

  seqCache           *W1 = ML1._seq1;
  seqCache           *W2 = ML1._seq2;


  //  For every match,
  //    find the match before and the match after, on both axes
  //    




  //  Extract unmapped in sequence 1

  ML.sort1();
  W = ML._seq1;
  W->find(ML[0]->iid1);
  S = W->getSequenceInCore();
  for (uint32 i=1; i<ML.numMatches(); i++) {
    atacMatch *l = ML[i-1];
    atacMatch *r = ML[i];

    if (l->iid1 != r->iid1)
      continue;

    if (l->iid1 != S->getIID()) {
      delete S;
      W->find(l->iid1);
      S = W->getSequenceInCore();
    }

    //  Extract from (l->pos1 + l->len1) to (r->pos1), if it's longer than 20bp
    //
    if (l->pos1 + l->len1 + 20 < r->pos1)
      writeGaplessSequence(Aoutput,
                           S,
                           l->pos1 + l->len1,
                           r->pos1);
  }

  //  Extract unmapped in sequence 2

  ML.sort2();
  W = ML._seq2;
  W->find(ML[0]->iid2);
  S = W->getSequenceInCore();
  for (uint32 i=1; i<ML.numMatches(); i++) {
    atacMatch *l = ML[i-1];
    atacMatch *r = ML[i];

    if (l->iid2 != r->iid2)
      continue;

    if (l->iid2 != S->getIID()) {
      delete S;
      W->find(l->iid2);
      S = W->getSequenceInCore();
    }

    //  Extract from (l->pos2 + l->len2) to (r->pos2), if it's longer than 20bp
    //
    if (l->pos2 + l->len2 + 20 < r->pos2)
      writeGaplessSequence(Boutput,
                           S,
                           l->pos2 + l->len2,
                           r->pos2);
  }


  fclose(Aoutput);
  fclose(Boutput);

  return(0);
}