Changeset 3477
- Timestamp:
- Mar 9, 2016, 9:26:38 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/bam_header.cc
r3412 r3477 133 133 } 134 134 135 typedef BamHeader::read_group_iterator iterator; 136 iterator it = hdr.read_group_begin(); 137 if (it == hdr.read_group_end()) { 138 suite.add(false); 139 suite.err() << "it == hdr.read_group_end()\n"; 140 } 141 else { 142 if (!suite.add(*it == "foo")) 143 suite.err() << "*it != foo\n"; 144 std::map<std::string, std::string> m = hdr.read_group(*it); 145 std::string val = m["SM"]; 146 if (!suite.add(val == "Tumour")) 147 suite.err() << "incorrect val: " << val << " expected Tumour\n"; 148 val = m["PL"]; 149 if (!suite.add(val == "ILLUMINA")) 150 suite.err() << "incorrect val: " << val << " expected ILLUMINA\n"; 151 } 152 135 153 std::string bwa_version = hdr.program_group("bwa", "VN"); 136 154 if (bwa_version!="0.6.1-r104") { -
trunk/yat/omic/BamHeader.cc
r3423 r3477 81 81 const std::string& id, 82 82 const std::string& key) const 83 { 84 update_group(table, type); 85 strMap2::const_iterator line_table = table.find(id); 86 if (line_table == table.end()) { 87 std::string msg = "@" + type + ": unknown ID: '" + id + "'"; 88 throw utility::runtime_error(msg); 89 } 90 strMap::const_iterator it = line_table->second.find(key); 91 if (it == line_table->second.end()) { 92 std::string msg = "@" + type + ": unknown KEY: '" + key + "'"; 93 throw utility::runtime_error(msg); 94 } 95 return it->second; 96 } 97 98 99 void BamHeader::update_group(strMap2& table, const std::string& type) const 83 100 { 84 101 assert(type.size()==2); … … 101 118 } 102 119 } 103 strMap2::const_iterator line_table = table.find(id);104 if (line_table == table.end()) {105 std::string msg = "@" + type + ": unknown ID: '" + id + "'";106 throw utility::runtime_error(msg);107 }108 strMap::const_iterator it = line_table->second.find(key);109 if (it == line_table->second.end()) {110 std::string msg = "@" + type + ": unknown KEY: '" + key + "'";111 throw utility::runtime_error(msg);112 }113 return it->second;114 120 } 115 121 … … 156 162 { 157 163 return group(read_group_, "RG", id, key); 164 } 165 166 167 const std::map<std::string, std::string>& 168 BamHeader::read_group(const std::string& id) const 169 { 170 update_group(read_group_, "RG"); 171 strMap2::const_iterator line_table = read_group_.find(id); 172 if (line_table == read_group_.end()) { 173 std::string msg = "@RG: unknown ID: '" + id + "'"; 174 throw utility::runtime_error(msg); 175 } 176 return line_table->second; 177 } 178 179 180 BamHeader::read_group_iterator BamHeader::read_group_begin(void) const 181 { 182 update_group(read_group_, "RG"); 183 BamHeader::strMap2::const_iterator it(read_group_.begin()); 184 return utility::pair_first_iterator(it); 185 } 186 187 188 BamHeader::read_group_iterator BamHeader::read_group_end(void) const 189 { 190 update_group(read_group_, "RG"); 191 BamHeader::strMap2::const_iterator it(read_group_.end()); 192 return utility::pair_first_iterator(it); 158 193 } 159 194 -
trunk/yat/omic/BamHeader.h
r3417 r3477 27 27 #include "yat/utility/config_public.h" 28 28 29 #include "yat/utility/stl_utility.h" 30 29 31 #include YAT_SAM_HEADER 32 33 #include <boost/iterator/transform_iterator.hpp> 30 34 31 35 #include <map> … … 56 60 class BamHeader 57 61 { 62 typedef std::map<std::string, std::string> strMap; 63 typedef std::map<std::string, strMap> strMap2; 58 64 public: 59 65 /** … … 112 118 and for this line \c read_group("foo", "SM") returns \c "Tumour" 113 119 120 To see which IDs are available in the header, iterate through 121 the set of IDs with read_group_begin() (and read_group_end()). 122 114 123 \return value for \a key for line with ID \a id. 115 124 116 125 \since New in yat 0.13 117 126 */ 118 //119 127 const std::string& read_group(const std::string& id, 120 128 const std::string& key) const; 129 130 /** 131 \returns a map describing an \@RG line such as 132 133 \code @RG ID:foo PL:ILLUMINA SM:Tumour \endcode 134 135 for which the returned map contains two entries: one with key 136 \c PL and value \c ILLUMINA, and one with key \c SM and value 137 \c Tumour. 138 139 \since New in yat 0.14 140 */ 141 const std::map<std::string, std::string>& 142 read_group(const std::string& id) const; 143 144 /** 145 read_group_iterator is used to iterate through read groups 146 147 \see read_group_begin 148 \see read_group_end 149 150 \since New in yat 0.14 151 */ 152 typedef boost::transform_iterator< 153 utility::PairFirst<const strMap2::value_type>, 154 strMap2::const_iterator> 155 read_group_iterator; 156 157 /** 158 \return first of available RG IDs 159 160 \since New in yat 0.14 161 */ 162 read_group_iterator read_group_begin(void) const; 163 164 /** 165 \return end of range of available RG IDs 166 167 \see read_group_begin() 168 169 \since New in yat 0.14 170 */ 171 read_group_iterator read_group_end(void) const; 121 172 122 173 /** … … 179 230 #endif 180 231 bam_hdr_t* header_; 181 typedef std::map<std::string, std::string> strMap;182 typedef std::map<std::string, strMap> strMap2;183 232 mutable strMap2 read_group_; 184 233 mutable strMap2 program_group_; … … 191 240 const std::string& key) const; 192 241 242 void update_group(strMap2& map, const std::string& type) const; 243 193 244 // using compiler generated copy and assignment 194 245 };
Note: See TracChangeset
for help on using the changeset viewer.