File: VulgarPrinter.hpp

package info (click to toggle)
pbseqlib 0~20161219-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,924 kB
  • ctags: 5,123
  • sloc: cpp: 82,727; makefile: 305; python: 239; sh: 8
file content (53 lines) | stat: -rw-r--r-- 1,265 bytes parent folder | download | duplicates (4)
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
#ifndef _BLASR_VULGAR_ALIGNMENT_PRINTER_HPP_
#define _BLASR_VULGAR_ALIGNMENT_PRINTER_HPP_

#include <string>
#include <sstream>

namespace VulgarOutput{
template <typename T_Alignment>
int CreateVulgarString(T_Alignment &alignment, std::string &vstring) {
    std::stringstream vstream;
	VectorIndex b;
	int tGap, qGap, cGap;
	if (alignment.blocks.size() == 0) {
		vstring = "";
		return 1;
	}
	for (b = 0; b < alignment.blocks.size() - 1; b++) {
		tGap = (alignment.blocks[b+1].tPos 
			    - (alignment.blocks[b].length + 
				alignment.blocks[b].tPos));
		qGap = (alignment.blocks[b+1].qPos 
				- (alignment.blocks[b].length + 
				alignment.blocks[b].qPos));
		if (tGap > 0 and qGap > 0)
			cGap = abs(tGap - qGap);
		else 
			cGap = 0;
		tGap -= cGap;
		qGap -= cGap;
		vstream << " M " << alignment.blocks[b].length + cGap;
		if (tGap > 0) {
			vstream << " D " << tGap;
		}
		else {
			vstream << " I " << qGap;
		}
	}
	if (alignment.blocks.size() > 0) {
		vstream << " M " << alignment.blocks[alignment.blocks.size() - 1].length;
	}
	vstring = vstream.str();
	return 1;
}

template <typename T_Alignment>
void Print(T_Alignment &alignment, std::ostream &out) {
    std::string vstring;
	CreateVulgarString(alignment, vstring);
	out << vstring;
}
}

#endif