File: VulgarPrinter.hpp

package info (click to toggle)
pbseqlib 5.3.5%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,020 kB
  • sloc: cpp: 77,250; python: 331; sh: 103; makefile: 41
file content (52 lines) | stat: -rw-r--r-- 1,431 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
#ifndef _BLASR_VULGAR_ALIGNMENT_PRINTER_HPP_
#define _BLASR_VULGAR_ALIGNMENT_PRINTER_HPP_

#include <sstream>
#include <string>

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 = std::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