Mercurial > repos > chrisd > testshed
comparison snp_caller/src/alignment_util.h @ 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 #ifndef ALIGNMENT_UTIL_H | |
2 #define ALIGNMENT_UTIL_H | |
3 | |
4 #include "int_util.h" | |
5 | |
6 #include <string> | |
7 #include <vector> | |
8 | |
9 #include <boost/algorithm/string.hpp> | |
10 | |
11 #define READ_PAIRED 1 | |
12 #define PROPER_PAIR 2 | |
13 #define READ_UNMAPPED 4 | |
14 #define MATE_UNMAPPED 8 | |
15 | |
16 std::vector<std::string> split_alignment(std::string &alignment) { | |
17 std::vector<std::string> parts; | |
18 boost::trim_if(alignment, boost::is_any_of("\t ")); | |
19 boost::split(parts, alignment, boost::is_any_of("\t "), boost::token_compress_on); | |
20 return parts; | |
21 } | |
22 | |
23 bool is_good_se_flag(const int &flag) { | |
24 if( (flag & READ_UNMAPPED) > 0) { | |
25 return false; | |
26 } | |
27 else { | |
28 return true; | |
29 } | |
30 } | |
31 | |
32 bool is_good_pe_flag(const int &flag) { | |
33 if( (flag & READ_UNMAPPED) > 0 || (flag & MATE_UNMAPPED) > 0 || | |
34 (flag & READ_PAIRED) == 0 || (flag & PROPER_PAIR == 0) ) { | |
35 return false; | |
36 } | |
37 else { | |
38 return true; | |
39 } | |
40 } | |
41 | |
42 bool is_good_rname(const std::string &rname) { | |
43 return rname.compare("*") != 0; | |
44 } | |
45 | |
46 bool is_good_pos(const int &pos) { | |
47 return pos > 0; | |
48 } | |
49 | |
50 bool is_good_pnext(const int &pnext) { | |
51 return pnext > 0; | |
52 } | |
53 | |
54 bool is_good_cigar(const std::string &cigar) { | |
55 return cigar.compare("*") != 0; | |
56 } | |
57 | |
58 bool is_good_seq(const std::string &seq) { | |
59 return seq.compare("*") != 0; | |
60 } | |
61 | |
62 bool is_alignment_unique(const std::string &alignment) { | |
63 if(alignment.find("XT:A:U") != std::string::npos) { | |
64 return true; | |
65 } | |
66 else { | |
67 return false; | |
68 } | |
69 } | |
70 | |
71 /*bool is_good_alignment(std::string &alignment) { | |
72 std::vector<std::string> alignment_parts; | |
73 | |
74 alignment_parts = split_alignment(alignment); | |
75 | |
76 if(!(fields_are_good(alignment_parts))) | |
77 return false; | |
78 else | |
79 return true; | |
80 }*/ | |
81 | |
82 bool se_fields_are_good(std::string &alignment, bool best) { | |
83 std::vector<std::string> parts = split_alignment(alignment); | |
84 int flag = s_to_i(parts[1]); | |
85 int pos = s_to_i(parts[3]); | |
86 | |
87 std::string rname = parts[2]; | |
88 std::string cigar = parts[5]; | |
89 std::string seq = parts[9]; | |
90 | |
91 if(!(is_good_se_flag(flag))) return false; | |
92 if(!(is_good_pos(pos))) return false; | |
93 if(!(is_good_rname(rname))) return false; | |
94 if(!(is_good_cigar(cigar))) return false; | |
95 if(!(is_good_seq(seq))) return false; | |
96 if(best) { | |
97 if(!(is_alignment_unique(alignment))) { | |
98 return false; | |
99 } | |
100 } | |
101 | |
102 return true; | |
103 } | |
104 | |
105 bool pe_fields_are_good(std::string &alignment, bool best) { | |
106 std::vector<std::string> parts = split_alignment(alignment); | |
107 int flag = s_to_i(parts[1]); | |
108 int pos = s_to_i(parts[3]); | |
109 int pnext = s_to_i(parts[7]); | |
110 | |
111 std::string rname = parts[2]; | |
112 std::string cigar = parts[5]; | |
113 std::string seq = parts[9]; | |
114 | |
115 if(!(is_good_pe_flag(flag))) return false; | |
116 if(!(is_good_pos(pos))) return false; | |
117 if(!(is_good_rname(rname))) return false; | |
118 if(!(is_good_cigar(cigar))) return false; | |
119 if(!(is_good_pnext(pnext))) return false; | |
120 if(!(is_good_seq(seq))) return false; | |
121 if(best) { | |
122 if(!(is_alignment_unique(alignment))) { | |
123 return false; | |
124 } | |
125 } | |
126 | |
127 return true; | |
128 } | |
129 | |
130 #endif // ALIGNMENT_UTIL_H |