Debian Codegraph @

SeqLib/SeqPlot.h

raw symbols SCIP
1 #ifndef SEQLIB_CONTIG_PLOT_H
2 #define SEQLIB_CONTIG_PLOT_H
3
4 #include "SeqLib/BamRecord.h"
5
6 namespace SeqLib {
7
8 /** Object for creating ASCII alignment plots
9 */
10 class SeqPlot {
11
12 public:
13
14 /** Create an empty plotter object */
15 SeqPlot() : m_pad(5) {}
16
17 /** Plot aligned read by stacking them in an IGV-like view */
18 std::string PlotAlignmentRecords(const BamRecordVector& brv) const;
19
20 /** Set the view window
21 * @param g Window to view reads in. Reads that
22 * start or end outside of this window are not plotted
23 */
24 void SetView(const GenomicRegion& g) { m_view = g; }
25
26 /** Set the padding between reads (default is 5) */
27 void SetPadding(int p) { m_pad = p; }
28
29 private:
30
31 // reads that align to the contig
32 BamRecordVector m_reads;
33
34 // view window
35 GenomicRegion m_view;
36
37 // padding when placing reads
38 int m_pad;
39
40 };
41
42 /** A single plotted read */
43 struct PlottedRead {
44
45 int pos;
46 std::string seq;
47 std::string info;
48
49 PlottedRead(int p, const std::string& s, const std::string& i) : pos(p), seq(s), info(i) {}
50
51 bool operator<(const PlottedRead& pr) const {
52 return (pos < pr.pos);
53 }
54
55 };
56
57 typedef std::vector<PlottedRead> PlottedReadVector;
58
59 /** A plotted line */
60 struct PlottedReadLine {
61
62 PlottedReadLine() : available(0), contig_len(0), pad(5) {}
63
64 std::vector<PlottedRead*> read_vec;
65 int available;
66 int contig_len;
67
68 int pad;
69
70 void addRead(PlottedRead *r) {
71 read_vec.push_back(r);
72 available = r->pos + r->seq.length() + pad;
73 }
74
75 bool readFits(const PlottedRead &r) {
76 return (r.pos >= available);
77 }
78
79 friend std::ostream& operator<<(std::ostream& out, const PlottedReadLine &r) {
80 int last_loc = 0;
81 for (std::vector<PlottedRead*>::const_iterator i = r.read_vec.begin(); i != r.read_vec.end(); ++i) {
82 // for (auto& i : r.read_vec) {
83 assert((*i)->pos - last_loc >= 0);
84 out << std::string((*i)->pos - last_loc, ' ') << (*i)->seq;
85 last_loc = (*i)->pos + (*i)->seq.length();
86 }
87 int name_buff = r.contig_len - last_loc;
88 assert(name_buff < 1e6);
89 out << std::string(std::max(name_buff, 5), ' ');
90 for (std::vector<PlottedRead*>::const_iterator i = r.read_vec.begin(); i != r.read_vec.end(); ++i) {
91 //for (auto& i : r.read_vec) { // add the data
92 out << (*i)->info << ",";
93 }
94 return out;
95 }
96
97 };
98
99 typedef std::vector<PlottedReadLine> PlottedReadLineVector;
100
101
102 }
103
104
105
106 #endif