Skip to content

Commit

Permalink
Added --unmapped-val <val> option to bedmap; fixed named-pipe bug whe…
Browse files Browse the repository at this point in the history
…n one file is passed to bedmap.
  • Loading branch information
sjneph committed Jun 21, 2018
1 parent bdbbf9f commit 03c00bf
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 49 deletions.
87 changes: 48 additions & 39 deletions applications/bed/bedmap/src/Bedmap.cpp

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion applications/bed/bedmap/src/Input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace BedMap {
precision_(6), useScientific_(false), useMinMemory_(false), setPrec_(false), numFiles_(0),
minRefFields_(0), minMapFields_(0), errorCheck_(false), sweepAll_(false),
outDelim_("|"), multiDelim_(";"), fastMode_(false), rangeAlias_(false),
chrom_("all"), skipUnmappedRows_(false) {
chrom_("all"), skipUnmappedRows_(false), unmappedVal_("") {

// Process user's operation options
if ( argc <= 1 )
Expand Down Expand Up @@ -108,6 +108,12 @@ namespace BedMap {
fastMode_ = true;
} else if ( next == "sweep-all" ) { // --> sweep through all of second file
sweepAll_ = true;
} else if ( next == "unmapped-val" ) {
Ext::Assert<ArgError>(unmappedVal_.empty(), "--unmapped-val specified multiple times");
Ext::Assert<ArgError>(argcntr < argc, "No value given for --unmapped-val");
unmappedVal_ = argv[argcntr++];
Ext::Assert<ArgError>(unmappedVal_.find("--") != 0,
"Apparent option: " + std::string(argv[argcntr]) + " where <val> expected for --unmapped-val.");
} else if ( next == "delim" ) {
Ext::Assert<ArgError>(outDelim_ == "|", "--delim specified multiple times");
Ext::Assert<ArgError>(argcntr < argc, "No output delimiter given");
Expand Down Expand Up @@ -399,6 +405,7 @@ namespace BedMap {
bool rangeAlias_;
std::string chrom_;
bool skipUnmappedRows_;
std::string unmappedVal_;

private:
struct MapFields {
Expand Down Expand Up @@ -480,6 +487,7 @@ namespace BedMap {
usage << " --sci Use scientific notation for score outputs. \n";
usage << " --skip-unmapped Print no output for a row with no mapped elements. \n";
usage << " --sweep-all Ensure <map-file> is read completely (helps to prevent broken pipes). \n";
usage << " --unmapped-val <val> Use <val> in place of the empty string on unmapped --echo-map* ops. \n";
usage << " --version Print program information. \n";
usage << " \n";
usage << " \n";
Expand Down
1 change: 1 addition & 0 deletions docs/content/reference/statistics/bedmap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ The ``--help`` option describes the various mapping and analytical operations an
--sci Use scientific notation for score outputs.
--skip-unmapped Print no output for a row with no mapped elements.
--sweep-all Ensure <map-file> is read completely (helps to prevent broken pipes).
--unmapped-val <val> Use <val> in place of the empty string on unmapped --echo-map* ops.
--version Print program information.

Overlap Options (At most, one may be selected. By default, --bp-ovr 1 is used):
Expand Down
2 changes: 2 additions & 0 deletions docs/content/revision-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Released: **TBD**

* To avoid mapping problems, map elements should not contain spaces in the ID or subsequent non-interval fields. Use of the :code:`--ec` can help identify problems in map input, at the cost of a longer runtime. The documentation is clarified to warn users about avoiding spaces in map input. Thanks to Wouter Meuleman for the report and providing test input.

* Added --unmapped-val <val> option, where <val> replaces the empty string output of --echo-map* operations when there are no mapped elements. --min/max-element operators will give results as before (the empty string).

=================
Previous versions
=================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,18 @@ namespace Visitors {
struct PrintUniqueRangeIDs : private Visitors::Helpers::PrintDelim {
typedef Visitors::Helpers::PrintDelim Base;

explicit PrintUniqueRangeIDs(const std::string& delim = ";")
: Base(delim)
explicit PrintUniqueRangeIDs(const std::string& delim = ";", const std::string& onEmpty = "")
: Base(delim), oe_(onEmpty)
{ /* */ }

template <typename Iter>
void operator()(Iter beg, Iter end) const {
typedef std::set<std::string> SortType;
if ( beg == end )
if ( beg == end ) {
if ( !oe_.empty() )
PrintTypes::Print(oe_.c_str());
return;
}
SortType srt;
while ( beg != end ) {
srt.insert((*beg)->id());
Expand All @@ -400,6 +403,9 @@ namespace Visitors {
PrintTypes::Print(i->c_str());
} // while
}

private:
std::string oe_;
};

//=========================
Expand Down Expand Up @@ -448,18 +454,22 @@ namespace Visitors {
//=====================
template <typename PrintType>
struct PrintGenomicRange {
typedef PrintType PType;
explicit PrintGenomicRange(const PrintType& p = PrintType())
: pt_(p)
explicit PrintGenomicRange(const PrintType& p = PrintType(), const std::string& onEmpty = "")
: pt_(p), oe_(onEmpty)
{ /* */ }
template <typename Iter>
void operator()(Iter beg, Iter end) const {
// It is often possible/likely that beg->end is not in an order
// of the original input file (sorted by sort-bed), due to
// issues of BED types (see BedBaseVisitor.hpp).
if ( beg == end )
if ( beg == end ) {
if ( !oe_.empty() )
PrintTypes::Print(oe_.c_str());
return;
}
typename std::remove_const<typename std::remove_pointer<typename Iter::value_type>::type>::type val = **beg;
while ( ++beg != end ) {
Expand All @@ -474,6 +484,7 @@ namespace Visitors {
private:
PrintType pt_;
std::string oe_;
};
} // namespace BedHelpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,18 @@ namespace Visitors {
typedef PrintType PType;

explicit PrintRangeDelim(const PrintType& p = PrintType(),
const std::string& delim = ";")
: Base(delim), pt_(p)
const std::string& delim = ";",
const std::string& onEmpty = "")
: Base(delim), pt_(p), oe_(onEmpty)
{ /* */ }
template <typename Iter>
void operator()(Iter beg, Iter end) const {
if ( beg == end )
if ( beg == end ) {
if ( !oe_.empty() )
PrintTypes::Print(oe_.c_str());
return;
}
pt_.operator()(*beg);
while ( ++beg != end ) {
Base::operator()();
Expand All @@ -167,6 +171,7 @@ namespace Visitors {
private:
PrintType pt_;
std::string oe_;
};
} // namespace Helpers
Expand Down

0 comments on commit 03c00bf

Please sign in to comment.