Commit 1dc57ab4 authored by Haowen Zhang's avatar Haowen Zhang
Browse files

Move Tn5 shift function to MappingProcessor.

parent cbdc8f8e
Loading
Loading
Loading
Loading
+4 −43
Original line number Diff line number Diff line
@@ -1289,7 +1289,7 @@ void Chromap<MappingRecord>::MapPairedEndReads() {
    // OutputMappingStatistics(num_reference_sequences,
    // mappings_on_diff_ref_seqs_, mappings_on_diff_ref_seqs_);
    if (Tn5_shift_) {
      ApplyTn5ShiftOnPairedEndMapping(num_reference_sequences,
      mapping_processor.ApplyTn5ShiftOnMappings(num_reference_sequences,
                                                mappings_on_diff_ref_seqs_);
    }

@@ -1404,24 +1404,6 @@ void Chromap<MappingRecord>::OutputMappings(
                         mappings);
}

template <typename MappingRecord>
void Chromap<MappingRecord>::ApplyTn5ShiftOnPairedEndMapping(
    uint32_t num_reference_sequences,
    std::vector<std::vector<MappingRecord>> &mappings) {
  uint64_t num_shifted_mappings = 0;
  for (auto &mappings_on_one_ref_seq : mappings) {
    for (auto &mapping : mappings_on_one_ref_seq) {
      // mapping.fragment_start_position += 4;
      // mapping.positive_alignment_length -= 4;
      // mapping.fragment_length -= 9;
      // mapping.negative_alignment_length -= 5;
      mapping.Tn5Shift();
      ++num_shifted_mappings;
    }
  }
  std::cerr << "# shifted mappings: " << num_shifted_mappings << ".\n";
}

template <typename MappingRecord>
void Chromap<MappingRecord>::MapSingleEndReads() {
  double real_start_time = GetRealTime();
@@ -1730,8 +1712,8 @@ void Chromap<MappingRecord>::MapSingleEndReads() {
                                        mapping_processor);
  } else {
    if (Tn5_shift_) {
      ApplyTn5ShiftOnSingleEndMapping(num_reference_sequences,
                                      &mappings_on_diff_ref_seqs_);
      mapping_processor.ApplyTn5ShiftOnMappings(num_reference_sequences,
                                                mappings_on_diff_ref_seqs_);
    }

    if (remove_pcr_duplicates_) {
@@ -1768,27 +1750,6 @@ void Chromap<MappingRecord>::MapSingleEndReads() {
  std::cerr << "Total time: " << GetRealTime() - real_start_time << "s.\n";
}

template <typename MappingRecord>
void Chromap<MappingRecord>::ApplyTn5ShiftOnSingleEndMapping(
    uint32_t num_reference_sequences,
    std::vector<std::vector<MappingRecord>> *mappings) {
  uint64_t num_shifted_mappings = 0;
  for (auto &mappings_on_one_ref_seq : *mappings) {
    for (auto &mapping : mappings_on_one_ref_seq) {
      mapping.Tn5Shift();
      // uint8_t strand = mapping.direction & 1;
      // if (strand == 1) {
      //  mapping.fragment_start_position += 4;
      //  mapping.fragment_length -= 4;
      //} else {
      //  mapping.fragment_length -= 5;
      //}
      ++num_shifted_mappings;
    }
  }
  std::cerr << "# shifted mappings: " << num_shifted_mappings << ".\n";
}

template <typename MappingRecord>
uint32_t Chromap<MappingRecord>::LoadSingleEndReadsWithBarcodes(
    SequenceBatch *read_batch, SequenceBatch *barcode_batch) {
+0 −8
Original line number Diff line number Diff line
@@ -153,20 +153,12 @@ class Chromap {
                                           const SequenceBatch &read_batch1,
                                           const SequenceBatch &read_batch2);

  void ApplyTn5ShiftOnPairedEndMapping(
      uint32_t num_reference_sequences,
      std::vector<std::vector<MappingRecord> > &mappings);

  // For single-end read mapping
  void MapSingleEndReads();

  uint32_t LoadSingleEndReadsWithBarcodes(SequenceBatch *read_batch,
                                          SequenceBatch *barcode_batch);

  void ApplyTn5ShiftOnSingleEndMapping(
      uint32_t num_reference_sequences,
      std::vector<std::vector<MappingRecord> > *mappings);

  // Supportive functions
  void ConstructIndex();

+18 −0
Original line number Diff line number Diff line
@@ -56,6 +56,10 @@ class MappingProcessor {
      int multi_mapping_allocation_distance,
      std::vector<std::vector<MappingRecord>> &mappings) const;

  void ApplyTn5ShiftOnMappings(
      uint32_t num_reference_sequences,
      std::vector<std::vector<MappingRecord> > &mappings);

 private:
  void BuildAugmentedTree(
      uint32_t ref_id,
@@ -368,6 +372,20 @@ void MappingProcessor<MappingRecord>::AllocateMultiMappings(
            << num_multi_mappings_without_overlapping_unique_mappings << ".\n";
}

template <typename MappingRecord>
void MappingProcessor<MappingRecord>::ApplyTn5ShiftOnMappings(
    uint32_t num_reference_sequences,
    std::vector<std::vector<MappingRecord>> &mappings) {
  uint64_t num_shifted_mappings = 0;
  for (auto &mappings_on_one_ref_seq : mappings) {
    for (auto &mapping : mappings_on_one_ref_seq) {
      mapping.Tn5Shift();
      ++num_shifted_mappings;
    }
  }
  std::cerr << "# shifted mappings: " << num_shifted_mappings << ".\n";
}

}  // namespace chromap

#endif  // MAPPING_PROCESSOR_H_