Mercurial > repos > chrisd > testing
comparison gene_fraction/src/alignment_util.h @ 0:f95150c37d38 draft default tip
planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
| author | chrisd |
|---|---|
| date | Sun, 21 Feb 2016 23:31:55 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:f95150c37d38 |
|---|---|
| 1 #ifndef ALIGNMENT_UTIL_H | |
| 2 #define ALIGNMENT_UTIL_H | |
| 3 | |
| 4 #include <string> | |
| 5 #include <vector> | |
| 6 | |
| 7 #include <boost/algorithm/string.hpp> | |
| 8 | |
| 9 #include "int_util.h" | |
| 10 | |
| 11 // macro to check if read mapped | |
| 12 #define READ_UNMAPPED 4 | |
| 13 | |
| 14 /** | |
| 15 * Splits alignment into separate parts | |
| 16 */ | |
| 17 std::vector<std::string> split_alignment(std::string &alignment) { | |
| 18 std::vector<std::string> parts; | |
| 19 | |
| 20 boost::trim_if(alignment, boost::is_any_of("\t ")); | |
| 21 // split on tab delimeter | |
| 22 boost::split(parts, alignment, boost::is_any_of("\t "), boost::token_compress_on); | |
| 23 | |
| 24 return parts; | |
| 25 } | |
| 26 | |
| 27 /** | |
| 28 * Validates bit flag | |
| 29 */ | |
| 30 bool is_good_flag(const int &bit_flag) { | |
| 31 if( (bit_flag & READ_UNMAPPED) > 0) return false; | |
| 32 return true; | |
| 33 } | |
| 34 | |
| 35 /** | |
| 36 * Validates rname | |
| 37 */ | |
| 38 bool is_good_rname(const std::string &rname) { | |
| 39 return rname.compare("*") != 0; | |
| 40 } | |
| 41 | |
| 42 /** | |
| 43 * Validates pos | |
| 44 */ | |
| 45 bool is_good_pos(const int &pos) { | |
| 46 return pos > 0; | |
| 47 } | |
| 48 | |
| 49 /** | |
| 50 * Validates cigar | |
| 51 */ | |
| 52 bool is_good_cigar(const std::string &cigar) { | |
| 53 return cigar.compare("*") != 0; | |
| 54 } | |
| 55 | |
| 56 /** | |
| 57 * Validates seq | |
| 58 */ | |
| 59 bool is_good_seq(const std::string &seq) { | |
| 60 return seq.compare("*") != 0; | |
| 61 } | |
| 62 | |
| 63 /** | |
| 64 * Validates alignment fields | |
| 65 */ | |
| 66 bool fields_are_good(std::vector<std::string> &parts) { | |
| 67 int bit_flag = s_to_i(parts[1]); | |
| 68 int pos = s_to_i(parts[3]); | |
| 69 | |
| 70 std::string rname = parts[2]; | |
| 71 std::string cigar = parts[5]; | |
| 72 std::string seq = parts[9]; | |
| 73 | |
| 74 if(!(is_good_flag(bit_flag))) return false; | |
| 75 if(!(is_good_pos(pos))) return false; | |
| 76 if(!(is_good_rname(rname))) return false; | |
| 77 if(!(is_good_cigar(cigar))) return false; | |
| 78 if(!(is_good_seq(seq))) return false; | |
| 79 | |
| 80 return true; | |
| 81 } | |
| 82 | |
| 83 /** | |
| 84 * Stores alignments that pass validity checks | |
| 85 */ | |
| 86 bool is_good_alignment(std::string &alignment) { | |
| 87 std::vector<std::string> alignment_parts; | |
| 88 | |
| 89 alignment_parts = split_alignment(alignment); | |
| 90 | |
| 91 if(!(fields_are_good(alignment_parts))) | |
| 92 return false; | |
| 93 return true; | |
| 94 } | |
| 95 | |
| 96 #endif /* ALIGNMENT_UTIL_H */ |
