27 #define VJ_CHAIN_SIZE 4 28 #define VDJ_CHAIN_SIZE 7 31 #include "multimatrixchain.h" 57 : _recomb(UNDEF_RECOMB),
74 _recomb(other._recomb),
75 _n_poses(other._n_poses),
79 _err_prob(other._err_prob)
94 std::swap(_recomb, other._recomb);
96 _chain.swap(other._chain);
97 _values.swap(other._values);
102 std::swap(_err_prob, other._err_prob);
104 std::swap(_n_poses, other._n_poses);
180 MAAG& operator= (
const MAAG &other) {
181 _recomb = other._recomb;
182 _chain = other._chain;
183 _values = other._values;
190 _err_prob = other._err_prob;
197 _n_poses = other._n_poses;
218 std::swap(_recomb, other._recomb);
220 _chain.swap(other._chain);
221 _values.swap(other._values);
226 std::swap(_err_prob, other._err_prob);
228 std::swap(_n_poses, other._n_poses);
248 prob_t
fullProbability(event_ind_t v_index, event_ind_t j_index)
const {
250 if (_recomb == VJ_RECOMB) {
252 return (matrix(0, 0)(v_index, j_index) *
255 matrix(3, j_index))(0, 0);
262 prob_t
fullProbability(event_ind_t v_index, event_ind_t d_index, event_ind_t j_index)
const {
263 if (_recomb == VDJ_RECOMB) {
265 return (matrix(0, v_index) *
271 matrix(6, 0)(j_index, d_index))(0, 0);
277 prob_t
fullProbability(MAAGComputeProbAction action = SUM_PROBABILITY)
const {
279 if (_recomb == UNDEF_RECOMB) {
283 if (action == MAX_PROBABILITY) {
284 prob_t max_prob = 0, cur_prob = 0;
285 if (_recomb == VJ_RECOMB) {
286 for (event_ind_t v_index = 0; v_index < this->
nVar(); ++v_index) {
287 for (event_ind_t j_index = 0; j_index < this->nJoi(); ++j_index) {
289 if (cur_prob > max_prob) { max_prob = cur_prob; }
293 for (event_ind_t v_index = 0; v_index < this->
nVar(); ++v_index) {
294 for (event_ind_t d_index = 0; d_index < this->nDiv(); ++d_index) {
295 for (event_ind_t j_index = 0; j_index < this->nJoi(); ++j_index) {
297 if (cur_prob > max_prob) { max_prob = cur_prob; }
307 if (_recomb == VJ_RECOMB) {
308 for (event_ind_t v_index = 0; v_index < this->
nVar(); ++v_index) {
309 for (event_ind_t j_index = 0; j_index < this->nJoi(); ++j_index) {
314 for (event_ind_t v_index = 0; v_index < this->
nVar(); ++v_index) {
315 for (event_ind_t d_index = 0; d_index < this->nDiv(); ++d_index) {
316 for (event_ind_t j_index = 0; j_index < this->nJoi(); ++j_index) {
333 event_ind_t
nVar()
const {
return (_chain.size() == VJ_CHAIN_SIZE) ? this->nodeRows(VJ_VAR_JOI_GEN_I) : this->nodeSize(VDJ_VAR_GEN_I); }
336 event_ind_t nJoi()
const {
return (_chain.size() == VJ_CHAIN_SIZE) ? this->nodeColumns(VJ_VAR_JOI_GEN_I) : this->nodeSize(VDJ_JOI_DEL_I); }
338 event_ind_t nDiv()
const {
return (_chain.size() == VJ_CHAIN_SIZE) ? 0 : _chain[VDJ_DIV_DEL_I].size(); }
355 return (*
this)(node_i, mat_i, row, col);
359 return _events ? (*_events)(node_i, mat_i, row, col) : 0;
363 return _errors ? (*_errors)(node_i, mat_i, row, col) : 0;
368 seq_len_t position(seq_len_t i)
const {
return _seq_poses[i]; }
377 bool save(
const std::string &filepath)
const {
379 std::ofstream ofs(filepath);
380 return this->
save(ofs);
383 bool save(std::ostream &stream)
const {
387 bool load(
const std::string &filepath) {
388 std::ifstream ifs(filepath);
389 return this->load(ifs);
392 bool load(std::istream &stream) {
401 Recombination recombination()
const {
return _recomb; }
404 bool is_vj()
const {
return _recomb == VJ_RECOMB; }
406 bool is_vdj()
const {
return _recomb == VDJ_RECOMB; }
412 bool has_events()
const {
return (
bool)
_events; }
415 bool has_errors()
const {
return (
bool)
_errors; }
417 prob_t error_prob()
const {
return _err_prob; }
420 const std::string& sequence()
const {
422 if (!
_sequence) {
throw(std::runtime_error(
"Access to a MAAG sequence when it's a nullptr!")); }
428 seq_len_t n_poses()
const {
return _n_poses; }
431 SequenceType sequence_type()
const {
return _seq_type; }
435 dim_t cols(
node_ind_t node_i)
const {
return this->nodeColumns(node_i); }
461 Recombination _recomb;
Definition: maagbuilder.h:56
bool save(const std::string &filepath) const
Save the graph to the harddrive and load a previously saved graph.
Definition: maag.h:378
pEventIndMMC _events
Definition: maag.h:455
unique_ptr< sequence_t > _sequence
Definition: maag.h:458
prob_t event_probability(node_ind_t node_i, matrix_ind_t mat_i, dim_t row, dim_t col) const
Access to event indices, event probabilities and mismatches in the underlying matrices of the MAAG...
Definition: maag.h:354
prob_t fullProbability(event_ind_t v_index, event_ind_t j_index) const
Compute and return the full assembling probability of this sequence (i.e., with all gene segments ali...
Definition: maag.h:249
virtual ~MAAG()
Special swap constructor for MAAGs that will be used only for computation of the full probability...
Definition: maag.h:177
Definition: maagforwardbackwardalgorithm.h:20
SequenceType _seq_type
Definition: maag.h:460
Multi-Alignment Assembly Graph - basic class for representing all possible generation scenarios of a ...
Definition: maag.h:46
MAAG()
Default constructor.
Definition: maag.h:56
uint8_t node_ind_t
Node index type.
Definition: multimatrixchain.h:91
seq_len_t dim_t
Type of dimensions of matrices (rows and columns).
Definition: multimatrixchain.h:108
event_ind_t nVar() const
Get the number of aligned gene segments.
Definition: maag.h:334
Class for storing lists of matrices, where one node in the list (called "chain") could contain more t...
Definition: multimatrixchain.h:39
uint8_t matrix_ind_t
Matrix index type.
Definition: multimatrixchain.h:99
pErrMMC _errors
Definition: maag.h:456
unique_ptr< seq_len_t[]> _seq_poses
Definition: maag.h:457