/usr/include/pbseq/hdf/HDFWriterBase.hpp is in libpbihdf-dev 0~20161219-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | // Author: Yuan Li
#ifndef _BLASR_HDFWRITERBASE_HPP_
#define _BLASR_HDFWRITERBASE_HPP_
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include "../pbdata/SMRTSequence.hpp"
#include "../pbdata/reads/RegionAnnotation.hpp"
#include "HDFFile.hpp"
#include "HDFGroup.hpp"
#include "HDFAtom.hpp"
#include "BufferedHDFArray.hpp"
#include "BufferedHDF2DArray.hpp"
#include "HDFScanDataWriter.hpp"
class HDFWriterBase {
public:
HDFWriterBase(const std::string & filename)
: filename_(filename)
{}
virtual ~HDFWriterBase(void) = 0;
public:
/// \returns Target H5 filename.
std::string Filename(void) {return filename_;}
std::vector<std::string> Errors(void) const;
/// Copy the given group and write to the output
/// \returns Object that was copied
void CopyObject(HDFFile& src, const char* path);
void WriteScanData(const ScanData& scanData);
virtual bool WriteFakeDataSets();
virtual void Flush();
virtual bool WriteOneZmw(const SMRTSequence& seq,
const std::vector<RegionAnnotation>& regions);
protected:
std::string filename_;
std::vector<std::string> errors_;
bool AddChildGroup(HDFGroup & parentGroup,
HDFGroup & childGroup,
const std::string & childGroupName);
bool AddAttribute(HDFData & group,
const std::string & attributeName,
const std::vector<std::string> & attributeValues);
bool AddAttribute(HDFGroup & group,
const std::string & attributeName,
const std::vector<std::string> & attributeValues);
template<typename T>
bool AddAttribute(HDFData & group,
const std::string & attributeName,
const T & attributeValue);
template<typename T>
bool AddAttribute(HDFGroup & group,
const std::string & attributeName,
const T & attributeValue);
/// \brief Checks whether chemistry triple, including
/// binding kit, sequencing kit and base caller version
/// are set.
/// If not, add error messages.
void SanityCheckChemistry(const std::string & bindingKit,
const std::string & sequencingKit);
void AddErrorMessage(const std::string & errmsg);
void FAILED_TO_CREATE_GROUP_ERROR(const std::string & groupName);
void FAILED_TO_CREATE_ATTRIBUTE_ERROR(const std::string & attributeName);
void PARENT_GROUP_NOT_INITIALIZED_ERROR(const std::string & groupName);
virtual void Close(void) = 0;
HDFFile outfile_; ///< HDFFile file handler
};
template<typename T>
bool HDFWriterBase::AddAttribute(HDFData & group,
const std::string & attributeName,
const T & attributeValue) {
try {
HDFAtom<T> attributeAtom;
attributeAtom.Create(group.dataset, std::string(attributeName));
attributeAtom.Write(attributeValue);
attributeAtom.Close();
}
catch (H5::Exception &e) {
this->FAILED_TO_CREATE_ATTRIBUTE_ERROR(attributeName);
return false;
}
return true;
}
template<typename T>
bool HDFWriterBase::AddAttribute(HDFGroup & group,
const std::string & attributeName,
const T & attributeValue) {
try {
HDFAtom<T> attributeAtom;
attributeAtom.Create(group.group, std::string(attributeName));
attributeAtom.Write(attributeValue);
attributeAtom.Close();
}
catch (H5::Exception &e) {
FAILED_TO_CREATE_ATTRIBUTE_ERROR(attributeName);
return false;
}
return true;
}
/// \brief Write a dataset of name 'dsName' under h5 group 'dsGroup' with
/// length 'dsLength'. Just fill this dataset with buffer repeatedly.
template<typename T>
bool __WriteFakeDataSet(HDFGroup & dsGroup, const std::string & dsName,
const uint32_t dsLength, std::vector<T> & buffer) {
BufferedHDFArray<T> dsArray_;
if (dsArray_.Initialize(dsGroup, dsName) == 0) return false;
uint32_t totalLength = 0;
while(totalLength < dsLength) {
uint32_t thisLength = buffer.size();
if (totalLength + thisLength <= dsLength) {
totalLength = totalLength + thisLength;
} else {
thisLength = dsLength - totalLength;
totalLength = dsLength;
}
dsArray_.Write(&buffer[0], thisLength);
dsArray_.Flush();
}
dsArray_.Close();
return true;
}
/// \brief Write a 2D dataset of name 'dSName' under h5 group 'dsGroup' with
/// row number 'rowNum', column number 'colNum'. Just fill this dataset
/// with value 'fillData'
template<typename T>
bool __WriteFake2DDataSet(HDFGroup & dsGroup, const std::string & dsName,
const uint32_t rowNum, const size_t colNum, const T & fillData) {
BufferedHDF2DArray<T> dsArray;
if (dsArray.Initialize(dsGroup, dsName, colNum) == 0) return false;
T * data = new T[colNum];
for(size_t i = 0; i < colNum; i++) {data[i] = fillData; }
for(uint32_t i = 0; i< rowNum; i++) {
dsArray.WriteRow(data, colNum);
}
dsArray.Close();
delete []data;
return true;
}
#endif
|