File: AfgBasWriter.cpp

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 (112 lines) | stat: -rw-r--r-- 2,987 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
#include <pbdata/amos/AfgBasWriter.hpp>

unsigned char AfgBasWriter::pacbioQVtoPhredQV(unsigned char pacbio)
{
    return (unsigned char)floor(10.0 * log10(1.0 + pow(10.0, pacbio / 100.0)) + 0.5);
}

AfgBasWriter::AfgBasWriter()
{
    firstRecord = true;
    recordCount = 1;
    defaultQuality = 5;
}

AfgBasWriter::~AfgBasWriter()
{
    firstRecord = true;
    recordCount = 1;
    defaultQuality = 5;
}

void AfgBasWriter::Initialize(std::string _afgFileName)
{
    afgFileName = _afgFileName;
    CrucialOpen(afgFileName, afgOut);
}

void AfgBasWriter::Close() { afgOut.close(); }

void AfgBasWriter::SetDefaultQuality(int _defaultQuality) { defaultQuality = _defaultQuality; }

int AfgBasWriter::Write(SMRTSequence &seq)
{
    if (firstRecord) {
        WriteHeader();
        firstRecord = false;
    }
    WriteOpen();
    WriteIdentifier(seq);
    WriteBases(seq);
    WriteQualities(seq);
    WriteClose();
    return 1;
}

void AfgBasWriter::WriteHeader()
{
    afgOut << "{UNV" << std::endl;
    afgOut << "iid:1" << std::endl;
    afgOut << "com:" << std::endl;
    afgOut << "generated by AfgBasWriter" << std::endl;
    afgOut << "Mon Jun 28 14:43:52 2010" << std::endl;  // TODO put in real date
    afgOut << "." << std::endl << "}" << std::endl;
    afgOut << "{LIB" << std::endl << "iid:1" << std::endl;
    afgOut << "{DST" << std::endl
           << "mea:0" << std::endl
           << "std:0" << std::endl
           << "}" << std::endl
           << "}" << std::endl;
}

void AfgBasWriter::WriteOpen(void)
{
    afgOut << "{RED" << std::endl;
    afgOut << "frg:" << recordCount + 1 << std::endl;
    afgOut << "iid:" << recordCount << std::endl;
}

void AfgBasWriter::WriteIdentifier(SMRTSequence &seq)
{
    afgOut << "clr:0," << seq.length << std::endl;

    afgOut << "eid:";
    std::string fastaTitle;
    seq.GetFASTATitle(fastaTitle);
    afgOut << fastaTitle << std::endl;
}

void AfgBasWriter::WriteClose()
{
    recordCount++;
    afgOut << "}" << std::endl;
    afgOut << "{FRG" << std::endl;
    afgOut << "iid:" << recordCount << std::endl;
    afgOut << "lib:1" << std::endl << "typ:I" << std::endl << "}" << std::endl;
    recordCount++;
}

void AfgBasWriter::WriteBases(SMRTSequence &seq)
{
    afgOut << "seq:" << std::endl;
    (static_cast<DNASequence *>(&seq))->PrintSeq(afgOut, lineLength);
    afgOut << "." << std::endl;
}

void AfgBasWriter::WriteQualities(SMRTSequence &seq)
{
    afgOut << "qlt:" << std::endl;
    DNALength i;
    for (i = 0; i < seq.length; i++) {
        unsigned char quality = seq.qual.data ? seq.qual[i] : defaultQuality;
        quality = quality + charToQuality;
        quality = quality > maxAfgQuality ? maxAfgQuality : quality;
        quality = quality < minAfgQuality ? minAfgQuality : quality;
        afgOut << quality;
        if (i > 0 and (i + 1) % lineLength == 0) afgOut << std::endl;
    }
    if (i == 0 or i % lineLength != 0) {
        afgOut << std::endl;
    }
    afgOut << "." << std::endl;
}