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