Commit 9ca20e7e authored by Li's avatar Li Committed by Haowen Zhang
Browse files

Fix a bug with the bit operation

parent 851d1a25
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ class BarcodeTranslator
private:
  khash_t(k64_str) *barcode_translate_table;
  int from_bc_length;
  uint64_t mask;

  std::string Seed2Sequence(uint64_t seed, uint32_t seed_length) const {
    std::string sequence;
@@ -91,10 +92,15 @@ public:
    barcode_translate_table = kh_init(k64_str);
    std::ifstream file_stream(file);
    std::string file_line;

    while (getline(file_stream, file_line)) {
      ProcessTranslateFileLine(file_line); 
    }
    
    mask = 0;
    for (int i = 0; i < from_bc_length; ++i)
    {
      mask |= (3ull << (2*i));
    }
  }
  
  std::string Translate(uint64_t bc, uint32_t bc_length) {
@@ -105,7 +111,8 @@ public:
    std::string ret;  
    uint64_t i;
    for (i = 0; i < bc_length / from_bc_length; ++i) {
      uint64_t seed = (bc << (i * from_bc_length)) >> (bc_length - from_bc_length);
      uint64_t seed = (bc << (2 * i * from_bc_length)) >> (2 * (bc_length / from_bc_length - 1) * from_bc_length);
      seed &= mask;
      khiter_t barcode_translate_table_iter = kh_get(k64_str, barcode_translate_table, seed);
      if (barcode_translate_table_iter == kh_end(barcode_translate_table)) {
        std::cerr << "Barcode does not exist in the translation table.\n" << std::endl;