File: HDFZMWReader_gtest.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 (126 lines) | stat: -rw-r--r-- 3,567 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
119
120
121
122
123
124
125
126
/*
 * ==========================================================================
 *
 *       Filename:  HDFZMWReader_gtest.cpp
 *
 *    Description:  Test hdf/HDFZMWReader.hpp
 *
 *        Version:  1.0
 *        Created:  08/21/2013 07:00:49 PM
 *       Revision:  08/20/2014
 *       Compiler:  gcc
 *
 *         Author:  Yuan Li (yli), yli@pacificbiosciences.com
 *        Company:  Pacific Biosciences
 *
 * ==========================================================================
 */

#include <gtest/gtest.h>

#include <pbdata/testdata.h>
#include <hdf/HDFZMWReader.hpp>

using namespace H5;

class HDFZMWReaderTEST : public ::testing::Test
{
public:
    virtual void SetUp() {}
    virtual void TearDown() {}

    void Initialize(H5File &pbihdfFile, std::string fileName, std::string groupName,
                    HDFGroup &callsGroup)
    {
        try {
            FileAccPropList propList;
            pbihdfFile.openFile(fileName.c_str(), H5F_ACC_RDONLY, propList);
        } catch (Exception &e) {
            std::cout << "ERROR, could not open hdf file" << fileName << ", exiting." << std::endl;
            std::exit(EXIT_FAILURE);
        }

        ASSERT_NE(callsGroup.Initialize(pbihdfFile, groupName), 0);

        /*
        HDFGroup rootGroup, pulseDataGroup;
        if (rootGroup.Initialize(pbihdfFile, "/") == 0) {
            std::cout << "ERROR, could not open /" << std::endl;
            std::exit(EXIT_FAILURE);
        }

        if (pulseDataGroup.Initialize(rootGroup, "PulseData") == 0){
            std::cout << "ERROR, could not open /PulseData" << std::endl;
            std::exit(EXIT_FAILURE);
        }

        ASSERT_NE(callsGroup.Initialize(pulseDataGroup, "BaseCalls"), 0);
        */
    }

    void Close(H5File &pbihdfFile, HDFGroup &callsGroup)
    {
        pbihdfFile.close();
        callsGroup.Close();
    }

    void TestGetNext(HDFZMWReader &zmwReader)
    {
        UInt count = 0;
        ZMWGroupEntry entry;
        while (zmwReader.GetNext(entry)) {
            count++;
            ASSERT_EQ(zmwReader.curZMW, count);
        }
        ASSERT_EQ(count, zmwReader.nZMWEntries);
    }
};

TEST_F(HDFZMWReaderTEST, ReadZMWFromBaseCalls)
{
    HDFZMWReader zmwReader;
    std::string fileName = baxFile2;
    std::string groupName = "/PulseData/BaseCalls";
    H5File pbihdfFile;
    HDFGroup baseCallsGroup;

    Initialize(pbihdfFile, fileName, groupName, baseCallsGroup);
    ASSERT_NE(zmwReader.Initialize(&baseCallsGroup), 0);

    TestGetNext(zmwReader);
    zmwReader.Close();
    Close(pbihdfFile, baseCallsGroup);
}

TEST_F(HDFZMWReaderTEST, ReadZMWFromPulseCalls)
{
    std::string fileName = plsFile1;
    H5File pbihdfFile;
    try {
        FileAccPropList propList;
        pbihdfFile.openFile(fileName.c_str(), H5F_ACC_RDONLY, propList);
    } catch (Exception &e) {
        std::cout << "ERROR, could not open hdf file" << fileName << ", exiting." << std::endl;
        std::exit(EXIT_FAILURE);
    }

    HDFGroup pulseCallsGroup;
    ASSERT_NE(pulseCallsGroup.Initialize(pbihdfFile, "/PulseData/PulseCalls"), 0);

    HDFZMWReader zmwReader;
    ASSERT_NE(zmwReader.Initialize(&pulseCallsGroup), 0);
    TestGetNext(zmwReader);
    zmwReader.Close();

    // Switch to read from CCS ZMW.
    HDFGroup ccsGroup;
    ASSERT_NE(ccsGroup.Initialize(pbihdfFile, "/PulseData/ConsensusBaseCalls"), 0);
    ASSERT_NE(zmwReader.Initialize(&ccsGroup), 0);
    TestGetNext(zmwReader);
    zmwReader.Close();

    // Close
    ccsGroup.Close();
    pulseCallsGroup.Close();
    pbihdfFile.close();
}