Skip to content

Commit

Permalink
Add+test code for outputting domains/regions
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyelewis committed Nov 21, 2017
1 parent fb33d0e commit 443aff2
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 0 deletions.
22 changes: 22 additions & 0 deletions source/chopping/chopping_format/chopping_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ namespace cath {
/// \brief TODOCUMENT
virtual domain do_parse_domain(const std::string &) const = 0;

/// \brief Pure virtual method with which each concrete format must define how to write a region to the specified string
virtual std::string do_write_region(const region &) const = 0;

/// \brief Pure virtual method with which each concrete format must define how to write a domain to the specified string
virtual std::string do_write_domain(const domain &) const = 0;

public:
chopping_format() = default;
virtual ~chopping_format() noexcept = default;
Expand All @@ -56,6 +62,9 @@ namespace cath {

domain parse_domain(const std::string &) const;

std::string write_region(const region &) const;
std::string write_domain(const domain &) const;

std::unique_ptr<chopping_format> clone() const;
};

Expand All @@ -70,6 +79,18 @@ namespace cath {
return do_parse_domain( arg_domain_chopping_string );
}

/// \brief Write the specified region to a string
inline std::string chopping_format::write_region(const region &arg_region ///< The region to write to a string
) const {
return do_write_region( arg_region );
}

/// \brief Write the specified domain to a string
inline std::string chopping_format::write_domain(const domain &arg_domain ///< The domain to write to a string
) const {
return do_write_domain( arg_domain );
}

/// \brief Standard approach to achieving a virtual copy-ctor
inline std::unique_ptr<chopping_format> chopping_format::clone() const {
return common::check_uptr_clone_against_this( do_clone(), *this );
Expand All @@ -78,6 +99,7 @@ namespace cath {
domain parse_domain(const chopping_format &,
const std::string &,
const std::string &);

} // namespace chop
} // namespace cath

Expand Down
12 changes: 12 additions & 0 deletions source/chopping/chopping_format/domall_chopping_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,15 @@ domain domall_chopping_format::do_parse_domain(const string &arg_domain_chopping

return domain( region_vec() );
}

/// \brief Concrete definition of this chopping_format writes a region to a string
string domall_chopping_format::do_write_region(const region &/*arg_region*/ ///< The region to write to a string
) const {
BOOST_THROW_EXCEPTION(not_implemented_exception("domall_chopping_format cannot currently write regions"));
}

/// \brief Concrete definition of this chopping_format writes a domain to a string
string domall_chopping_format::do_write_domain(const domain &/*arg_domain*/ ///< The domain to write to a string
) const {
BOOST_THROW_EXCEPTION(not_implemented_exception("domall_chopping_format cannot currently write domains"));
}
5 changes: 5 additions & 0 deletions source/chopping/chopping_format/domall_chopping_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ namespace cath {
bool do_represents_fragments() const final;

domain do_parse_domain(const std::string &) const final;

std::string do_write_region(const region &) const final;

std::string do_write_domain(const domain &) const final;

};

} // namespace chop
Expand Down
12 changes: 12 additions & 0 deletions source/chopping/chopping_format/jmol_selection_chopping_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ domain jmol_selection_chopping_format::do_parse_domain(const string &arg_domain_

return domain( region_vec() );
}

/// \brief Concrete definition of this chopping_format writes a region to a string
string jmol_selection_chopping_format::do_write_region(const region &/*arg_region*/ ///< The region to write to a string
) const {
BOOST_THROW_EXCEPTION(not_implemented_exception("jmol_selection_chopping_format cannot currently write regions"));
}

/// \brief Concrete definition of this chopping_format writes a domain to a string
string jmol_selection_chopping_format::do_write_domain(const domain &/*arg_domain*/ ///< The domain to write to a string
) const {
BOOST_THROW_EXCEPTION(not_implemented_exception("jmol_selection_chopping_format cannot currently write domains"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ namespace cath {
bool do_represents_fragments() const final;

domain do_parse_domain(const std::string &) const final;

std::string do_write_region(const region &) const final;

std::string do_write_domain(const domain &) const final;

};

} // namespace chop
Expand Down
12 changes: 12 additions & 0 deletions source/chopping/chopping_format/scop_chopping_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ domain scop_chopping_format::do_parse_domain(const string &arg_domain_chopping_s

return domain( region_vec() );
}

/// \brief Concrete definition of this chopping_format writes a region to a string
string scop_chopping_format::do_write_region(const region &/*arg_region*/ ///< The region to write to a string
) const {
BOOST_THROW_EXCEPTION(not_implemented_exception("scop_chopping_format cannot currently write regions"));
}

/// \brief Concrete definition of this chopping_format writes a domain to a string
string scop_chopping_format::do_write_domain(const domain &/*arg_domain*/ ///< The domain to write to a string
) const {
BOOST_THROW_EXCEPTION(not_implemented_exception("scop_chopping_format cannot currently write domains"));
}
5 changes: 5 additions & 0 deletions source/chopping/chopping_format/scop_chopping_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ namespace cath {
bool do_represents_fragments() const final;

domain do_parse_domain(const std::string &) const final;

std::string do_write_region(const region &) const final;

std::string do_write_domain(const domain &) const final;

};

} // namespace chop
Expand Down
45 changes: 45 additions & 0 deletions source/chopping/chopping_format/sillitoe_chopping_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

#include "sillitoe_chopping_format.hpp"

#include <boost/range/adaptor/transformed.hpp>
#include <boost/algorithm/string/join.hpp>

#include "chopping/domain/domain.hpp"
#include "common/boost_addenda/make_string_ref.hpp"
#include "common/clone/make_uptr_clone.hpp"
Expand All @@ -32,7 +35,10 @@
using namespace cath;
using namespace cath::chop;
using namespace cath::common;
using namespace std::literals::string_literals;

using boost::adaptors::transformed;
using boost::algorithm::join;
using boost::string_ref;
using std::find;
using std::isdigit;
Expand Down Expand Up @@ -123,6 +129,45 @@ domain sillitoe_chopping_format::do_parse_domain(const string &arg_domain_choppi
: domain{ segments, name_str_ref.to_string() };
}

/// \brief Concrete definition of this chopping_format writes a region to a string
string sillitoe_chopping_format::do_write_region(const region &arg_region ///< The region to write to a string
) const {
const chain_label_opt &opt_chain_label = arg_region.get_opt_chain_label();

return
(
arg_region.has_starts_stops()
? (
to_string( get_residue_name( arg_region.get_start_residue() ) )
+ "-"
+ to_string( get_residue_name( arg_region.get_stop_residue() ) )
)
: ""s
)
+ (
opt_chain_label
? ( ":" + opt_chain_label->to_string() )
: ""s
);
}

/// \brief Concrete definition of this chopping_format writes a domain to a string
string sillitoe_chopping_format::do_write_domain(const domain &arg_domain ///< The domain to write to a string
) const {
return
"D"
+ (
arg_domain.get_opt_domain_id()
? ( "[" + *arg_domain.get_opt_domain_id() + "]" )
: ""s
)
+ join(
arg_domain
| transformed( [&] (const region &x) { return write_region( x ); } ),
","
);
}

/// \brief Parse a segment from the specified segment string
///
/// Example valid inputs: "7-232:K", "1B-99C:S"
Expand Down
4 changes: 4 additions & 0 deletions source/chopping/chopping_format/sillitoe_chopping_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ namespace cath {

domain do_parse_domain(const std::string &) const final;

std::string do_write_region(const region &) const final;

std::string do_write_domain(const domain &) const final;

public:
region parse_segment(const boost::string_ref &) const;

Expand Down
28 changes: 28 additions & 0 deletions source/chopping/chopping_format/sillitoe_chopping_format_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ using namespace cath;
using namespace cath::chop;
using namespace cath::common;

using std::string;
using boost::string_ref;

BOOST_AUTO_TEST_SUITE(sillitoe_chopping_format_test_suite)

BOOST_AUTO_TEST_CASE(throws_on_attempt_to_parse_invalid_segment) {
Expand Down Expand Up @@ -90,4 +93,29 @@ BOOST_AUTO_TEST_CASE(parses_whole_chain_region) {

/// \todo Include functionality to specify an "all" domain

template <typename Fmt>
string parse_and_write_segment(const string_ref &arg_orig_str) {
const Fmt format{};
return format.write_region( format.parse_segment( arg_orig_str ) );
}

template <typename Fmt>
string parse_and_write_domain(const string &arg_orig_str) {
const Fmt format{};
return format.write_domain( format.parse_domain( arg_orig_str ) );
}

BOOST_AUTO_TEST_CASE(parsed_and_writes_back_to_orig) {
BOOST_TEST( parse_and_write_segment<sillitoe_chopping_format>( ":R" ) == ":R" );
BOOST_TEST( parse_and_write_segment<sillitoe_chopping_format>( "7-232:K" ) == "7-232:K" );
BOOST_TEST( parse_and_write_segment<sillitoe_chopping_format>( "1B-99C:S" ) == "1B-99C:S" );

BOOST_TEST( parse_and_write_domain <sillitoe_chopping_format>( "D1-191:C" ) == "D1-191:C" );
BOOST_TEST( parse_and_write_domain <sillitoe_chopping_format>( "D192-247:C,103S-104S:C,248-318:C" ) == "D192-247:C,103S-104S:C,248-318:C" );
BOOST_TEST( parse_and_write_domain <sillitoe_chopping_format>( "D1-191:C" ) == "D1-191:C" );
BOOST_TEST( parse_and_write_domain <sillitoe_chopping_format>( "D192-247:C,103S-104S:C,248-318:C" ) == "D192-247:C,103S-104S:C,248-318:C" );
BOOST_TEST( parse_and_write_domain <sillitoe_chopping_format>( "D[1o7iB]:B" ) == "D[1o7iB]:B" );
BOOST_TEST( parse_and_write_domain <sillitoe_chopping_format>( "D[1qdmC02]192-247:C,103S-104S:C,248-318:C" ) == "D[1qdmC02]192-247:C,103S-104S:C,248-318:C" );
}

BOOST_AUTO_TEST_SUITE_END()
12 changes: 12 additions & 0 deletions source/chopping/chopping_format/simple_chopping_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ domain simple_chopping_format::do_parse_domain(const string &arg_domain_chopping
return domain( region_vec() );
}

/// \brief Concrete definition of this chopping_format writes a region to a string
string simple_chopping_format::do_write_region(const region &/*arg_region*/ ///< The region to write to a string
) const {
BOOST_THROW_EXCEPTION(not_implemented_exception("simple_chopping_format cannot currently write regions"));
}

/// \brief Concrete definition of this chopping_format writes a domain to a string
string simple_chopping_format::do_write_domain(const domain &/*arg_domain*/ ///< The domain to write to a string
) const {
BOOST_THROW_EXCEPTION(not_implemented_exception("simple_chopping_format cannot currently write domains"));
}

/// \brief Parse a segment from the specified segment string
region simple_chopping_format::parse_segment(const string_ref &arg_segment_string ///< The string from which to parse the segment
) const {
Expand Down
4 changes: 4 additions & 0 deletions source/chopping/chopping_format/simple_chopping_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ namespace cath {

domain do_parse_domain(const std::string &) const final;

std::string do_write_region(const region &) const final;

std::string do_write_domain(const domain &) const final;

public:
region parse_segment(const boost::string_ref &) const;

Expand Down
24 changes: 24 additions & 0 deletions source/chopping/region/region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <boost/algorithm/string/join.hpp>
#include <boost/program_options.hpp>
#include <boost/range/adaptor/transformed.hpp>

#include "chopping/chopping_format/sillitoe_chopping_format.hpp"
#include "common/exception/invalid_argument_exception.hpp"
Expand All @@ -31,6 +32,7 @@ using namespace cath;
using namespace cath::chop;
using namespace cath::common;

using boost::adaptors::transformed;
using boost::algorithm::join;
using boost::any;
using boost::program_options::invalid_option_value;
Expand Down Expand Up @@ -399,6 +401,28 @@ ostream & cath::chop::operator<<(ostream &arg_os, ///< The ostream into
return arg_os;
}

/// \brief Generate a string describing the specified region_vec
///
/// \relates region
string cath::chop::to_string(const region_vec &arg_regions ///< The region_vec to describe
) {
return join(
arg_regions
| transformed( [] (const region &x) { return to_string( x ); } ),
","
);
}

/// \brief Insert a description of the specified region_vec into the specified ostream
///
/// \relates region_vec
ostream & cath::chop::operator<<(ostream &arg_os, ///< The ostream into which the description should be inserted
const region_vec &arg_regions ///< The region_vec to describe
) {
arg_os << to_string( arg_regions );
return arg_os;
}

/// \brief TODOCUMENT
void cath::chop::validate(any &arg_prev_value, ///< TODOCUMENT
const str_vec &arg_value_strings, ///< TODOCUMENT
Expand Down
5 changes: 5 additions & 0 deletions source/chopping/region/region.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ namespace cath {
std::ostream & operator<<(std::ostream &,
const region &);

std::string to_string(const region_vec &);

std::ostream & operator<<(std::ostream &,
const region_vec &);

void validate(boost::any &,
const str_vec &,
domain *,
Expand Down

0 comments on commit 443aff2

Please sign in to comment.