File: StickAlignmentPrinter.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 (118 lines) | stat: -rw-r--r-- 4,655 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef _BLASR_STICK_ALIGNMENT_PRINTER_HPP_
#define _BLASR_STICK_ALIGNMENT_PRINTER_HPP_

#include <fstream>
#include <iostream>
#include <string>

#include <alignment/algorithms/alignment/AlignmentUtils.hpp>
#include <alignment/datastructures/alignment/Alignment.hpp>

template <typename T_Alignment, typename T_QuerySequence, typename T_TargetSequence>
void StickPrintAlignment(T_Alignment &alignment, T_QuerySequence &query, T_TargetSequence &text,
                         std::ostream &out, unsigned int qPrintStart = 0,
                         unsigned int tPrintStart = 0, int maxPrintLength = 50)
{
    //
    // Eventually hack to add options for alignment format.
    //
    std::string queryStr, alignStr, textStr;
    char gapChar = '-';
    //
    // [q/t]PrintStart are the beginning/ending of the subsequence that
    // is being printed however the actual alignment begins at
    // [q/t]PrintStart + alignment->[q/t]Pos, since there may be a small
    // gap between the beginning of the alignment and the beginning of
    // the substring that is aligned.
    //
    out << "         Query: " << alignment.qName << std::endl;
    out << "        Target: " << alignment.tName << std::endl;
    out << "         Model: a hybrid of global/local non-affine alignment" << std::endl;
    out << "     Raw score: " << alignment.score << std::endl;
    out << "        Map QV: " << alignment.mapQV << std::endl;
    out << "  Query strand: " << alignment.qStrand << std::endl;
    out << " Target strand: " << alignment.tStrand << std::endl;
    if (alignment.blocks.size() > 0) {
        out << "   QueryRange: " << qPrintStart + alignment.qPos  //alignment.blocks[0].qPos
            << " -> "
            << (qPrintStart + alignment.qPos + +alignment.blocks[alignment.blocks.size() - 1].qPos +
                alignment.blocks[alignment.blocks.size() - 1].length)
            << " of " << alignment.qLength << std::endl;
        out << "  TargetRange: " << tPrintStart + alignment.tPos  //alignment.blocks[0].tPos
            << " -> "
            //				<< (tPrintStart + alignment.blocks[alignment.blocks.size() - 1].tPos +
            << (tPrintStart + alignment.tPos + alignment.blocks[alignment.blocks.size() - 1].tPos +
                alignment.blocks[alignment.blocks.size() - 1].length)
            << " of " << alignment.tLength << std::endl;
    } else {
        out << "   QueryRange: NONE " << std::endl;
        out << "  TargetRange: NONE " << std::endl;
    }

    if (alignment.blocks.size() == 0) return;
    CreateAlignmentStrings(alignment, query.seq, text.seq, textStr, alignStr, queryStr,
                           query.length, text.length);

    //
    // Process any gaps at the beginning of
    // the alignment.
    //

    DNALength qPos, tPos;

    int coordsPrintWidth = MAX(GetNumberWidth(alignment.qPos + qPrintStart + query.length),
                               GetNumberWidth(alignment.tPos + tPrintStart + query.length));

    //
    // Now print the alignment
    VectorIndex lineLength = maxPrintLength;
    if (lineLength > textStr.size()) lineLength = textStr.size();

    std::string textLine, queryLine, alignLine;
    DNALength pos = 0;
    tPos = alignment.tPos;
    qPos = alignment.qPos;
    int spacePad = 2;
    std::string coordPadding(spacePad, ' ');
    std::string alignStrPadding(coordsPrintWidth + spacePad, ' ');

    while (lineLength > 0) {
        textLine.assign(textStr, pos, lineLength);
        alignLine.assign(alignStr, pos, lineLength);
        queryLine.assign(queryStr, pos, lineLength);
        out.width(coordsPrintWidth);
        out << qPrintStart + qPos;
        out.width(0);
        out << coordPadding << queryLine << std::endl;
        out << alignStrPadding << alignLine << std::endl;
        out.width(coordsPrintWidth);
        out << tPrintStart + tPos;
        out.width(0);
        out << coordPadding << textLine << std::endl;
        out << std::endl;

        pos += lineLength;
        tPos += lineLength;
        qPos += lineLength;
        //
        // Adjust tPos and qPos for indels.
        //
        VectorIndex p;
        for (p = 0; p < textLine.size(); p++) {
            if (textLine[p] == gapChar) tPos--;
        }
        for (p = 0; p < queryLine.size(); p++) {
            if (queryLine[p] == gapChar) qPos--;
        }

        lineLength = maxPrintLength;
        if (textStr.size() < (pos + lineLength)) {
            // sets lineLength to 0 on the last iteration
            lineLength = textStr.size() - pos;
        } else {
            lineLength = maxPrintLength;
        }
    }
}

#endif  // _BLASR_STICK_ALIGNMENT_PRINTER_HPP_