File: OutputSample.hpp

package info (click to toggle)
pbseqlib 5.3.1%2Bdfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,136 kB
  • sloc: cpp: 77,246; python: 570; makefile: 312; sh: 111; ansic: 9
file content (67 lines) | stat: -rw-r--r-- 1,587 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
#ifndef _SIMULATOR_OUTPUT_SAMPLE_HPP_
#define _SIMULATOR_OUTPUT_SAMPLE_HPP_

#include <alignment/simulator/QualitySample.hpp>
#include <pbdata/SMRTSequence.hpp>

class OutputSample
{
public:
    enum Type
    {
        Match,
        Insertion,
        Deletion,
        Substitution
    };

    std::vector<QualitySample> qualities;
    std::vector<Nucleotide> nucleotides;
    Type type;

    void Resize(int size)
    {
        qualities.resize(size);
        nucleotides.resize(size);
    }

    void CopyFromSeq(SMRTSequence &seq, int pos, int length = 1)
    {
        Resize(length);
        int i;
        for (i = 0; i < length; i++) {
            qualities[i].CopyFromSequence(seq, pos + i);
            nucleotides[i] = seq.seq[pos + i];
        }
    }

    void Write(std::ofstream &out)
    {

        out.write((char *)&type, sizeof(type));
        unsigned nNuc = nucleotides.size();

        out.write((char *)&nNuc, sizeof(unsigned));
        for (size_t i = 0; i < qualities.size(); i++) {
            qualities[i].Write(out);
        }
        assert(nNuc == qualities.size());
        out.write((char *)&nucleotides[0], sizeof(Nucleotide) * nucleotides.size());
    }

    void Read(std::ifstream &in)
    {
        in.read((char *)&type, sizeof(Type));
        int nNuc;
        in.read((char *)&nNuc, sizeof(int));
        qualities.resize(nNuc);
        int i;
        for (i = 0; i < nNuc; i++) {
            qualities[i].Read(in);
        }
        nucleotides.resize(nNuc);
        in.read((char *)&nucleotides[0], sizeof(Nucleotide) * nNuc);
    }
};

#endif