MCPcopy Create free account
hub / github.com/arq5x/bedtools2 / GetFreqDesc

Method GetFreqDesc

src/utils/VectorOps/VectorOps.cpp:295–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293}
294
295string VectorOps::GetFreqDesc(void)
296{
297 // compute the frequency of each unique value
298 map<string, int> freqs;
299 vector<string>::const_iterator dIt = _vecs.begin();
300 vector<string>::const_iterator dEnd = _vecs.end();
301 for (; dIt != dEnd; ++dIt) {
302 freqs[*dIt]++;
303 }
304 // pair for the num times a values was
305 // observed (1) and the value itself (2)
306 pair<int, string> freqPair;
307 vector< pair<int, string> > freqList;
308
309 // create a list of pairs of all the observed values (second)
310 // and their occurences (first)
311 map<string,int>::const_iterator mapIter = freqs.begin();
312 map<string,int>::const_iterator mapEnd = freqs.end();
313 for(; mapIter != mapEnd; ++mapIter)
314 freqList.push_back( make_pair(mapIter->second, mapIter->first) );
315
316 // sort the list of pairs in the requested order by the frequency
317 // this will make the value that was observed least/most bubble to the top
318 sort(freqList.begin(), freqList.end(), ValueGreaterThan());
319
320 // record all of the values and their frequencies.
321 ostringstream buffer;
322 vector< pair<int, string> >::const_iterator iter = freqList.begin();
323 vector< pair<int, string> >::const_iterator iterEnd = freqList.end();
324 for (; iter != iterEnd; ++iter)
325 buffer << iter->second << ":" << iter->first << _delimStr;
326
327 return buffer.str();
328}
329
330
331string VectorOps::GetFreqAsc(void)

Callers

nothing calls this directly

Calls 5

ValueGreaterThanClass · 0.85
strMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected