File: OutputUnmappedFilter.hpp

package info (click to toggle)
salmon 1.10.3%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,148 kB
  • sloc: cpp: 200,707; ansic: 171,082; sh: 859; python: 792; makefile: 238
file content (45 lines) | stat: -rw-r--r-- 1,279 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef __OUTPUT_UNMAPPED_FILTER_HPP__
#define __OUTPUT_UNMAPPED_FILTER_HPP__

#include "ReadPair.hpp"
#include "UnpairedRead.hpp"
#include <iostream>
#include <oneapi/tbb/concurrent_queue.h>

template <typename FragT> class OutputUnmappedFilter {
public:
  OutputUnmappedFilter(oneapi::tbb::concurrent_bounded_queue<FragT*>* outQueue)
      : outQueue_(outQueue), qlen_(0) {
    memset(&qname_[0], 0, 255);
  }

  inline void processFrag(FragT* f) {
    bool distinctRead{true};

    // Check if the new read name is distinct from
    // the previous one.
    auto newLen = f->getNameLength();
    if (qlen_ == newLen) {
      distinctRead = (memcmp(&qname_[0], f->getName(), qlen_) != 0);
    }

    // If this doesn't have the same name as the last read we saw,
    // than pass it to the output queue and update the name of the
    // most recently observed read.
    if (distinctRead) {
      auto* alnCpy = f->clone();
      outQueue_->push(alnCpy);
      qlen_ = newLen;
      memcpy(&qname_[0], f->getName(), qlen_);
    }
    // If it does have the same name as the last read, no need
    // to update.
  }

private:
  oneapi::tbb::concurrent_bounded_queue<FragT*>* outQueue_ = nullptr;
  char qname_[255];
  uint32_t qlen_;
};

#endif // __OUTPUT_UNMAPPED_FILTER_HPP__