Changeset 4290
- Timestamp:
- Feb 3, 2023, 4:17:58 PM (4 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/bam_header.cc
r4264 r4290 23 23 #include "yat/omic/BamFile.h" 24 24 #include "yat/omic/BamHeader.h" 25 #include <set> 25 26 #endif 27 26 28 27 29 using namespace theplu::yat; … … 172 174 int32_t n_chr = hdr.n_targets(); 173 175 174 // check that we can add another chromosome via a @SG field176 // check that we can add another chromosome via a @SG field 175 177 std::stringstream ss(hdr.text()); 176 178 std::string str3; … … 253 255 suite.out() << "expected exception with what(): " << e.what() << "\n"; 254 256 } 257 258 259 std::set<std::string> 260 programs(hdr.program_group_begin(), hdr.program_group_end()); 261 for (const auto& prog : programs) 262 suite.out() << prog << "\n"; 263 if (!programs.count("bwa") || !programs.count("samtools") || 264 programs.size()!=3) { 265 suite.add(false); 266 suite.err() << "incorrect programs\n"; 267 } 268 hdr.program_group("bwa"); 255 269 } 256 270 #endif -
trunk/yat/omic/BamHeader.cc
r4265 r4290 67 67 68 68 69 const std::map<std::string, std::string>& 70 BamHeader::group(strMap2& map, const std::string& type, 71 const std::string& id) const 72 { 73 update_group(map, type); 74 strMap2::const_iterator line_table = map.find(id); 75 if (line_table == map.end()) { 76 std::string msg = "@" + type + ": unknown ID: '" + id + "'"; 77 throw utility::runtime_error(msg); 78 } 79 return line_table->second; 80 } 81 82 83 BamHeader::read_group_iterator 84 BamHeader::group_begin(strMap2& group, const std::string& type) const 85 { 86 update_group(group, type); 87 BamHeader::strMap2::const_iterator it(group.begin()); 88 return utility::pair_first_iterator(it); 89 } 90 91 92 BamHeader::read_group_iterator 93 BamHeader::group_end(strMap2& group, const std::string& type) const 94 { 95 update_group(group, type); 96 BamHeader::strMap2::const_iterator it(group.end()); 97 return utility::pair_first_iterator(it); 98 } 99 100 69 101 const std::string& BamHeader::group(strMap2& table,const std::string& type, 70 102 const std::string& id, 71 103 const std::string& key) const 72 104 { 73 update_group(table, type); 74 strMap2::const_iterator line_table = table.find(id); 75 if (line_table == table.end()) { 76 std::string msg = "@" + type + ": unknown ID: '" + id + "'"; 77 throw utility::runtime_error(msg); 78 } 79 strMap::const_iterator it = line_table->second.find(key); 80 if (it == line_table->second.end()) { 105 const std::map<std::string, std::string>& m = group(table, type, id); 106 strMap::const_iterator it = m.find(key); 107 if (it == m.end()) { 81 108 std::string msg = "@" + type + ": unknown KEY: '" + key + "'"; 82 109 throw utility::runtime_error(msg); … … 142 169 143 170 171 const std::map<std::string, std::string>& 172 BamHeader::program_group(const std::string& id) const 173 { 174 return group(program_group_, "PG", id); 175 } 176 177 178 BamHeader::program_group_iterator BamHeader::program_group_begin(void) const 179 { 180 return group_begin(program_group_, "PG"); 181 } 182 183 184 BamHeader::program_group_iterator BamHeader::program_group_end(void) const 185 { 186 return group_end(program_group_, "PG"); 187 } 188 189 144 190 const std::string& BamHeader::read_group(const std::string& id, 145 191 const std::string& key) const … … 152 198 BamHeader::read_group(const std::string& id) const 153 199 { 154 update_group(read_group_, "RG"); 155 strMap2::const_iterator line_table = read_group_.find(id); 156 if (line_table == read_group_.end()) { 157 std::string msg = "@RG: unknown ID: '" + id + "'"; 158 throw utility::runtime_error(msg); 159 } 160 return line_table->second; 200 return group(read_group_, "RG", id); 161 201 } 162 202 … … 164 204 BamHeader::read_group_iterator BamHeader::read_group_begin(void) const 165 205 { 166 update_group(read_group_, "RG"); 167 BamHeader::strMap2::const_iterator it(read_group_.begin()); 168 return utility::pair_first_iterator(it); 206 return group_begin(read_group_, "RG"); 169 207 } 170 208 … … 172 210 BamHeader::read_group_iterator BamHeader::read_group_end(void) const 173 211 { 174 update_group(read_group_, "RG"); 175 BamHeader::strMap2::const_iterator it(read_group_.end()); 176 return utility::pair_first_iterator(it); 212 return group_end(read_group_, "RG"); 177 213 } 178 214 -
trunk/yat/omic/BamHeader.h
r4272 r4290 106 106 107 107 /** 108 \returns a map describing an \@PG line such as 109 110 \code @PG ID:bwa PN:bwa VN:0.6.1-r104 \endcode 111 112 for which the returned map contains two entries: one with key 113 \c PN and value \c bwa, and one with key \c VN and value 114 \c 0.6.1-r104. 115 116 \since New in yat 0.21 117 */ 118 const std::map<std::string, std::string>& 119 program_group(const std::string& id) const; 120 121 /** 122 program_group_iterator is used to iterate through program groups 123 124 program_group_iterator is a \readable_iterator and 125 \bidirectional_traversal_iterator with value type \c 126 std::string 127 128 \see program_group_begin 129 \see program_group_end 130 131 \since New in yat 0.21 132 */ 133 typedef boost::transform_iterator< 134 utility::PairFirst<const strMap2::value_type>, 135 strMap2::const_iterator> 136 program_group_iterator; 137 138 /** 139 \return first of available PG IDs 140 141 \since New in yat 0.21 142 */ 143 program_group_iterator program_group_begin(void) const; 144 145 /** 146 \return end of range of available PG IDs 147 148 \see program_group_begin() 149 150 \since New in yat 0.21 151 */ 152 program_group_iterator program_group_end(void) const; 153 154 /** 108 155 \brief Access value in \c \@RG lines. 109 156 … … 240 287 friend class OutBamFile; 241 288 289 const std::map<std::string, std::string>& 290 group(strMap2&, const std::string& type, 291 const std::string& id) const; 292 293 read_group_iterator 294 group_begin(strMap2&, const std::string& type) const; 295 296 read_group_iterator 297 group_end(strMap2&, const std::string& type) const; 298 242 299 const std::string& group(strMap2& map, const std::string& type, 243 300 const std::string& id,
Note: See TracChangeset
for help on using the changeset viewer.