コード例 #1
0
ファイル: ClassifyVariant.cpp プロジェクト: Rashesh7/TS
void AlleleIdentity::CalculateWindowForVariant(LocalReferenceContext seq_context, const string &local_contig_sequence, int DEBUG) {

  // If we have an invalid vcf candidate, set a length zero window and exit
  if (!seq_context.context_detected) {
    start_window = seq_context.position0;
    end_window = seq_context.position0;
    return;
  }

  // Check for MNRs first, for InDelLengths 2,3,4
  if (status.isIndel and !status.isHPIndel and inDelLength < 5)
    for (int rep_period = 2; rep_period < 5; rep_period++)
      if (IdentifyMultiNucRepeatSection(local_contig_sequence, seq_context, rep_period)) {
        if (DEBUG > 0) {
          cout << "MNR found in allele " << seq_context.reference_allele << " -> " << altAllele << endl;
          cout << "Window for allele " << altAllele << ": (" << start_window << ") ";
          for (int p_idx = start_window; p_idx < end_window; p_idx++)
            cout << local_contig_sequence.at(p_idx);
          cout << " (" << end_window << ") " << endl;
        }
        return; // Found a matching period and computed window
      }

  // OK, not an MNR. Moving on along to InDels.
  // need at least one anchor base left and right of InDel allele
  if (status.isIndel) {
    if (status.isDeletion) {
      start_window = seq_context.my_hp_start_pos.at(anchor_length) - 1;
      end_window = seq_context.right_hp_start;
    }
    else { // Insertions require a bit more thought
      if (altAllele.at(anchor_length) == altAllele.at(anchor_length - 1))
        start_window = seq_context.my_hp_start_pos.at(anchor_length - 1) - 1;
      else
        start_window = seq_context.position0 + anchor_length - 1; // 1 anchor base before we insert a new HP
      if (start_window < 0)
        start_window = 0; // Safety for something happening in the first HP of the ref. and not left-aligned...
      end_window = seq_context.right_hp_start;
      if (altAllele.at(altAllele.length() - 1) == seq_context.ref_right_hp_base)
        end_window += seq_context.right_hp_length;
    }
    if ((unsigned int)end_window < local_contig_sequence.length())
      end_window++; // anchor base to the right
  }
  else {
    // SNPs and MNVs are 1->1 base replacements
    // make window as short as possible, only around bases to be replaced
    // Think: include full HPs affected like in the InDel case? <- no for now, like in old code
    start_window = seq_context.position0;
    end_window = seq_context.position0 + seq_context.reference_allele.length();
  } // */

  if (DEBUG > 0) {
    cout << "Window for allele " << altAllele << ": (" << start_window << ") ";
    for (int p_idx = start_window; p_idx < end_window; p_idx++)
      cout << local_contig_sequence.at(p_idx);
    cout << " (" << end_window << ") " << endl;
  }
}
コード例 #2
0
ファイル: ClassifyVariant.cpp プロジェクト: Lingrui/TS
void AlleleIdentity::CalculateWindowForVariant(const LocalReferenceContext &seq_context, int DEBUG,
    const ReferenceReader &ref_reader, int chr_idx) {

  // If we have an invalid vcf candidate, set a length zero window and exit
  if (!seq_context.context_detected or status.isProblematicAllele) {
    start_window = seq_context.position0;
    end_window = seq_context.position0;
    return;
  }

  // Check for MNRs first, for InDelLengths 2,3,4,5
  if (status.isIndel and !status.isHPIndel and inDelLength < 5)
    for (int rep_period = 2; rep_period < 6; rep_period++)
      if (IdentifyMultiNucRepeatSection(seq_context, rep_period, ref_reader, chr_idx)) {
        if (DEBUG > 0) {
          cout << "MNR found in allele " << seq_context.reference_allele << " -> " << altAllele << endl;
          cout << "Window for allele " << altAllele << ": (" << start_window << ") ";
          for (int p_idx = start_window; p_idx < end_window; p_idx++)
            cout << ref_reader.base(chr_idx,p_idx);
          cout << " (" << end_window << ") " << endl;
        }
        return; // Found a matching period and computed window
      }

  // not an MNR. Moving on along to InDels.
  if (status.isIndel) {
	// Default variant window
    end_window = seq_context.right_hp_start +1; // Anchor base to the right of allele
    start_window = seq_context.position0;

    // Adjustments if necessary
    if (status.isDeletion)
      if (seq_context.my_hp_start_pos[left_anchor] == seq_context.my_hp_start_pos[0])
        start_window = seq_context.my_hp_start_pos[0] - 1;

    if (status.isInsertion) {
      if (left_anchor == 0) {
        start_window = seq_context.my_hp_start_pos[0] - 1;
      }
      else if (altAllele[left_anchor] == altAllele[left_anchor - 1] and
          seq_context.position0 > (seq_context.my_hp_start_pos[left_anchor - 1] - 1)) {
        start_window = seq_context.my_hp_start_pos[left_anchor - 1] - 1;
      }
      if (altAllele[altAllele.length() - 1] == seq_context.ref_right_hp_base) {
        end_window += seq_context.right_hp_length;
      }
    }

    // Safety
    if (start_window < 0)
      start_window = 0;
    if (end_window > ref_reader.chr_size(chr_idx))
      end_window = ref_reader.chr_size(chr_idx);
  }
  else {
    // SNPs and MNVs are 1->1 base replacements
    start_window = seq_context.position0;
    end_window = seq_context.position0 + seq_context.reference_allele.length();
  } // */

  if (DEBUG > 0) {
    cout << "Window for allele " << altAllele << ": (" << start_window << ") ";
    for (int p_idx = start_window; p_idx < end_window; p_idx++)
      cout << ref_reader.base(chr_idx,p_idx);
    cout << " (" << end_window << ") " << endl;
  }
}