]> git.donarmstrong.com Git - bamtools.git/blob - src/utils/bamtools_pileup_engine.h
24d70849e16fd1ab8eccb137dd15573f853d80b0
[bamtools.git] / src / utils / bamtools_pileup_engine.h
1 // ***************************************************************************
2 // bamtools_pileup_engine.h (c) 2010 Derek Barnett, Erik Garrison
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 18 September 2010
6 // ---------------------------------------------------------------------------
7 // Provides pileup at position functionality for various tools.
8 // ***************************************************************************
9
10 #ifndef BAMTOOLS_PILEUP_ENGINE_H
11 #define BAMTOOLS_PILEUP_ENGINE_H
12
13 #include <api/BamAlignment.h>
14 #include <utils/utils_global.h>
15 #include <vector>
16
17 namespace BamTools {
18
19 // contains auxiliary data about a single BamAlignment
20 // at current position considered
21 struct UTILS_EXPORT PileupAlignment {
22   
23     // data members
24     BamAlignment Alignment;
25     int32_t PositionInAlignment;
26     bool IsCurrentDeletion;
27     bool IsNextDeletion;
28     bool IsNextInsertion;
29     int DeletionLength;
30     int InsertionLength;
31     bool IsSegmentBegin;
32     bool IsSegmentEnd;
33     
34     // ctor
35     PileupAlignment(const BamAlignment& al)
36         : Alignment(al)
37         , PositionInAlignment(-1)
38         , IsCurrentDeletion(false)
39         , IsNextDeletion(false)
40         , IsNextInsertion(false)
41         , DeletionLength(0)
42         , InsertionLength(0)
43         , IsSegmentBegin(false)
44         , IsSegmentEnd(false)
45     { }
46 };
47   
48 // contains all data at a position
49 struct UTILS_EXPORT PileupPosition {
50   
51     // data members
52     int RefId;
53     int Position;
54     std::vector<PileupAlignment> PileupAlignments;
55
56     // ctor
57     PileupPosition(const int& refId = 0,
58                    const int& position = 0, 
59                    const std::vector<PileupAlignment>& alignments = std::vector<PileupAlignment>())
60         : RefId(refId)
61         , Position(position)
62         , PileupAlignments(alignments)
63     { }
64 };
65   
66 class UTILS_EXPORT PileupVisitor {
67   
68     public:
69         PileupVisitor(void) { }
70         virtual ~PileupVisitor(void) { }
71   
72     public:
73         virtual void Visit(const PileupPosition& pileupData) =0;
74 };
75
76 class UTILS_EXPORT PileupEngine {
77   
78     public:
79         PileupEngine(void);
80         ~PileupEngine(void);
81         
82     public:
83         bool AddAlignment(const BamAlignment& al);
84         void AddVisitor(PileupVisitor* visitor);
85         void Flush(void);
86         
87     private:
88         struct PileupEnginePrivate;
89         PileupEnginePrivate* d;
90 };
91
92 } // namespace BamTools
93
94 #endif // BAMTOOLS_PILEUP_ENGINE_H