File: AlignmentCommon.hpp

package info (click to toggle)
salmon 1.10.3%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,148 kB
  • sloc: cpp: 200,707; ansic: 171,082; sh: 859; python: 792; makefile: 238
file content (101 lines) | stat: -rw-r--r-- 2,880 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef __ALIGNMENTCOMMON_H__
#define __ALIGNMENTCOMMON_H__

#include <atomic>
#include <memory>
#include <mutex>


// logger includes
#include "spdlog/spdlog.h"

extern "C" {
#include "io_lib/os.h"
#include "io_lib/scram.h"
#undef max
#undef min
}

struct UnpairedRead;
struct ReadPair;
class Transcript;


// Common functionalities to different alignment models
class AlignmentCommon {
public:
  AlignmentCommon()
    : burnedIn_(false)
  { }

  bool burnedIn() { return burnedIn_; }
  void burnedIn(bool burnedIn) { burnedIn_ = burnedIn; }

  void setLogger(std::shared_ptr<spdlog::logger> logger) { logger_ = logger; }
  bool hasLogger() { return (logger_) ? true : false; }


  static bool hasIndel(ReadPair& hit);
  static bool hasIndel(UnpairedRead& hit);

protected:
  enum AlignmentModelChar {
    ALN_A = 0,
    ALN_C = 1,
    ALN_G = 2,
    ALN_T = 3,
    ALN_DASH = 4,
    ALN_SOFT_CLIP = 5,
    ALN_HARD_CLIP = 6,
    ALN_PAD = 7,
    ALN_REF_SKIP = 8
  };

  static bool hasIndel(bam_seq_t* read);
  static void setBasesFromCIGAROp_(enum cigar_op op, size_t& curRefBase, size_t& curReadBase);
  static char opToChr(enum cigar_op op);

  template<typename T>
  static int32_t alnLen(const T& aln, const T& primary) {
    const auto l = aln.readLen();
    return l != 0 ? l : primary.readLen();
  }

  struct ErrorCount {
  protected:
    int32_t insertions_, deletions_, mismatches_, matches_;
    int32_t sclips_, hclips_; // soft and hard clips
    int32_t fclips_, bclips_; // clips at front and at back
    friend AlignmentCommon;

  public:
    inline int32_t clips() const { return sclips_ + hclips_; }
    // Indels + mismatches
    inline int32_t ims() const { return insertions_ + deletions_ + mismatches_; }
    // Should be equal to the length of the query sequence
    inline int32_t length() const { return insertions_ + mismatches_ + matches_ + sclips_; }
    void clear() {
      insertions_ = deletions_ = mismatches_ = matches_ = sclips_ = hclips_ = fclips_ = bclips_ = 0;
    }
    inline int32_t insertions() const { return insertions_; }
    inline int32_t deletions() const { return deletions_; }
    inline int32_t mismatches() const { return mismatches_; }
    inline int32_t matches() const { return matches_; }
    inline int32_t sclips() const { return sclips_; }
    inline int32_t hclips() const { return hclips_; }
    inline int32_t fclips() const { return fclips_; }
    inline int32_t bclips() const { return bclips_; }

    bool computeErrorCount(bam_seq_t* read, bam_seq_t* primary, Transcript& ref,
                           const char* src);
  };
  bool computeErrorCount(bam_seq_t* read, bam_seq_t* primary, Transcript& ref,
                         ErrorCount& counts, const char* src);

  std::shared_ptr<spdlog::logger> logger_;
  std::atomic<bool> burnedIn_;

  std::mutex throwMutex_;
};

#endif /* __ALIGNMENTCOMMON_H__ */