Skip to content

Commit

Permalink
Merge pull request #489 from Bioinformatics/rev-interop2csv
Browse files Browse the repository at this point in the history
Replace interop2csv with versioned dumptext
  • Loading branch information
ezralanglois authored and GitHub Enterprise committed Dec 21, 2016
2 parents 8837739 + b54c112 commit 1b96bbf
Show file tree
Hide file tree
Showing 24 changed files with 1,217 additions and 22 deletions.
12 changes: 12 additions & 0 deletions docs/src/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

Date | Description
---------- | -----------
2016-12-21 | Replace interop2csv with dumptext
2016-12-20 | IPA-5923: Fix bug in legacy q-metric binning
2016-12-19 | Removes the coverity run from the build matrix for every pull request
2016-12-16 | IPA-5885: Ensure error summary matches requirements
2016-12-14 | Enhance C# version information
2016-12-14 | Clean up unused enum types
2016-12-12 | IPA-5153: Ensure Summary tab calculations are consistent with Docs
2016-12-09 | IPA-5883: Fix possible memory issue in MSVC12
2016-12-08 | IPA-4674: Add support for absolute naming convention
2016-12-07 | IPA-5869: Add section filtering
2016-12-06 | IPA-5734: Synchronize master
2016-12-02 | Add Google Analytics tracking to documentation
2016-12-08 | Added admonition to avoid using MSVC 12 (2013) with C# bindings
2016-12-08 | Added support for absolute tile naming
2016-12-08 | Added ability to do section filtering
Expand Down
72 changes: 72 additions & 0 deletions interop/io/format/abstract_text_format.h
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;
};
}}}

7 changes: 7 additions & 0 deletions interop/io/format/generic_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ namespace illumina { namespace interop { namespace io
template<class MetricType, int Version>
struct generic_layout;

/** Define a text layout of the metric
*
* This is currently only used for writing metrics
*/
template<class MetricType, int Version>
struct text_layout;


}}}

Expand Down
14 changes: 1 addition & 13 deletions interop/io/format/metric_format_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <vector>
#include "interop/util/map.h"
#include "interop/util/assert.h"
#include "interop/util/self_registration.h"
#include "interop/io/format/abstract_metric_format.h"
#include "interop/util/unique_ptr.h"
#include "interop/io/stream_exceptions.h"
Expand All @@ -33,19 +34,6 @@
illumina::interop::io::metric_format_factory< Proxy > \
illumina_interop_io_##Type##Proxy##Version(new illumina::interop::io::metric_format<Proxy, illumina::interop::io::generic_layout<Metric, Version> >);

/** Ensure that static libraries are properly linked
* This must be used in a function that will definitely be linked.
*
* Tested for Microsoft Visual C++, GCC and CLang
*/
#define INTEROP_FORCE_LINK_USE(X) void force_link_metric_format(X*); force_link_metric_format(0);
/** Ensure that static libraries are properly linked
* This must be used in a file that may not be linked.
*
* Tested for Microsoft Visual C++, GCC and CLang
*/
#define INTEROP_FORCE_LINK_DEF(X) namespace illumina{namespace interop{namespace io{ void force_link_metric_format(X*){} }}} \
void force_link_metric_format(X*){} // For Microsoft Visual C++

namespace illumina { namespace interop { namespace io
{
Expand Down
92 changes: 92 additions & 0 deletions interop/io/format/text_format.h
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);
}
};
}}}


125 changes: 125 additions & 0 deletions interop/io/format/text_format_factory.h
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);
}
};

}}}



Loading

0 comments on commit 1b96bbf

Please sign in to comment.