File: HDFWriterBase.cpp

package info (click to toggle)
pbseqlib 5.3.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,020 kB
  • sloc: cpp: 77,246; python: 331; sh: 103; makefile: 42
file content (105 lines) | stat: -rw-r--r-- 3,339 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
// Author: Yuan Li

#include <hdf/HDFWriterBase.hpp>

HDFWriterBase::~HDFWriterBase(void) {}

std::vector<std::string> HDFWriterBase::Errors(void) const { return errors_; }

void HDFWriterBase::CopyObject(HDFFile &src, const char *path)
{
    H5Ocopy(src.hdfFile.getId(), path, outfile_.hdfFile.getId(), path, H5P_DEFAULT, H5P_DEFAULT);
}

void HDFWriterBase::WriteScanData(const ScanData &scanData)
{
    // sanity check chemistry meta data.
    SanityCheckChemistry(scanData.BindingKit(), scanData.SequencingKit());
    HDFScanDataWriter writer(outfile_.rootGroup);
    writer.Write(scanData);
}

bool HDFWriterBase::WriteFakeDataSets() { return true; }

void HDFWriterBase::Flush() {}

bool HDFWriterBase::WriteOneZmw(const SMRTSequence &, const std::vector<RegionAnnotation> &)
{
    // XXX: unused variables
    return true;
}

bool HDFWriterBase::AddChildGroup(HDFGroup &parentGroup, HDFGroup &childGroup,
                                  const std::string &childGroupName)
{
    parentGroup.AddGroup(childGroupName);
    if (childGroup.Initialize(parentGroup, childGroupName) == 0) {
        FAILED_TO_CREATE_GROUP_ERROR(childGroupName);
        return false;
    }
    return true;
}

template <>
bool HDFWriterBase::AddAttribute(HDFData &group, const std::string &attributeName,
                                 const std::vector<std::string> &attributeValues)
{
    try {
        HDFAtom<std::vector<std::string> > attributeAtom;
        attributeAtom.Create(group.dataset, std::string(attributeName), attributeValues);
        attributeAtom.Close();
    } catch (H5::Exception &e) {
        FAILED_TO_CREATE_ATTRIBUTE_ERROR(attributeName);
        return false;
    }
    return true;
}

template <>
bool HDFWriterBase::AddAttribute(HDFGroup &group, const std::string &attributeName,
                                 const std::vector<std::string> &attributeValues)
{
    try {
        HDFAtom<std::vector<std::string> > attributeAtom;
        attributeAtom.Create(group.group, std::string(attributeName), attributeValues);
        attributeAtom.Close();
    } catch (H5::Exception &e) {
        FAILED_TO_CREATE_ATTRIBUTE_ERROR(attributeName);
        return false;
    }
    return true;
}

void HDFWriterBase::SanityCheckChemistry(const std::string &bindingKit,
                                         const std::string &sequencingKit)
{
    if (bindingKit.empty()) {
        AddErrorMessage("Binding kit must be specified.");
    }
    if (sequencingKit.empty()) {
        AddErrorMessage("Sequencing kit must be specified.");
    }
}

void HDFWriterBase::AddErrorMessage(const std::string &errmsg) { errors_.push_back(errmsg); }

void HDFWriterBase::FAILED_TO_CREATE_GROUP_ERROR(const std::string &groupName)
{
    std::stringstream ss;
    ss << "Failed to create group " << groupName << " in " << filename_;
    AddErrorMessage(ss.str());
}

void HDFWriterBase::FAILED_TO_CREATE_ATTRIBUTE_ERROR(const std::string &attributeName)
{
    std::stringstream ss;
    ss << "Failed to create attribute " << attributeName << " in " << filename_;
    AddErrorMessage(ss.str());
}

void HDFWriterBase::PARENT_GROUP_NOT_INITIALIZED_ERROR(const std::string &groupName)
{
    std::stringstream ss;
    ss << "Parent hdf group of " << groupName << " in file " << filename_ << " is not initialized.";
    AddErrorMessage(ss.str());
}