| 1 |
#ifndef SEQLIB_CONTIG_PLOT_H |
| 2 |
#define SEQLIB_CONTIG_PLOT_H |
| 3 |
|
| 4 |
#include "SeqLib/BamRecord.h" |
| 5 |
|
| 6 |
namespace SeqLib { |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class SeqPlot { |
| 11 |
|
| 12 |
public: |
| 13 |
|
| 14 |
|
| 15 |
SeqPlot() : m_pad(5) {} |
| 16 |
|
| 17 |
|
| 18 |
std::string PlotAlignmentRecords(const BamRecordVector& brv) const; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
void SetView(const GenomicRegion& g) { m_view = g; } |
| 25 |
|
| 26 |
|
| 27 |
void SetPadding(int p) { m_pad = p; } |
| 28 |
|
| 29 |
private: |
| 30 |
|
| 31 |
|
| 32 |
BamRecordVector m_reads; |
| 33 |
|
| 34 |
|
| 35 |
GenomicRegion m_view; |
| 36 |
|
| 37 |
|
| 38 |
int m_pad; |
| 39 |
|
| 40 |
}; |
| 41 |
|
| 42 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |