File: DNATupleList.h

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 (52 lines) | stat: -rw-r--r-- 1,596 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 TUPLES_DNA_TUPLE_LIST_H_
#define TUPLES_DNA_TUPLE_LIST_H_

#include <vector>

#include <alignment/tuples/DNATuple.h>

template <typename Sequence>
DNALength StoreTuplePosList(Sequence seq, TupleMetrics &tm,
                            std::vector<PositionDNATuple> &tupleList)
{
    //
    // Do this faster later on with a suffix tree -- faster than n log n construction time.
    //
    DNALength s;

    PositionDNATuple tempTuple;
    for (s = 0; s < seq.length - tm.tupleSize + 1; s++) {
        if (tempTuple.FromStringLR(&(seq.seq[s]), tm)) {
            tempTuple.pos = s;
            tupleList.push_back(tempTuple);
        }
    }

    std::sort(tupleList.begin(), tupleList.end());

    //
    // Be nice and leave the pos list in ascending sorted order,
    // even though the top of this function does not specify it.
    //

    return tupleList.size();
}

void WriteTuplePosList(std::vector<PositionDNATuple> &tupleList, int tupleSize, std::ofstream &out)
{
    DNALength tupleListLength = tupleList.size();
    out.write((char *)&tupleSize, sizeof(tupleSize));
    out.write((char *)&tupleListLength, sizeof(DNALength));
    out.write((char *)&tupleList[0], sizeof(PositionDNATuple) * tupleList.size());
}

void ReadTuplePosList(std::ifstream &in, std::vector<PositionDNATuple> &tupleList, int &tupleSize)
{
    DNALength tupleListLength;
    in.read((char *)&tupleSize, sizeof(int));
    in.read((char *)&tupleListLength, sizeof(DNALength));
    tupleList.resize(tupleListLength);
    in.read((char *)&tupleList[0], sizeof(PositionDNATuple) * tupleListLength);
}

#endif