Changeset 3410 for trunk/yat/omic/BamHeader.cc
- Timestamp:
- Apr 22, 2015, 1:05:43 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/omic/BamHeader.cc
r3409 r3410 25 25 26 26 #include "yat/utility/Exception.h" 27 #include "yat/utility/split.h" 27 28 28 29 // we need to include 'sam_header.h' when compiling against libbam … … 67 68 68 69 BamHeader::BamHeader(const BamHeader& other) 70 : read_group_(other.read_group_), program_group_(other.program_group_) 69 71 { 70 72 #ifndef YAT_HAVE_HTSLIB … … 72 74 #endif 73 75 header_ = bam_hdr_dup(other.header_); 76 } 77 78 79 const std::string& BamHeader::group(strMap2& table,const std::string& type, 80 const std::string& id, 81 const std::string& key) const 82 { 83 assert(type.size()==2); 84 if (table.empty()) { // parse header 85 std::istringstream ss(text()); 86 std::string line; 87 while (getline(ss, line)) { 88 if (line.substr(1,2)!=type) 89 continue; 90 // find ID value 91 size_t pos = line.find("\tID:", 3); 92 size_t end = line.find('\t', pos+4); 93 std::string id_val = line.substr(pos+4, end-(pos+4)); 94 std::vector<std::string> vec; 95 utility::split(vec, line, '\t'); 96 strMap& m = table[id_val]; 97 for (size_t i=1; i<vec.size(); ++i) { 98 m[vec[i].substr(0,2)] = vec[i].substr(3); 99 } 100 } 101 if (table.empty()) 102 table[""][""]; // to avoid re-parsing 103 } 104 return table[id][key]; 74 105 } 75 106 … … 105 136 106 137 138 const std::string& BamHeader::program_group(const std::string& id, 139 const std::string& key) const 140 { 141 return group(program_group_, "PG", id, key); 142 } 143 144 145 const std::string& BamHeader::read_group(const std::string& id, 146 const std::string& key) const 147 { 148 return group(read_group_, "RG", id, key); 149 } 150 151 107 152 void BamHeader::swap(BamHeader& other) 108 153 { 109 154 std::swap(header_, other.header_); 155 std::swap(read_group_, other.read_group_); 156 std::swap(program_group_, other.program_group_); 110 157 } 111 158 … … 134 181 void BamHeader::text(const std::string& txt) 135 182 { 183 read_group_.clear(); 184 program_group_.clear(); 136 185 #ifdef YAT_HAVE_HTSLIB 137 186 // destroy the old
Note: See TracChangeset
for help on using the changeset viewer.