File: HDFRegionTableWriter.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 (143 lines) | stat: -rw-r--r-- 4,108 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef _BLASR_HDF_REGION_TABLE_WRITER_HPP_
#define _BLASR_HDF_REGION_TABLE_WRITER_HPP_

#include <string>

#include <pbdata/Enumerations.h>
#include <hdf/HDF2DArray.hpp>
#include <hdf/HDFArray.hpp>
#include <hdf/HDFAtom.hpp>
#include <hdf/HDFFile.hpp>
#include <pbdata/reads/RegionTable.hpp>

using namespace H5;

class HDFRegionTableWriter
{
public:
    HDFFile regionTableFile;

    HDF2DArray<int> regions;
    HDFAtom<std::vector<std::string> > regionTypes;
    HDFAtom<std::vector<std::string> > regionDescriptions;
    HDFAtom<std::vector<std::string> > regionSources;
    HDFAtom<std::vector<std::string> > columnNames;
    int curRow;
    int nRows;
    HDFGroup *parentGroupPtr, pulseDataGroup;

    void CreateGroupStructure()
    {

        regionTableFile.rootGroup.AddGroup("PulseData");
        if (pulseDataGroup.Initialize(regionTableFile.rootGroup, "PulseData") == 0) {
            std::cout << "Could not create group PulseData. This is a bug." << std::endl;
            std::exit(EXIT_FAILURE);
        }
        parentGroupPtr = &pulseDataGroup;
        regions.Initialize(pulseDataGroup, "Regions", RegionAnnotation::NCOLS);
    }

    int Create(std::string fileName)
    {
        H5File newFile(fileName.c_str(), H5F_ACC_TRUNC, FileCreatPropList::DEFAULT,
                       FileAccPropList::DEFAULT);
        regionTableFile.hdfFile.openFile(fileName.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
        regionTableFile.rootGroup.Initialize(regionTableFile.hdfFile, "/");
        CreateGroupStructure();
    }

    HDFRegionTableWriter()
    {
        curRow = 0;
        nRows = 0;
        parentGroupPtr = NULL;
    }

    int Initialize(HDFGroup &parentGroupP)
    {
        /*
         * Initialize in an existing file.
         */
        parentGroupPtr = &parentGroupP;
        return Initialize();
    }

    int Initialize(std::string &regionTableFileName,
                   const H5::FileAccPropList &fileAccPropList = H5::FileAccPropList::DEFAULT)
    {
        /*
         * Initialize access to the HDF file.
         */
        try {
            regionTableFile.Open(regionTableFileName, H5F_ACC_TRUNC, fileAccPropList);
        } catch (Exception &e) {
            std::cout << e.getDetailMsg() << std::endl;
            return 0;
        }
        CreateGroupStructure();
        return 1;
    }

    int Initialize()
    {

        if (regions.Initialize(*parentGroupPtr, "Regions", RegionAnnotation::NCOLS) == 0) {
            return 0;
        }
        nRows = regions.GetNRows();

        curRow = 0;
        return 1;
    }

    void Finalize(std::vector<std::string> &columnNamesVect,
                  std::vector<std::string> &regionTypesVect,
                  std::vector<std::string> &regionDescriptionsVect,
                  std::vector<std::string> &regionSourcesVect)
    {
        //
        // Make sure data has been written to the dataset.  If not, the
        // dataset will not exist and creating the attributes will fail.
        //
        if (curRow > 0) {
            regionTypes.Create(regions.dataset, "RegionTypes", regionTypesVect);
            columnNames.Create(regions.dataset, "ColumnNames", columnNamesVect);
            regionDescriptions.Create(regions.dataset, "RegionDescriptions",
                                      regionDescriptionsVect);
            regionSources.Create(regions.dataset, "RegionSources", regionSourcesVect);
        }
    }

    void WriteRows(std::vector<RegionAnnotation> &annotations)
    {
        int i;
        for (i = 0; i < annotations.size(); i++) {
            Write(annotations[i]);
        }
    }

    int Write(RegionAnnotation &annotation, int at = -1)
    {
        if (at == -1) {
            regions.WriteRow(annotation.row, annotation.NCOLS);
            ++curRow;
        } else {
        }
        return 1;
    }

    void Close()
    {
        regions.Close();
        //
        // Check to see if this is external
        //
        if (parentGroupPtr == &pulseDataGroup) {
            pulseDataGroup.Close();
        }
        regionTableFile.rootGroup.Close();
    }
};

#endif