本文整理汇总了C++中Mapping::set_rank方法的典型用法代码示例。如果您正苦于以下问题:C++ Mapping::set_rank方法的具体用法?C++ Mapping::set_rank怎么用?C++ Mapping::set_rank使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mapping
的用法示例。
在下文中一共展示了Mapping::set_rank方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: align_internal
void Aligner::align_internal(Alignment& alignment, vector<Alignment>* multi_alignments, Graph& g,
int64_t pinned_node_id, bool pin_left, int32_t max_alt_alns, bool print_score_matrices) {
// check input integrity
if (pin_left && !pinned_node_id) {
cerr << "error:[Aligner] cannot choose pinned end in non-pinned alignment" << endl;
exit(EXIT_FAILURE);
}
if (multi_alignments && !pinned_node_id) {
cerr << "error:[Aligner] multiple traceback is not valid in local alignment, only pinned and global" << endl;
exit(EXIT_FAILURE);
}
if (!(multi_alignments) && max_alt_alns != 1) {
cerr << "error:[Aligner] cannot specify maximum number of alignments in single alignment" << endl;
exit(EXIT_FAILURE);
}
// alignment pinning algorithm is based on pinning in bottom right corner, if pinning in top
// left we need to reverse all the sequences first and translate the alignment back later
// create reversed objects if necessary
Graph reversed_graph;
string reversed_sequence;
if (pin_left) {
reversed_sequence.resize(alignment.sequence().length());
reverse_copy(alignment.sequence().begin(), alignment.sequence().end(), reversed_sequence.begin());
reverse_graph(g, reversed_graph);
}
// choose forward or reversed objects
Graph* align_graph;
string* align_sequence;
if (pin_left) {
align_graph = &reversed_graph;
align_sequence = &reversed_sequence;
}
else {
align_graph = &g;
align_sequence = alignment.mutable_sequence();
}
// convert into gssw graph and get the counterpart to pinned node (if pinning)
gssw_node* pinned_node = nullptr;
gssw_graph* graph = create_gssw_graph(*align_graph, pinned_node_id, &pinned_node);
if (pinned_node_id & !pinned_node) {
cerr << "error:[Aligner] pinned node for pinned alignment is not in graph" << endl;
exit(EXIT_FAILURE);
}
// perform dynamic programming
gssw_graph_fill(graph, (*align_sequence).c_str(),
nt_table, score_matrix,
gap_open, gap_extension, 15, 2);
// traceback either from pinned position or optimal local alignment
if (pinned_node) {
// trace back pinned alignment
gssw_graph_mapping** gms = gssw_graph_trace_back_pinned_multi (graph,
pinned_node,
max_alt_alns,
(*align_sequence).c_str(),
(*align_sequence).size(),
nt_table,
score_matrix,
gap_open,
gap_extension);
if (pin_left) {
// translate graph and mappings into original node space
unreverse_graph(reversed_graph);
for (int32_t i = 0; i < max_alt_alns; i++) {
unreverse_graph_mapping(gms[i]);
}
}
// convert optimal alignment and store it in the input Alignment object (in the multi alignment,
// this will have been set to the first in the vector)
if (gms[0]->score > 0) {
// have a mapping, can just convert normally
gssw_mapping_to_alignment(graph, gms[0], alignment, print_score_matrices);
}
else {
// gssw will not identify mappings with 0 score, infer location based on pinning
Mapping* mapping = alignment.mutable_path()->add_mapping();
mapping->set_rank(1);
// locate at the end of the node
Position* position = mapping->mutable_position();
position->set_node_id(pinned_node_id);
position->set_offset(pin_left ? 0 : pinned_node->len);
// soft clip
Edit* edit = mapping->add_edit();
edit->set_to_length(alignment.sequence().length());
edit->set_sequence(alignment.sequence());
}
//.........这里部分代码省略.........
示例2: gssw_mapping_to_alignment
void Aligner::gssw_mapping_to_alignment(gssw_graph* graph,
gssw_graph_mapping* gm,
Alignment& alignment,
bool print_score_matrices) {
alignment.clear_path();
alignment.set_score(gm->score);
alignment.set_query_position(0);
Path* path = alignment.mutable_path();
//alignment.set_cigar(graph_cigar(gm));
gssw_graph_cigar* gc = &gm->cigar;
gssw_node_cigar* nc = gc->elements;
int to_pos = 0;
int from_pos = gm->position;
//cerr << "gm->position " << gm->position << endl;
string& to_seq = *alignment.mutable_sequence();
//cerr << "-------------" << endl;
if (print_score_matrices) {
gssw_graph_print_score_matrices(graph, to_seq.c_str(), to_seq.size(), stderr);
//cerr << alignment.DebugString() << endl;
}
for (int i = 0; i < gc->length; ++i, ++nc) {
if (i > 0) from_pos = 0; // reset for each node after the first
// check that the current alignment has a non-zero length
gssw_cigar* c = nc->cigar;
int l = c->length;
if (l == 0) continue;
gssw_cigar_element* e = c->elements;
Node* from_node = (Node*) nc->node->data;
string& from_seq = *from_node->mutable_sequence();
Mapping* mapping = path->add_mapping();
mapping->mutable_position()->set_node_id(nc->node->id);
mapping->mutable_position()->set_offset(from_pos);
mapping->set_rank(path->mapping_size());
//cerr << from_node->id() << ":" << endl;
for (int j=0; j < l; ++j, ++e) {
Edit* edit;
int32_t length = e->length;
//cerr << e->length << e->type << endl;
switch (e->type) {
case 'M':
case 'X':
case 'N': {
// do the sequences match?
// emit a stream of "SNPs" and matches
int h = from_pos;
int last_start = from_pos;
int k = to_pos;
for ( ; h < from_pos + length; ++h, ++k) {
//cerr << h << ":" << k << " " << from_seq[h] << " " << to_seq[k] << endl;
if (from_seq[h] != to_seq[k]) {
// emit the last "match" region
if (h-last_start > 0) {
edit = mapping->add_edit();
edit->set_from_length(h-last_start);
edit->set_to_length(h-last_start);
}
// set up the SNP
edit = mapping->add_edit();
edit->set_from_length(1);
edit->set_to_length(1);
edit->set_sequence(to_seq.substr(k,1));
last_start = h+1;
}
}
// handles the match at the end or the case of no SNP
if (h-last_start > 0) {
edit = mapping->add_edit();
edit->set_from_length(h-last_start);
edit->set_to_length(h-last_start);
}
to_pos += length;
from_pos += length;
}
break;
case 'D':
edit = mapping->add_edit();
edit->set_from_length(length);
edit->set_to_length(0);
from_pos += length;
break;
case 'I':
edit = mapping->add_edit();
edit->set_from_length(0);
edit->set_to_length(length);
edit->set_sequence(to_seq.substr(to_pos, length));
to_pos += length;
break;
case 'S':
// note that soft clips and insertions are semantically equivalent
// and can only be differentiated by their position in the read
// with soft clips coming at the start or end
edit = mapping->add_edit();
//.........这里部分代码省略.........