Ejemplo n.º 1
0
VariantContig::VariantContig(
        RawVariant const& var,
        Fasta& ref,
        int flank,
        std::string const& seqname
        )
{
    uint64_t seqlen = ref.seqlen(seqname);
    uint64_t preflank_len = var.pos <= flank ? var.pos - 1 : flank;
    _start = std::max(1ul, var.pos - preflank_len);
    _stop = std::min(var.pos + var.ref.size() - 1 + flank, seqlen);
    uint64_t postflank_start = var.pos + var.ref.size();
    uint64_t postflank_len = _stop - postflank_start + 1;
    
    // build sequence
    if (preflank_len)
        _sequence = ref.sequence(seqname, _start, preflank_len); // left flank
    _sequence += var.alt;
    if (postflank_start <= seqlen && postflank_len)
        _sequence += ref.sequence(seqname, postflank_start, postflank_len); // right flank
    
    // build cigar
    if (preflank_len)
        _cigar.push_back(preflank_len, MATCH);

    if (var.ref.size() > var.alt.size()) {
        _cigar.push_back(var.alt.size(), MATCH);
        _cigar.push_back(var.ref.size() - var.alt.size(), DEL);
    } else if (var.ref.size() < var.alt.size()) {
        _cigar.push_back(var.ref.size(), MATCH);
        _cigar.push_back(var.alt.size() - var.ref.size(), INS);
    } else {
        _cigar.push_back(var.alt.size(), MATCH);
    }

    if (postflank_len)
        _cigar.push_back(postflank_len, MATCH);
}
Ejemplo n.º 2
0
void align_against_collection(string &read, Fasta &rep, int forbidden_rep_id,
                              bool reverse_ref, bool reverse_both, bool local,
                             AlignBox *box, Cost segment_cost)
{
  
  int best_score = MINUS_INF ;
  box->ref_nb = MINUS_INF ;
  int best_best_i = (int) string::npos ;
  int best_best_j = (int) string::npos ;
  int best_first_i = (int) string::npos ;
  int best_first_j = (int) string::npos ;

  vector<pair<int, int> > score_r;

  DynProg::DynProgMode dpMode = DynProg::LocalEndWithSomeDeletions;
  if (local==true) dpMode = DynProg::Local;

  // With reverse_ref, the read is reversed to prevent calling revcomp on each reference sequence
  string sequence_or_rc = revcomp(read, reverse_ref);
  
  for (int r = 0 ; r < rep.size() ; r++)
    {
      if (r == forbidden_rep_id)
        continue;

      DynProg dp = DynProg(sequence_or_rc, rep.sequence(r),
			   dpMode, // DynProg::SemiGlobalTrans, 
			   segment_cost, // DNA
			   reverse_both, reverse_both,
                          rep.read(r).marked_pos);

      bool onlyBottomTriangle = !local ;
      int score = dp.compute(onlyBottomTriangle, BOTTOM_TRIANGLE_SHIFT);
      
      if (local==true){ 
	dp.backtrack();
      }
      
      if (score > best_score)
	{
	  best_score = score ;
	  best_best_i = dp.best_i ;
	  best_best_j = dp.best_j ;
	  best_first_i = dp.first_i ;
	  best_first_j = dp.first_j ;
	  box->ref_nb = r ;
	  box->ref_label = rep.label(r) ;

          if (!local)
            dp.backtrack();
          box->marked_pos = dp.marked_pos_i ;
	}
	
	score_r.push_back(make_pair(score, r));

	// #define DEBUG_SEGMENT      

#ifdef DEBUG_SEGMENT	
	cout << rep.label(r) << " " << score << " " << dp.best_i << endl ;
#endif

    }
    sort(score_r.begin(),score_r.end(),comp_pair);

  box->ref = rep.sequence(box->ref_nb);
  box->del_right = reverse_both ? best_best_j : box->ref.size() - best_best_j - 1;
  box->del_left = best_first_j;
  box->start = best_first_i;
  
  box->score = score_r;

#ifdef DEBUG_SEGMENT	
  cout << "best: " << box->ref_label << " " << best_score ;
  cout << "del/del2/begin:" << (box->del_right) << "/" << (box->del_left) << "/" << (box->start) << endl;
  cout << endl;
#endif

  if (reverse_ref)
    // Why -1 here and +1 in dynprog.cpp /// best_i = m - best_i + 1 ;
    best_best_i = read.length() - best_best_i - 1 ;

  box->end = best_best_i ;
}