Skip to content

Commit

Permalink
Make alignment_acquirer take strucs_context
Browse files Browse the repository at this point in the history
By comparison to taking PDBs, this allows alignment_acquirers to use the
extra information about the PDBs, such as their names and provenances.
  • Loading branch information
tonyelewis committed Nov 18, 2017
1 parent 96f489f commit e8bebb3
Show file tree
Hide file tree
Showing 21 changed files with 110 additions and 122 deletions.
24 changes: 7 additions & 17 deletions source/cath_refine_align/cath_align_refiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
#include "cath_refine_align/options/cath_refine_align_options.hpp"
#include "chopping/region/region.hpp"
#include "common/exception/not_implemented_exception.hpp"
#include "file/pdb/pdb.hpp"
#include "file/pdb/pdb_atom.hpp"
#include "file/pdb/pdb_list.hpp"
#include "file/pdb/pdb_residue.hpp"
#include "outputter/alignment_outputter/alignment_outputter.hpp"
#include "outputter/alignment_outputter/alignment_outputter_list.hpp"
#include "outputter/superposition_outputter/superposition_outputter.hpp"
Expand Down Expand Up @@ -76,27 +72,21 @@ void cath_align_refiner::refine(const cath_refine_align_options &arg_cath_refine

// Grab the PDBs and their IDs
const strucs_context context = get_pdbs_and_names( arg_cath_refine_align_options, arg_istream, true );
const pdb_list &raw_pdbs = context.get_pdbs();

// TODO: Populate this name summarising the overall group so it can be used, eg in superposition scripts
const string overall_name{};

const pdb_list backbone_complete_subset_pdbs = pdb_list_of_backbone_complete_region_limited_subset_pdbs(
raw_pdbs,
context.get_regions(),
const auto backbone_complete_strucs_context = strucs_context_of_backbone_complete_region_limited_subset_pdbs(
context,
ref( arg_stderr )
);

const protein_list proteins = build_protein_list_of_pdb_list_and_names(
backbone_complete_subset_pdbs,
context.get_name_sets()
);

// An alignment is required but this should have been checked elsewhere
const auto aln_acq_ptr = get_alignment_acquirer( arg_cath_refine_align_options );
const auto alignment_and_tree = aln_acq_ptr->get_alignment_and_spanning_tree( backbone_complete_subset_pdbs );
const alignment &the_alignment = alignment_and_tree.first;
const size_size_pair_vec &spanning_tree = alignment_and_tree.second;
const protein_list proteins = build_protein_list( backbone_complete_strucs_context );
const auto aln_acq_ptr = get_alignment_acquirer( arg_cath_refine_align_options );
const auto alignment_and_tree = aln_acq_ptr->get_alignment_and_spanning_tree( backbone_complete_strucs_context );
const alignment &the_alignment = alignment_and_tree.first;
const auto &spanning_tree = alignment_and_tree.second;

// if ( proteins.size() != 2 || the_alignment.num_entries() != 2 ) {
// BOOST_THROW_EXCEPTION(not_implemented_exception("Currently only able to score alignments of more than two structures"));
Expand Down
12 changes: 5 additions & 7 deletions source/cath_score_align/cath_align_scorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include "file/name_set/name_set_list.hpp"
#include "file/pdb/pdb.hpp"
#include "file/pdb/pdb_atom.hpp"
#include "file/pdb/pdb_list.hpp"
#include "file/pdb/pdb_residue.hpp"
#include "file/strucs_context.hpp"
#include "score/aligned_pair_score_list/aligned_pair_score_list_factory.hpp"
#include "score/aligned_pair_score_list/aligned_pair_score_value_list.hpp"
#include "score/aligned_pair_score_list/score_value_list_outputter/score_value_list_json_outputter.hpp"
Expand Down Expand Up @@ -63,15 +63,13 @@ void cath_align_scorer::score(const cath_score_align_options &arg_cath_score_ali
return;
}

const auto pdbs_acquirer_ptr = get_pdbs_acquirer( arg_cath_score_align_options );
const auto pdbs_and_names = pdbs_acquirer_ptr->get_pdbs_and_names( arg_istream, true );
const pdb_list &pdbs = pdbs_and_names.first;
const name_set_list &names = pdbs_and_names.second;
const protein_list proteins = build_protein_list_of_pdb_list_and_names( pdbs, names );
// Grab the PDBs and their IDs
const strucs_context context = get_pdbs_and_names( arg_cath_score_align_options, arg_istream, false );
const protein_list proteins = build_protein_list( context );

// An alignment is required but this should have been checked elsewhere
const auto alignment_acq_ptr = get_alignment_acquirer( arg_cath_score_align_options );
const auto alignment_and_tree = alignment_acq_ptr->get_alignment_and_spanning_tree( pdbs );
const auto alignment_and_tree = alignment_acq_ptr->get_alignment_and_spanning_tree( context );
const alignment &the_alignment = alignment_and_tree.first;
// const auto &spanning_tree = alignment_and_tree.second;

Expand Down
19 changes: 19 additions & 0 deletions source/cath_score_align/options/cath_score_align_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "alignment/common_atom_selection_policy/common_atom_select_ca_policy.hpp"
#include "alignment/common_residue_selection_policy/common_residue_select_all_policy.hpp"
#include "alignment/common_residue_selection_policy/common_residue_select_best_score_percent_policy.hpp"
#include "chopping/domain/domain.hpp"
#include "chopping/region/region.hpp"
#include "common/argc_argv_faker.hpp"
#include "common/exception/invalid_argument_exception.hpp"
Expand All @@ -49,9 +50,11 @@
using namespace cath;
using namespace cath::align;
using namespace cath::common;
using namespace cath::file;
using namespace cath::opts;

using boost::none;
using std::istream;
using std::string;
using std::unique_ptr;

Expand Down Expand Up @@ -164,3 +167,19 @@ unique_ptr<const pdbs_acquirer> cath::opts::get_pdbs_acquirer(const cath_score_a
) {
return get_pdbs_acquirer( arg_cath_score_align_options.get_pdb_input_spec() );
}

/// \brief Get PDBs and names as implied by the specified cath_score_align_options
///
/// Throws an invalid_argument_exception if the cath_score_align_options isn't configured to read PDBs
///
/// \relates cath_score_align_options
strucs_context cath::opts::get_pdbs_and_names(const cath_score_align_options &arg_cath_score_align_options, ///< The options to specify how to get the PDBs and names
istream &arg_istream, ///< The istream, which may contain PDB data
const bool &arg_remove_partial_residues ///< Whether to remove partial residues from the PDB data
) {
return get_strucs_context(
*get_pdbs_acquirer( arg_cath_score_align_options ),
arg_istream,
arg_remove_partial_residues
);
}
9 changes: 7 additions & 2 deletions source/cath_score_align/options/cath_score_align_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <vector>

namespace cath { namespace align { class alignment_acquirer; } }
namespace cath { namespace file { class strucs_context; } }
namespace cath { namespace opts { class pdbs_acquirer; } }

namespace cath {
Expand All @@ -43,10 +44,10 @@ namespace cath {
static const std::string STANDARD_USAGE_ERROR_STRING;

/// \brief TODOCUMENT
alignment_input_options_block the_alignment_input_options_block;
alignment_input_options_block the_alignment_input_options_block;

/// \brief TODOCUMENT
pdb_input_options_block the_pdb_input_options_block;
pdb_input_options_block the_pdb_input_options_block;

std::string do_get_program_name() const final;
str_opt do_get_error_or_help_string() const final;
Expand All @@ -68,6 +69,10 @@ namespace cath {

std::unique_ptr<const align::alignment_acquirer> get_alignment_acquirer(const cath_score_align_options &);
std::unique_ptr<const pdbs_acquirer> get_pdbs_acquirer(const cath_score_align_options &);
file::strucs_context get_pdbs_and_names(const cath_score_align_options &,
std::istream &,
const bool &);

} // namespace opts
} // namespace cath

Expand Down
18 changes: 8 additions & 10 deletions source/cath_superpose/cath_superposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ superposition_context cath_superposer::get_superposition_context(const cath_supe

// Grab the PDBs and their IDs
const strucs_context context = get_pdbs_and_names( arg_cath_sup_opts, arg_istream, false );
const pdb_list &raw_pdbs = context.get_pdbs();

if ( raw_pdbs.empty() ) {
if ( context.get_pdbs().empty() ) {
logger::log_and_exit(
logger::return_code::NO_PDB_FILES_LOADED,
"No valid PDBs were loaded"
Expand All @@ -116,19 +115,18 @@ superposition_context cath_superposer::get_superposition_context(const cath_supe
if ( json_sup_infile ) {
return set_pdbs_copy(
read_from_json_file<superposition_context>( *json_sup_infile ),
raw_pdbs
context.get_pdbs()
);
}

// Get the alignment and corresponding spanning tree
const pdb_list backbone_complete_subset_pdbs = pdb_list_of_backbone_complete_region_limited_subset_pdbs(
raw_pdbs,
context.get_regions(),
const auto backbone_complete_strucs_context = strucs_context_of_backbone_complete_region_limited_subset_pdbs(
context,
ref( arg_stderr )
);
const auto aln_and_spn_tree = [&] {
const auto aln_and_spn_tree = [&] {
try {
return get_alignment_and_spanning_tree( arg_cath_sup_opts, backbone_complete_subset_pdbs );
return get_alignment_and_spanning_tree( arg_cath_sup_opts, backbone_complete_strucs_context );
}
catch (const std::exception &e) {
logger::log_and_exit(
Expand All @@ -146,14 +144,14 @@ superposition_context cath_superposer::get_superposition_context(const cath_supe
if ( ! ssap_scores_file.empty() ) {
return {
hacky_multi_ssap_fuction(
backbone_complete_subset_pdbs,
backbone_complete_strucs_context.get_pdbs(),
get_multi_ssap_alignment_file_names( context.get_name_sets() ),
spanning_tree,
ssap_scores_file.parent_path(),
arg_cath_sup_opts.get_selection_policy_acquirer(),
arg_stderr
),
context, ///< Importantly, this contains the raw_pdbs, not backbone_complete_subset_pdbs, so that superpositions include stripped residues (eg HETATM only residues). /// \todo Consider adding fast, simple test that ssap_scores_file superposition output includes HETATMs.
context, ///< Importantly, this contains the raw structures, not backbone_complete_subset, so that superpositions include stripped residues (eg HETATM only residues). /// \todo Consider adding fast, simple test that ssap_scores_file superposition output includes HETATMs.
the_alignment
};
}
Expand Down
4 changes: 2 additions & 2 deletions source/cath_superpose/options/cath_superpose_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ unique_ptr<const alignment_acquirer> cath::opts::get_alignment_acquirer(const ca
///
/// \relates cath_superpose_options
pair<alignment, size_size_pair_vec> cath::opts::get_alignment_and_spanning_tree(const cath_superpose_options &arg_cath_sup_opts, ///< The options to specify how to get the alignment and spanning tree
const pdb_list &arg_pdbs ///< The PDBs to use
const strucs_context &arg_strucs ///< The structures to use
) {
return get_alignment_acquirer( arg_cath_sup_opts )->get_alignment_and_spanning_tree( arg_pdbs );
return get_alignment_acquirer( arg_cath_sup_opts )->get_alignment_and_spanning_tree( arg_strucs );
}

/// \brief Get the single pdbs_acquirer implied by the specified cath_superpose_options
Expand Down
2 changes: 1 addition & 1 deletion source/cath_superpose/options/cath_superpose_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace cath {

std::unique_ptr<const align::alignment_acquirer> get_alignment_acquirer(const cath_superpose_options &);
std::pair<align::alignment, size_size_pair_vec> get_alignment_and_spanning_tree(const cath_superpose_options &,
const file::pdb_list &);
const file::strucs_context &);

std::unique_ptr<const pdbs_acquirer> get_pdbs_acquirer(const cath_superpose_options &);
file::strucs_context get_pdbs_and_names(const cath_superpose_options &,
Expand Down
11 changes: 4 additions & 7 deletions source/uni/acquirer/alignment_acquirer/alignment_acquirer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@
#include "common/exception/out_of_range_exception.hpp"
#include "common/exception/runtime_error_exception.hpp"
#include "common/logger.hpp"
#include "file/pdb/pdb.hpp"
#include "file/pdb/pdb_atom.hpp"
#include "file/pdb/pdb_list.hpp"
#include "file/pdb/pdb_residue.hpp"
#include "file/strucs_context.hpp"
#include "options/options_block/alignment_input_options_block.hpp"
#include "options/options_block/alignment_input_spec.hpp"

Expand Down Expand Up @@ -65,18 +62,18 @@ unique_ptr<alignment_acquirer> alignment_acquirer::clone() const {
///
/// The order of the edges in the spanning tree doesn't matter and the scores are discarded
/// because none of that matters for superposing
pair<alignment, size_size_pair_vec> alignment_acquirer::get_alignment_and_spanning_tree(const pdb_list &arg_pdbs ///< The PDBs to which the alignment should correspond
pair<alignment, size_size_pair_vec> alignment_acquirer::get_alignment_and_spanning_tree(const strucs_context &arg_strucs_context ///< The structures to which the alignment should correspond
) const {
using std::to_string;

// Call the concrete class's implementation of do_get_alignment_and_orderer() and grab the resulting alignment and spanning_tree
const pair<alignment, size_size_pair_vec> alignment_and_orderer = do_get_alignment_and_spanning_tree( arg_pdbs );
const pair<alignment, size_size_pair_vec> alignment_and_orderer = do_get_alignment_and_spanning_tree( arg_strucs_context );

const size_t num_alignment_entries = alignment_and_orderer.first.num_entries();
const size_t num_span_tree_entries = alignment_and_orderer.second.size();

// Check that both are of the correct size
const size_t num_pdbs = arg_pdbs.size();
const size_t num_pdbs = arg_strucs_context.get_pdbs().size();
if ( num_alignment_entries != num_pdbs ) {
BOOST_THROW_EXCEPTION(runtime_error_exception(
"Number of entries in alignment ("
Expand Down
10 changes: 3 additions & 7 deletions source/uni/acquirer/alignment_acquirer/alignment_acquirer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@
#include <utility>

namespace cath { namespace align { class alignment; } }
namespace cath { namespace file { class pdb_list; } }
namespace cath { namespace file { class strucs_context; } }
namespace cath { namespace opts { class alignment_input_options_block; } }
namespace cath { namespace opts { class alignment_input_spec; } }
namespace cath { namespace opts { class cath_refine_align_options; } }
namespace cath { namespace opts { class cath_score_align_options; } }
namespace cath { namespace opts { class cath_superpose_options; } }
namespace cath { namespace opts {class pdbs_acquirer; } }

namespace cath {
namespace align {
Expand All @@ -45,7 +41,7 @@ namespace cath {
virtual std::unique_ptr<alignment_acquirer> do_clone() const = 0;

/// \brief TODOCUMENT
virtual std::pair<alignment, size_size_pair_vec> do_get_alignment_and_spanning_tree(const file::pdb_list &) const = 0;
virtual std::pair<alignment, size_size_pair_vec> do_get_alignment_and_spanning_tree(const file::strucs_context &) const = 0;

protected:
/// \brief The minimum number of residues that are required in "residue name" aligning
Expand All @@ -66,7 +62,7 @@ namespace cath {
alignment_acquirer & operator=(const alignment_acquirer &) = default;
alignment_acquirer & operator=(alignment_acquirer &&) noexcept = default;

std::pair<alignment, size_size_pair_vec> get_alignment_and_spanning_tree(const file::pdb_list &) const;
std::pair<alignment, size_size_pair_vec> get_alignment_and_spanning_tree(const file::strucs_context &) const;
};

uptr_vec<alignment_acquirer> get_alignment_acquirers(const opts::alignment_input_spec &);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
#include "common/boost_addenda/graph/spanning_tree.hpp"
#include "common/clone/make_uptr_clone.hpp"
#include "common/file/open_fstream.hpp"
#include "file/pdb/pdb.hpp"
#include "file/pdb/pdb_atom.hpp"
#include "file/pdb/pdb_list.hpp"
#include "file/pdb/pdb_residue.hpp"
#include "file/strucs_context.hpp"
#include "structure/protein/protein.hpp"
#include "structure/protein/protein_list.hpp"
#include "structure/protein/residue.hpp"
Expand Down Expand Up @@ -58,16 +55,17 @@ unique_ptr<alignment_acquirer> cora_aln_file_alignment_acquirer::do_clone() cons
}

/// \brief TODOCUMENT
pair<alignment, size_size_pair_vec> cora_aln_file_alignment_acquirer::do_get_alignment_and_spanning_tree(const pdb_list &arg_pdbs ///< TODOCUMENT
pair<alignment, size_size_pair_vec> cora_aln_file_alignment_acquirer::do_get_alignment_and_spanning_tree(const strucs_context &arg_strucs_context ///< TODOCUMENT
) const {
// Construct an alignment from the CORA alignment file
const size_t num_pdbs = arg_pdbs.size();
const auto &the_pdbs = arg_strucs_context.get_pdbs();
const size_t num_pdbs = the_pdbs.size();
ifstream my_aln_stream;
open_ifstream(my_aln_stream, get_cora_alignment_file());
const alignment new_alignment = read_alignment_from_cath_cora_legacy_format( my_aln_stream, arg_pdbs, ostream_ref{ cerr } );
const alignment new_alignment = read_alignment_from_cath_cora_legacy_format( my_aln_stream, the_pdbs, ostream_ref{ cerr } );
my_aln_stream.close();

const protein_list proteins_of_pdbs = build_protein_list_of_pdb_list( arg_pdbs );
const protein_list proteins_of_pdbs = build_protein_list( arg_strucs_context );
const alignment scored_new_alignment = score_alignment_copy( residue_scorer(), new_alignment, proteins_of_pdbs );

// Return the results with a simple spanning tree that will connect the entries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace cath {
boost::filesystem::path cora_alignment_file;

std::unique_ptr<alignment_acquirer> do_clone() const final;
std::pair<alignment, size_size_pair_vec> do_get_alignment_and_spanning_tree(const file::pdb_list &) const final;
std::pair<alignment, size_size_pair_vec> do_get_alignment_and_spanning_tree(const file::strucs_context &) const final;

public:
explicit cora_aln_file_alignment_acquirer(const boost::filesystem::path &);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
#include "common/boost_addenda/graph/spanning_tree.hpp"
#include "common/clone/make_uptr_clone.hpp"
#include "common/file/open_fstream.hpp"
#include "file/pdb/pdb.hpp"
#include "file/pdb/pdb_atom.hpp"
#include "file/pdb/pdb_list.hpp"
#include "file/pdb/pdb_residue.hpp"
#include "file/strucs_context.hpp"
#include "structure/protein/protein.hpp"
#include "structure/protein/protein_list.hpp"
#include "structure/protein/residue.hpp"
Expand All @@ -54,18 +51,18 @@ unique_ptr<alignment_acquirer> fasta_aln_file_alignment_acquirer::do_clone() con
}

/// \brief TODOCUMENT
pair<alignment, size_size_pair_vec> fasta_aln_file_alignment_acquirer::do_get_alignment_and_spanning_tree(const pdb_list &arg_pdbs ///< TODOCUMENT
pair<alignment, size_size_pair_vec> fasta_aln_file_alignment_acquirer::do_get_alignment_and_spanning_tree(const strucs_context &arg_strucs_context ///< TODOCUMENT
) const {
// Construct an alignment from the FASTA alignment file
const protein_list proteins_of_pdbs = build_protein_list_of_pdb_list( arg_pdbs );
const protein_list proteins_of_pdbs = build_protein_list( arg_strucs_context );
const alignment new_alignment = read_alignment_from_fasta_file( get_fasta_alignment_file(), proteins_of_pdbs, cerr );

const alignment scored_new_alignment = score_alignment_copy( residue_scorer(), new_alignment, proteins_of_pdbs );

// Return the results
return make_pair(
scored_new_alignment,
make_simple_unweighted_spanning_tree( arg_pdbs.size() )
make_simple_unweighted_spanning_tree( proteins_of_pdbs.size() )
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace cath {
boost::filesystem::path fasta_alignment_file;

std::unique_ptr<alignment_acquirer> do_clone() const final;
std::pair<alignment, size_size_pair_vec> do_get_alignment_and_spanning_tree(const file::pdb_list &) const final;
std::pair<alignment, size_size_pair_vec> do_get_alignment_and_spanning_tree(const file::strucs_context &) const final;

public:
explicit fasta_aln_file_alignment_acquirer(const boost::filesystem::path &);
Expand Down

0 comments on commit e8bebb3

Please sign in to comment.