annotate snp_caller/src/Alignment.cpp @ 0:0fd352f62446 draft default tip

planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
author chrisd
date Sun, 21 Feb 2016 06:05:24 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
1 #include "Alignment.h"
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
2 #include "int_util.h"
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
3
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
4 #include <boost/algorithm/string.hpp>
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
5
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
6 #include <iostream>
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
7 #include <sstream>
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
8 #include <algorithm>
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
9
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
10 #define READ_PAIRED 1
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
11 #define READ_MAPPED_IN_PROPER_PAIR 2
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
12 #define READ_UNMAPPED 4
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
13 #define MATE_UNMAPPED 8
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
14 #define READ_REVERSE_STRAND 16
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
15 #define MATE_REVERSE_STRAND 32
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
16 #define FIRST_IN_PAIR 64
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
17 #define SECOND_IN_PAIR 128
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
18 #define NOT_PRIMARY_ALIGNMENT 256
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
19 #define READ_FAILS_VENDOR_QUALITY_CHECKS 512
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
20 #define READ_IS_PCR_OR_OPTICAL_DUPLICATE 1024
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
21 #define SUPPLEMENTARY_ALIGNMENT 2048
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
22
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
23 Alignment::Alignment(std::string alignment) : _alignment(alignment) {
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
24 fill_alignment_fields(alignment);
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
25 fill_bit_flag(field.FLAG);
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
26 fill_xa_field(alignment);
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
27 }
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
28
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
29 void Alignment::fill_alignment_fields(const std::string &alignment) {
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
30 std::istringstream ss(alignment);
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
31 ss >> field.QNAME >> field.FLAG >> field.RNAME >> field.POS >>
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
32 field.MAPQ >> field.CIGAR >> field.RNEXT >> field.PNEXT >>
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
33 field.TLEN >> field.SEQ >> field.QUAL;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
34 }
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
35
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
36 void Alignment::fill_bit_flag(const int &flag) {
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
37 if( (flag & READ_PAIRED) == 1) b_flag.read_paired = true;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
38 if( (flag & READ_MAPPED_IN_PROPER_PAIR) > 1) b_flag.read_mapped_in_proper_pair = true;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
39 if( (flag & READ_UNMAPPED) > 1) b_flag.read_unmapped = true;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
40 if( (flag & MATE_UNMAPPED) > 1) b_flag.mate_unmapped = true;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
41 if( (flag & READ_REVERSE_STRAND) > 1) b_flag.read_reverse_strand = true;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
42 if( (flag & MATE_REVERSE_STRAND) > 1) b_flag.mate_reverse_strand = true;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
43 if( (flag & FIRST_IN_PAIR) > 1) b_flag.first_in_pair = true;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
44 if( (flag & SECOND_IN_PAIR) > 1) b_flag.second_in_pair = true;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
45 }
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
46
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
47 // XA:Z:mef(A)_10_AF376746,+81,92M,2;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
48 bool Alignment::fill_xa_field(const std::string &alignment) {
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
49 xa_fields hits;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
50 std::string alt_fields;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
51 int offset = 5;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
52 std::size_t alt_index = alignment.find("XA:Z:");
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
53
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
54 if(alt_index != std::string::npos) {
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
55 alt_fields = alignment.substr(alt_index+offset, alignment.length());
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
56 }
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
57 else {
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
58 return false;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
59 }
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
60
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
61 std::string field;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
62 std::istringstream ss(alt_fields);
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
63
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
64 while(std::getline(ss, field, ',')) {
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
65 hits.rname = field;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
66 //std::cout << hits.rname << std::endl;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
67 getline(ss, field, ',');
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
68 hits.pos = strand_to_i(field);
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
69 //std::cout << hits.pos << std::endl;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
70 getline(ss, field, ',');
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
71 hits.cigar = field;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
72 //std::cout << hits.cigar << std::endl;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
73 getline(ss, field, ';');
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
74 hits.edit = 0;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
75 alternate_hits.push_back(hits);
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
76 }
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
77
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
78 return true;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
79 }
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
80
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
81 std::vector<std::pair<int,char> > Alignment::get_cigar() {
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
82 return get_cigar_operations(field.CIGAR);
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
83 }
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
84
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
85 std::vector<std::pair<int,char> > Alignment::get_cigar_operations(const std::string &cigar) {
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
86 std::vector<std::pair<int,char>> p;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
87 int count;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
88 char operation;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
89
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
90 std::istringstream ss(cigar);
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
91 while(ss >> count >> operation) {
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
92 p.push_back(std::make_pair(count,operation));
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
93 }
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
94
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
95 return p;
0fd352f62446 planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
chrisd
parents:
diff changeset
96 }