本文整理汇总了C++中Alignment::path方法的典型用法代码示例。如果您正苦于以下问题:C++ Alignment::path方法的具体用法?C++ Alignment::path怎么用?C++ Alignment::path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Alignment
的用法示例。
在下文中一共展示了Alignment::path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Alignment
pair<Alignment, Alignment> Filter::orientation_filter(Alignment& aln_first, Alignment& aln_second){
bool f_rev = false;
bool s_rev = false;
Path f_path = aln_first.path();
Path s_path = aln_second.path();
for (int i = 0; i < f_path.mapping_size(); i++){
if (f_path.mapping(i).position().is_reverse()){
f_rev = true;
}
}
for (int j = 0; j < s_path.mapping_size(); j++){
if (s_path.mapping(j).position().is_reverse()){
s_rev = true;
}
}
if (!s_rev != !f_rev){
return inverse ? std::make_pair(aln_first, aln_second) : std::make_pair(Alignment(), Alignment());
}
else{
return inverse ? std::make_pair(Alignment(), Alignment()) : std::make_pair(aln_first, aln_second);
}
}
示例2: soft_clip_filter
Alignment Filter::soft_clip_filter(Alignment& aln){
//Find overhangs - portions of the read that
// are inserted at the ends.
if (aln.path().mapping_size() > 0){
Path path = aln.path();
Edit left_edit = path.mapping(0).edit(0);
Edit right_edit = path.mapping(path.mapping_size() - 1).edit(path.mapping(path.mapping_size() - 1).edit_size() - 1);
int left_overhang = left_edit.to_length() - left_edit.from_length();
int right_overhang = right_edit.to_length() - right_edit.from_length();
if (left_overhang > soft_clip_limit || right_overhang > soft_clip_limit){
return inverse ? Alignment() : aln;
}
else{
return inverse ? aln : Alignment();
}
}
else{
if (aln.sequence().length() > soft_clip_limit){
return inverse ? Alignment() : aln;
}
cerr << "WARNING: SHORT ALIGNMENT: " << aln.sequence().size() << "bp" << endl
<< "WITH NO MAPPINGS TO REFERENCE" << endl
<< "CONSIDER REMOVING IT FROM ANALYSIS" << endl;
return inverse ? Alignment() : aln;
}
}
示例3: mutate
Alignment Sampler::mutate(const Alignment& aln,
double base_error,
double indel_error) {
if (base_error == 0 && indel_error == 0) return aln;
string bases = "ATGC";
uniform_real_distribution<double> rprob(0, 1);
uniform_int_distribution<int> rbase(0, 3);
Alignment mutaln;
for (size_t i = 0; i < aln.path().mapping_size(); ++i) {
auto& orig_mapping = aln.path().mapping(i);
Mapping* new_mapping = mutaln.mutable_path()->add_mapping();
*new_mapping->mutable_position() = orig_mapping.position();
// for each edit in the mapping
for (size_t j = 0; j < orig_mapping.edit_size(); ++j) {
auto& orig_edit = orig_mapping.edit(j);
auto new_edits = mutate_edit(orig_edit, make_pos_t(orig_mapping.position()),
base_error, indel_error,
bases, rprob, rbase);
for (auto& edit : new_edits) {
*new_mapping->add_edit() = edit;
}
}
}
// re-derive the alignment's sequence
mutaln = simplify(mutaln);
mutaln.set_sequence(alignment_seq(mutaln));
mutaln.set_name(aln.name());
return mutaln;
}
示例4: compute_from_alignment
void Pileups::compute_from_alignment(VG& graph, Alignment& alignment) {
// if we start reversed
if (alignment.has_path() && alignment.path().mapping(0).position().is_reverse()) {
alignment = reverse_alignment(alignment,
(function<int64_t(int64_t)>) ([&graph](int64_t id) {
return graph.get_node(id)->sequence().size();
}));
}
const Path& path = alignment.path();
int64_t read_offset = 0;
for (int i = 0; i < path.mapping_size(); ++i) {
const Mapping& mapping = path.mapping(i);
if (graph.has_node(mapping.position().node_id())) {
const Node* node = graph.get_node(mapping.position().node_id());
NodePileup* pileup = get_create(node->id());
int64_t node_offset = mapping.position().offset();
for (int j = 0; j < mapping.edit_size(); ++j) {
const Edit& edit = mapping.edit(j);
// process all pileups in edit.
// update the offsets as we go
compute_from_edit(*pileup, node_offset, read_offset, *node,
alignment, mapping, edit);
}
}
}
assert(alignment.sequence().empty() ||
alignment.path().mapping_size() == 0 ||
read_offset == alignment.sequence().length());
}
示例5: make_pair
pair<Alignment, Alignment> Filter::interchromosomal_filter(Alignment& aln_first, Alignment& aln_second){
if (aln_first.path().name() != aln_second.path().name()){
return std::make_pair(aln_first, aln_second);
}
else{
return std::make_pair(Alignment(), Alignment());
}
}
示例6: merge_alignments
Alignment merge_alignments(const Alignment& a1, const Alignment& a2, bool debug) {
//cerr << "overlap is " << overlap << endl;
// if either doesn't have a path, then treat it like a massive softclip
if (debug) cerr << "merging alignments " << endl << pb2json(a1) << endl << pb2json(a2) << endl;
// concatenate them
Alignment a3;
a3.set_sequence(a1.sequence() + a2.sequence());
*a3.mutable_path() = concat_paths(a1.path(), a2.path());
if (debug) cerr << "merged alignments, result is " << endl << pb2json(a3) << endl;
return a3;
}
示例7: alignment_seq
string Sampler::alignment_seq(const Alignment& aln) {
// get the graph corresponding to the alignment path
Graph sub;
for (int i = 0; i < aln.path().mapping_size(); ++ i) {
auto& m = aln.path().mapping(i);
if (m.has_position() && m.position().node_id()) {
auto id = aln.path().mapping(i).position().node_id();
xgidx->neighborhood(id, 2, sub);
}
}
VG g; g.extend(sub);
return g.path_string(aln.path());
}
示例8: percent_identity_filter
/**
* Filter reads that are less than <PCTID> reference.
* I.E. if a read matches the reference along 80% of its
* length, and your cutoff is 90% PCTID, throw it out.
*/
Alignment Filter::percent_identity_filter(Alignment& aln){
double read_pctid = 0.0;
//read pct_id = len(matching sequence / len(total sequence)
int64_t aln_total_len = aln.sequence().size();
int64_t aln_match_len = 0;
std::function<double(int64_t, int64_t)> calc_pct_id = [](int64_t rp, int64_t ttlp){
return ((double) rp / (double) ttlp);
};
Path path = aln.path();
//TODO handle reversing mappings
for (int i = 0; i < path.mapping_size(); i++){
Mapping mapping = path.mapping(i);
for (int j = 0; j < mapping.edit_size(); j++){
Edit ee = mapping.edit(j);
if (ee.from_length() == ee.to_length() && ee.sequence() == ""){
aln_match_len += ee.to_length();
}
}
}
if (calc_pct_id(aln_match_len, aln_total_len) < min_percent_identity){
return inverse ? aln : Alignment();
}
return inverse ? Alignment() : aln;
}
示例9: alignment_from_length
int alignment_from_length(const Alignment& a) {
int l = 0;
for (const auto& m : a.path().mapping()) {
l += from_length(m);
}
return l;
}
示例10: alignment_with_error
Alignment Sampler::alignment_with_error(size_t length,
double base_error,
double indel_error) {
size_t maxiter = 100;
Alignment aln;
if (base_error > 0 || indel_error > 0) {
// sample a longer-than necessary alignment, then trim
size_t iter = 0;
while (iter++ < maxiter) {
aln = mutate(
alignment(length + 2 * ((double) length * indel_error)),
base_error, indel_error);
if (aln.sequence().size() == length) {
break;
} else if (aln.sequence().size() > length) {
aln = strip_from_end(aln, aln.sequence().size() - length);
break;
}
}
if (iter == maxiter) {
cerr << "[vg::Sampler] Warning: could not generate alignment of sufficient length. "
<< "Graph may be too small, or indel rate too high." << endl;
}
} else {
aln = alignment(length);
}
aln.set_identity(identity(aln.path()));
return aln;
}
示例11: alignment_to_sam
string alignment_to_sam(const Alignment& alignment,
const string& refseq,
const int32_t refpos,
const string& cigar,
const string& mateseq,
const int32_t matepos,
const int32_t tlen) {
stringstream sam;
sam << (!alignment.name().empty() ? alignment.name() : "*") << "\t"
<< sam_flag(alignment) << "\t"
<< (refseq.empty() ? "*" : refseq) << "\t"
<< refpos + 1 << "\t"
//<< (alignment.path().mapping_size() ? refpos + 1 : 0) << "\t" // positions are 1-based in SAM, 0 means unmapped
<< alignment.mapping_quality() << "\t"
<< (alignment.has_path() && alignment.path().mapping_size() ? cigar : "*") << "\t"
<< (mateseq == refseq ? "=" : mateseq) << "\t"
<< matepos + 1 << "\t"
<< tlen << "\t"
<< (!alignment.sequence().empty() ? alignment.sequence() : "*") << "\t";
// hack much?
if (!alignment.quality().empty()) {
const string& quality = alignment.quality();
for (int i = 0; i < quality.size(); ++i) {
sam << quality_short_to_char(quality[i]);
}
} else {
sam << "*";
//sam << string(alignment.sequence().size(), 'I');
}
//<< (alignment.has_quality() ? string_quality_short_to_char(alignment.quality()) : string(alignment.sequence().size(), 'I'));
if (!alignment.read_group().empty()) sam << "\tRG:Z:" << alignment.read_group();
sam << "\n";
return sam.str();
}
示例12: interchromosomal_filter
Alignment Filter::interchromosomal_filter(Alignment& aln){
bool fails = aln.path().name() != aln.fragment_prev().path().name();
if (fails){
return inverse ? Alignment() : aln;
}
else{
return inverse ? aln : Alignment();
}
}
示例13: cigar_against_path
// act like the path this is against is the reference
// and generate an equivalent cigar
string cigar_against_path(const Alignment& alignment) {
vector<pair<int, char> > cigar;
if (!alignment.has_path()) return "";
const Path& path = alignment.path();
int l = 0;
for (const auto& mapping : path.mapping()) {
mapping_cigar(mapping, cigar);
}
return cigar_string(cigar);
}
示例14: one_end_anchored_filter
/* PE functions using fragment_prev and fragment_next */
Alignment Filter::one_end_anchored_filter(Alignment& aln){
if (aln.fragment_prev().name() != ""){
if (aln.path().name() == "" || aln.fragment_prev().path().name() == ""){
inverse ? Alignment() : aln;
}
else{
inverse ? aln : Alignment();
}
}
else{
return inverse ? aln : Alignment();
}
}
示例15: ret
vector<int> Vectorizer::alignment_to_a_hot(Alignment a){
int64_t entity_size = my_xg->node_count + my_xg->edge_count;
vector<int> ret(entity_size, 0);
Path path = a.path();
for (int i = 0; i < path.mapping_size(); i++){
Mapping mapping = path.mapping(i);
if(! mapping.has_position()){
continue;
}
Position pos = mapping.position();
int64_t node_id = pos.node_id();
int64_t key = my_xg->node_rank_as_entity(node_id);
// Okay, solved the previous out of range errors:
// We have to use an entity-space that is |nodes + edges + 1|
// as nodes are indexed from 1, not from 0.
//TODO: this means we may one day have to do the same bump up
// by one for edges, as I assume they are also indexed starting at 1.
//cerr << key << " - " << entity_size << endl;
//Find edge by current / previous node ID
// we can check the orientation, though it shouldn't **really** matter
// whether we catch them in the forward or reverse direction.
if (i > 0){
Mapping prev_mapping = path.mapping(i - 1);
Position prev_pos = prev_mapping.position();
int64_t prev_node_id = prev_pos.node_id();
if (my_xg->has_edge(prev_node_id, false, node_id, false)){
int64_t edge_key = my_xg->edge_rank_as_entity(prev_node_id, false, node_id, false);
vector<size_t> edge_paths = my_xg->paths_of_entity(edge_key);
if (edge_paths.size() > 0){
ret[edge_key - 1] = 1;
}
else{
ret[edge_key - 1] = 2;
}
}
}
//Check if the node of interest is on a path
vector<size_t> node_paths = my_xg->paths_of_node(node_id);
if (node_paths.size() > 0){
ret[key - 1] = 2;
}
else{
ret[key - 1] = 1;
}
}
return ret;
}