Skip to content

Commit

Permalink
fixed bugs related to new BED classes
Browse files Browse the repository at this point in the history
  • Loading branch information
sjneph committed Jul 17, 2017
1 parent 82d923f commit f82564d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 52 deletions.
2 changes: 1 addition & 1 deletion applications/bed/bedmap/src/TDefs.hpp
Expand Up @@ -70,9 +70,9 @@ namespace BedMap {
typedef Visitors::Average<ProcessScorePrecision, BaseClass> Average;
typedef Visitors::CoeffVariation<ProcessScorePrecision, BaseClass> CoeffVariation;
typedef Visitors::Count<ProcessScore, BaseClass> Count;
typedef Visitors::Indicator<ProcessScore, BaseClass> Indicator;
typedef Visitors::RollingKthAverage<ProcessScorePrecision, BaseClass, Ext::ArgumentError> KthAverage;
typedef Visitors::Extreme<ProcessScorePrecision, BaseClass, MaxOrderArb> Max;
typedef Visitors::Indicator<ProcessScore, BaseClass> Indicator;
typedef Visitors::Median<ProcessScorePrecision, BaseClass> Median;
typedef Visitors::MedianAbsoluteDeviation<ProcessScorePrecision, BaseClass> MedianAbsoluteDeviation;
typedef Visitors::Extreme<ProcessScorePrecision, BaseClass, MinOrderArb> Min;
Expand Down
Expand Up @@ -205,16 +205,16 @@ namespace Visitors {
}

void operator()(const Signal::NaN& s) const {
throw(std::string("Unable to process a 'NAN' with PrintAllScorePrecision."));
PrintTypes::Print("");
}

protected:
template <typename T>
typename std::enable_if<T::UseRest, void>::type printRest(T* t) const {
// PrintTypes::Print(t->rest()); // already includes '\t' out front
// t->full_rest() now includes t->id() and t->measurement(), exclude here
if ( t->full_rest()[0] != '\0' )
PrintTypes::Print(t->full_rest());
if ( t->full_rest()[0] != '\0' && t->rest_offset() >= 0 )
PrintTypes::Print(t->full_rest() + t->rest_offset());
}

template <typename T>
Expand Down
Expand Up @@ -114,7 +114,7 @@ namespace Visitors {
if ( !m_.empty() )
pt_.operator()(onTies.breakTie(m_));
else
pt_.operator()(nan);
pt_.operator()(nan);
}


Expand Down
72 changes: 25 additions & 47 deletions interfaces/general-headers/data/bed/Bed.hpp
Expand Up @@ -254,15 +254,6 @@ namespace Bed {
: public BasicCoords<IsNonStaticChrom, false> {

BasicCoords() : BaseClass() { fullrest_[0] = '\0'; }
BasicCoords(char const* chrom, CoordType start, CoordType end, char const* rest = nullptr)
: BaseClass(chrom, start, end) {
fullrest_[0] = '\0';
if ( rest && std::strcmp(rest, "") != 0 ) {
if ( rest[0] != '\t' )
fullrest_[0] = '\t', fullrest_[1] = '\0';
std::strcat(fullrest_, rest);
}
}
BasicCoords(const BasicCoords& c)
: BaseClass(c)
{ std::strcpy(fullrest_, c.fullrest_); }
Expand Down Expand Up @@ -336,7 +327,7 @@ namespace Bed {
return(std::string("%s\t%" SCNu64 "\t%" SCNu64 "%[^\n]s\n"));
}
};


/*****************************************/
/* Bed4 Classes */
Expand Down Expand Up @@ -442,15 +433,6 @@ namespace Bed {
*fullrest_ = '\0';
std::strcpy(fullrest_, c.fullrest_);
}
Bed4(char const* chrom, CoordType start, CoordType end, char const* id, char const* rest = nullptr)
: BaseClass(chrom, start, end, id) {
*fullrest_ = '\0';
if ( id && std::strcmp(id, "") != 0 )
std::strcpy(fullrest_, id);

if ( rest && std::strcmp(rest, "") != 0 )
std::strcat(fullrest_, rest);
}
explicit Bed4(FILE* inF) : BaseClass()
{ this->readline(inF); }
explicit Bed4(const std::string& inS) : BaseClass()
Expand Down Expand Up @@ -487,9 +469,9 @@ namespace Bed {
format, chrom_,
&start_, &end_, id_,
other);
std::strcpy(fullrest_, id_);
if ( other[0] != '\0' )
std::strcat(fullrest_, other);
const int numWritten = std::snprintf(fullrest_, MAXRESTSIZE+1, "\t%s", id_);
if ( other[0] != '\0' && numWritten < MAXRESTSIZE )
std::snprintf(fullrest_ + numWritten, MAXRESTSIZE+1-numWritten, "%s", other);
return numScanned;
}
inline int readline(FILE* inputFile) {
Expand All @@ -506,9 +488,9 @@ namespace Bed {
other);

std::fgetc(inputFile); // Read and discard trailing newline
std::strcpy(fullrest_, id_);
if ( other[0] != '\0' )
std::strcat(fullrest_, other);
const int numWritten = std::snprintf(fullrest_, MAXRESTSIZE+1, "\t%s", id_);
if ( other[0] != '\0' && numWritten < MAXRESTSIZE )
std::snprintf(fullrest_ + numWritten, MAXRESTSIZE+1-numWritten, "%s", other);
return numScanned;
}

Expand Down Expand Up @@ -643,29 +625,19 @@ namespace Bed {
struct Bed5
: public Bed5<Bed4Type, MeasureType, false> { /* Bed4Type is forced to be Bed4<> specialization above */

Bed5() : BaseClass() { *chrom_ = '\0'; *id_ = '\0'; *fullrest_ = '\0'; }
Bed5(const Bed5& c) : BaseClass(c)
Bed5() : BaseClass() { *chrom_ = '\0'; *id_ = '\0'; *fullrest_ = '\0'; restOffset_ = -1; }
Bed5(const Bed5& c) : BaseClass(c), restOffset_(c.restOffset_)
{
*fullrest_ = '\0'; std::strcpy(fullrest_, c.fullrest_);
}
Bed5(char const* chrom, CoordType start, CoordType end,
char const* id, MeasureType measurement, char const* rest = nullptr)
: BaseClass(chrom, start, end, id, measurement)
{
*fullrest_ = '\0';
if ( id && std::strcmp(id, "") != 0 )
std::strcpy(fullrest_, id);

if ( rest && 0 != std::strcmp(rest, "") )
std::strcat(fullrest_, rest);
}
explicit Bed5(FILE* inF) : BaseClass()
{ *fullrest_ = '\0'; this->readline(inF); }
explicit Bed5(const std::string& inS) : BaseClass()
{ *fullrest_ = '\0'; this->readline(inS); }

// Properties
inline char const* full_rest() const { return fullrest_; }
inline int rest_offset() const { return restOffset_; }

// IO
inline void print() const {
Expand All @@ -691,15 +663,17 @@ namespace Bed {
*chrom_ = '\0';
*id_ = '\0';
*fullrest_ = '\0';
restOffset_ = -1;
int numScanned = std::sscanf(inputLine.c_str(),
format, chrom_,
&start_, &end_, id_,
&measurement_, other);

static const char* f = (std::string("\t%s\t") + BaseClass::MFormat).c_str();
int numWritten = std::snprintf(fullrest_, MAXRESTSIZE+1, f, id_, &measurement_);
if ( other[0] != '\0' )
std::strcpy(fullrest_ + numWritten + 1, other);
const int numWritten = std::snprintf(fullrest_, MAXRESTSIZE+1, (std::string("\t%s\t") + BaseClass::MFormat).c_str(), id_, measurement_);
if ( other[0] != '\0' && numWritten < MAXRESTSIZE ) {
restOffset_ = numWritten;
std::snprintf(fullrest_ + numWritten, MAXRESTSIZE+1-numWritten, "%s", other);
}
return numScanned;
}
inline int readline(FILE* inputFile) {
Expand All @@ -710,6 +684,7 @@ namespace Bed {
*chrom_ = '\0';
*id_ = '\0';
*fullrest_ = '\0';
restOffset_ = -1;
int numScanned = std::fscanf(inputFile,
format, chrom_,
&start_, &end_, id_,
Expand All @@ -718,9 +693,11 @@ namespace Bed {
std::fgetc(inputFile); // Read and discard trailing newline

static const char* f = (std::string("\t%s\t") + BaseClass::MFormat).c_str();
int numWritten = std::snprintf(fullrest_, MAXRESTSIZE+1, f, id_, &measurement_);
if ( other[0] != '\0' )
std::strcpy(fullrest_ + numWritten + 1, other);
const int numWritten = std::snprintf(fullrest_, MAXRESTSIZE+1, f, id_, measurement_);
if ( other[0] != '\0' && numWritten < MAXRESTSIZE ) {
restOffset_ = numWritten;
std::snprintf(fullrest_ + numWritten, MAXRESTSIZE+1-numWritten, "%s", other);
}
return numScanned;
}

Expand All @@ -742,10 +719,11 @@ namespace Bed {
using BaseClass::id_;
using BaseClass::measurement_;

int restOffset_; // marks spot after id_/measurement_ in fullrest_
char fullrest_[MAXRESTSIZE+1];

static std::string outFormatter() {
return(BaseClass::outFormatter() + "%s");
static std::string outFormatter() { /* BC::BC::BC --> output 3 columns and fullrest_ */
return BaseClass::BaseClass::BaseClass::outFormatter() + "%s";
}

static std::string inFormatter() {
Expand Down
1 change: 1 addition & 0 deletions interfaces/general-headers/data/bed/Bed_minmem.hpp
Expand Up @@ -785,6 +785,7 @@ namespace Bed {
// Properties
char const* rest() const { return rest_; }
char const* full_rest() const { return fullrest_; }
int rest_offset() const { return 0; /* not applicable in min-memory case */ }

// IO
inline void print() const {
Expand Down

0 comments on commit f82564d

Please sign in to comment.