int main() {

	Punkt pierwszy(1, 5), drugi(1, 8), trzeci(4, 5), czwarty(4, 8);
	Kwadrat figura(pierwszy, drugi, trzeci, czwarty);

	figura.obwod();
	figura.pole();

	double szukana;
	DTab ala(0);

	ala.print();
	ala.add(3.6);
	ala.print();
	ala.add(4.9);
	ala.print();
	ala.add(4.9);
	ala.print();
	szukana = ala.get(6);
	cout << szukana << endl;
	ala.set(3.999, 3);
	ala.print();

	Zespolona pierwsza(1, 2);
	Zespolona druga(3, 4);
	Zespolona wynik;

	wynik.add(pierwsza, druga);
	wynik.Wypisz();
	wynik.sub(pierwsza, druga);
	wynik.Wypisz();
	wynik.mul(pierwsza, druga);
	wynik.Wypisz();
	wynik.div(pierwsza, druga);
	wynik.Wypisz();
	wynik.pow(pierwsza);
	wynik.Wypisz();

	return 0;
}
Esempio n. 2
0
fasta::SequenceList ScoringMatrix::backtrace_alignment_path(
    const fasta::Sequence& sequence, const profile::ProfileMap& profile,
    const FeatureScores& f_profile,
    int codon_length) {
  //creating polyA pseudoSequence representing the profile,
  //to know later where are the gaps in the profile
  fasta::Residue ala('A' + std::string(codon_length - 1, 'A'), {});
  fasta::Residue gap_residue('-' + std::string(codon_length - 1, 'A'), {});

  fasta::Sequence new_s1;
  fasta::Sequence new_s2;
  const size_t profile_length = profile.begin()->second.size();
  // TODO: i and j aren't great names...are they?
  size_t i = profile_length;
  size_t j = sequence.residues.size();

  //if bestScore isn't in the lower right corner, then add gaps
  //to new_s1 or new_s2
  ValueCoords best_score = find_best_score();

  // TODO: comparing value to size of something? fishy!
  if (best_score[0] != (signed)m_matrix_v.size()-1
      || best_score[1] != (signed)m_matrix_v[0].size()-1) {
    i = best_score[0];
    j = best_score[1];
    for (size_t k = profile_length; k > i; --k) {
      new_s1.residues.push_back(ala);
      new_s2.residues.push_back(gap_residue);
    }
    for (size_t k = sequence.residues.size(); k > j; --k) {
      new_s2.residues.push_back(sequence.residues[k - 1]);
      new_s1.residues.push_back(gap_residue);
    }
  }
  std::string current_matrix = "V";

  assert(m_matrix_v.size() == m_matrix_g.size());
  assert(m_matrix_v.size() == m_matrix_h.size());
  fasta::Residue new_res1;
  fasta::Residue new_res2;

  //trace back the matrix
  while (i > 0 || j > 0) {
    if (i > 0 && j > 0 && current_matrix == "V") {  //match/mismatch
      new_res1 = ala;
      new_res2 = sequence.residues[j - 1];
      // double profile_score = profile.at(
      //     sequence.residues[j - 1].codon[0])[i - 1];
      double profile_score = profile::get_score(profile, i - 1,
          sequence.residues[j - 1].codon[0]);
      double feature_score = 0;
      if (!m_no_feat) {
        for (auto& feat_name : sequence.residues[j - 1].features) {
          feature_score += f_profile.get_score(feat_name, i - 1);
        }
      }
      double final_score = profile_score + feature_score;
      if (m_matrix_v[i][j] != m_matrix_v[i-1][j-1] + final_score) {
        if (i > 0 && j > 0
            && compare_doubles::is_equal(m_matrix_v[i][j],
                                         m_matrix_g[i-1][j-1] + final_score)) {
          current_matrix = "G";
        } else if (i > 0 && j > 0
                   && compare_doubles::is_equal(m_matrix_v[i][j],
                                                m_matrix_h[i-1][j-1]
                                                + final_score)) {
          current_matrix = "H";
        }
      }
      --i;
      --j;
    } else if (j > 0 && current_matrix == "G") {  //gap in seq2
      new_res1 = gap_residue;
      new_res2 = sequence.residues[j - 1];
      if (compare_doubles::is_equal(m_matrix_g[i][j],
                                    m_matrix_v[i][j - 1] + m_gap_opening)) {
        current_matrix = "V";
      }
      else if (compare_doubles::is_equal(m_matrix_g[i][j],
                                         m_matrix_h[i][j - 1]
                                         + m_gap_opening)) {
        current_matrix = "H";
      }
      --j;
    } else if (i > 0 && current_matrix == "H") {  //gap in profile
      new_res1 = ala;
      new_res2 = gap_residue;
      if (compare_doubles::is_equal(m_matrix_h[i][j],
                                    m_matrix_v[i - 1][j] + m_gap_opening)) {
        current_matrix = "V";
      }
      else if (compare_doubles::is_equal(m_matrix_h[i][j],
                                         m_matrix_g[i - 1][j]
                                         + m_gap_opening)) {
        current_matrix = "G";
      }
      --i;
    }
    new_s1.residues.push_back(new_res1);
    new_s2.residues.push_back(new_res2);
  }
  //need to reverse the sequences, because tracing back the alignment goes
  //from the end to the beginning
  std::reverse(new_s1.residues.begin(), new_s1.residues.end());
  std::reverse(new_s2.residues.begin(), new_s2.residues.end());
  return {new_s1, new_s2};
}