-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #489 from Bioinformatics/rev-interop2csv
Replace interop2csv with versioned dumptext
- Loading branch information
Showing
24 changed files
with
1,217 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** Metric format interface for the text format factory | ||
* | ||
* @file | ||
* @date 12/19/16 | ||
* @version 1.0 | ||
* @copyright GNU Public License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <iosfwd> | ||
#include "interop/util/cstdint.h" | ||
|
||
namespace illumina { namespace interop { namespace io | ||
{ | ||
/** Abstract class that provides an interface for the text format of a metric | ||
* | ||
* The template argument for this class corresponds to a specific type | ||
* of metric set. | ||
*/ | ||
template<class Metric> | ||
struct abstract_text_format | ||
{ | ||
/** Define the metric type */ | ||
typedef Metric metric_t; | ||
/** Define the metric header type */ | ||
typedef typename Metric::header_type header_t; | ||
/** ID type */ | ||
typedef typename metric_t::id_t id_t; | ||
|
||
/** Destructor | ||
*/ | ||
virtual ~abstract_text_format() {} | ||
/** Write the header for a set of metric records to the given output stream | ||
* | ||
* @param out output stream to write the binary InterOp file data | ||
* @param header header of a metric set | ||
* @param channel_names list of channel names | ||
* @param sep column seperator | ||
* @param eol row separator | ||
* @return number of column headers | ||
*/ | ||
virtual size_t write_header(std::ostream &out, | ||
const header_t &header, | ||
const std::vector<std::string>& channel_names, | ||
const char sep, | ||
const char eol) = 0; | ||
/** Write a metric record to the given output stream | ||
* | ||
* @param out output stream to write the binary InterOp file data | ||
* @param metric interop metric data to write | ||
* @param header interop metric header data to write | ||
* @param sep column seperator | ||
* @param eol row separator | ||
* @param missing missing value indicator | ||
* @return number of columns written | ||
*/ | ||
virtual size_t write_metric(std::ostream &out, | ||
const metric_t &metric, | ||
const header_t &header, | ||
const char sep, | ||
const char eol, | ||
const char missing) = 0; | ||
|
||
/** Get the version of this metric format | ||
* | ||
* @return version number | ||
*/ | ||
virtual ::int16_t version() const=0; | ||
}; | ||
}}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** Concrete text layout formats for the abstract text format interface. | ||
* | ||
* | ||
* @file | ||
* @date 12/19/16 | ||
* @version 1.0 | ||
* @copyright GNU Public License. | ||
*/ | ||
#pragma once | ||
#ifdef _MSC_VER | ||
#pragma warning(disable:4702) // MSVC warns that there is unreachable code | ||
#endif | ||
|
||
|
||
#include "interop/util/exception.h" | ||
#include "interop/io/format/abstract_text_format.h" | ||
#include "interop/io/format/generic_layout.h" | ||
|
||
namespace illumina { namespace interop { namespace io | ||
{ | ||
/** Shared functionality for writing text InterOp metrics | ||
*/ | ||
template<class Metric, class Layout> | ||
struct text_format; | ||
/** Shared functionality for writing text InterOp metrics | ||
* | ||
* Specialization for text_layout | ||
*/ | ||
template<class Metric, int Version> | ||
struct text_format<Metric, text_layout<Metric, Version> > : public abstract_text_format<Metric> | ||
{ | ||
private: | ||
typedef text_layout<Metric, Version> layout_t; | ||
typedef typename Metric::id_t id_t; | ||
public: | ||
/** Define the metric type */ | ||
typedef Metric metric_t; | ||
/** Define the metric header type */ | ||
typedef typename Metric::header_type header_t; | ||
|
||
/** Write the header of text format to the given output stream | ||
* | ||
* @param out output stream to write the binary InterOp file data | ||
* @param header header of a metric set | ||
* @param channel_names list of channel names | ||
* @param sep column seperator | ||
* @param eol row separator | ||
* @return number of column headers | ||
*/ | ||
size_t write_header(std::ostream &out, | ||
const header_t &header, | ||
const std::vector<std::string>& channel_names, | ||
const char sep, | ||
const char eol) | ||
{ | ||
out << "# " << Metric::prefix() << Metric::suffix() << sep; | ||
out << Version << eol; | ||
return layout_t::write_header(out, header, channel_names, sep, eol); | ||
} | ||
|
||
/** Write a text record to the given output stream | ||
* | ||
* @param out output stream | ||
* @param metric a metric to write | ||
* @param header metric set header | ||
* @param sep column seperator | ||
* @param eol row separator | ||
* @param missing missing value indicator | ||
* @return number of columns written | ||
*/ | ||
size_t write_metric(std::ostream &out, | ||
const metric_t &metric, | ||
const header_t &header, | ||
const char sep, | ||
const char eol, | ||
const char missing) | ||
{ | ||
return layout_t::write_metric(out, metric, header, sep, eol, missing); | ||
} | ||
|
||
/** Get the version of this metric format | ||
* | ||
* @return version number | ||
*/ | ||
::int16_t version() const | ||
{ | ||
return static_cast< ::int16_t >(Version); | ||
} | ||
}; | ||
}}} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/** Factory for generating text formats | ||
* | ||
* @file | ||
* @date 12/19/16 | ||
* @version 1.0 | ||
* @copyright GNU Public License. | ||
*/ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include "interop/util/map.h" | ||
#include "interop/util/assert.h" | ||
#include "interop/util/self_registration.h" | ||
#include "interop/io/format/abstract_text_format.h" | ||
#include "interop/util/unique_ptr.h" | ||
#include "interop/io/stream_exceptions.h" | ||
|
||
/** Register a text format with the factory | ||
* | ||
* @param Metric metric class | ||
* @param Version version number | ||
*/ | ||
#define INTEROP_REGISTER_METRIC_TEXT_LAYOUT(Metric, Version) \ | ||
illumina::interop::io::text_format_factory_proxy< Metric > \ | ||
illumina_interop_io_text_##Type##Metric##Version(new illumina::interop::io::text_format<Metric, illumina::interop::io::text_layout<Metric, Version> >); | ||
|
||
|
||
namespace illumina { namespace interop { namespace io | ||
{ | ||
/** Factory for generating text formats | ||
* | ||
* This class defines static methods to register a metric format. The registered metric formats can | ||
* be accessed through the `instance()` static function. | ||
* | ||
* @note this is not thread safe | ||
*/ | ||
template<class Metric> | ||
struct text_format_factory | ||
{ | ||
/** Define the metric type */ | ||
typedef Metric metric_type; | ||
/** Define the abstract format type */ | ||
typedef abstract_text_format<metric_type> abstract_text_format_t; | ||
/** Define the header type */ | ||
typedef typename Metric::header_type header_type; | ||
/** Define a unique pointer to a metric format */ | ||
typedef stdbp::unique_ptr<abstract_text_format_t> metric_format_pointer; | ||
/** Define a map between format version and the format */ | ||
typedef INTEROP_UNORDERED_MAP(int, metric_format_pointer) text_format_map; | ||
|
||
/** Find a format for a given version | ||
* | ||
* If the format is not found, return null | ||
* | ||
* @param version version to search for | ||
* @return pointer to format or null | ||
*/ | ||
abstract_text_format_t* find(int version) | ||
{ | ||
if(version < 0) version = m_latest_version; | ||
typename text_format_map::iterator it = m_format_map.find(version); | ||
if(it == m_format_map.end()) return 0; | ||
return &(*it->second); | ||
} | ||
|
||
/** Add a text format to the factory | ||
* | ||
* @param pformat format to add | ||
*/ | ||
void add(abstract_text_format_t *pformat) | ||
{ | ||
const int version = pformat->version(); | ||
if(version > m_latest_version) m_latest_version = version; | ||
m_format_map[version] = metric_format_pointer(pformat); | ||
} | ||
/** Get number of text formats | ||
* | ||
* @return number of text formats | ||
*/ | ||
size_t size()const | ||
{ | ||
return m_format_map.size(); | ||
} | ||
|
||
/** Instance of the factory singleton | ||
* | ||
* @note this is not thread safe | ||
* @return instance to singleton | ||
*/ | ||
static text_format_factory<Metric> &instance() | ||
{ | ||
INTEROP_FORCE_LINK_USE(metric_type); | ||
static text_format_factory<Metric> _inst; | ||
return _inst; | ||
} | ||
|
||
private: | ||
text_format_factory() : m_latest_version(-1) {} | ||
text_format_map m_format_map; | ||
int m_latest_version; | ||
|
||
}; | ||
/** Proxy for registering text formats | ||
*/ | ||
template<class Metric> | ||
struct text_format_factory_proxy | ||
{ | ||
/** Define the metric type */ | ||
typedef Metric metric_type; | ||
/** Define the abstract format type */ | ||
typedef abstract_text_format<metric_type> abstract_text_format_t; | ||
/** Constructor | ||
* | ||
* This constructor is used to statically register a text format in a source file. | ||
*/ | ||
text_format_factory_proxy(abstract_text_format_t *pformat) | ||
{ | ||
text_format_factory<Metric>::instance().add(pformat); | ||
} | ||
}; | ||
|
||
}}} | ||
|
||
|
||
|
Oops, something went wrong.