Changeset 3398


Ignore:
Timestamp:
Mar 25, 2015, 8:57:32 AM (8 years ago)
Author:
Peter
Message:

refs #794

Global arrays bam_nt16_stable and bam_nt16_rev_table in libbam have in
htslib changed name to seq_nt16_table and seq_nt16_str.

Introduce two functions that allow access to these arrays in a uniform
way regardless whether we are working against libbam or htslib.

Location:
trunk/yat/omic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/omic/BamRead.cc

    r3395 r3398  
    228228  {
    229229    int offset = 4*c.size() - 4*core().n_cigar;
    230    
     230
    231231    reserve(data_size() + offset);
    232232    /*
     
    348348  char BamRead::sequence_str(size_t i) const
    349349  {
    350 #if YAT_HAVE_HTSLIB
    351     return seq_nt16_str[sequence(i)];
    352 #elif HAVE_BAM_NT16_REV_TABLE
    353     return bam_nt16_rev_table[sequence(i)];
    354 #else
    355     std::string table = "=ACMGRSVTWYHKDBN";
    356     return table[sequence(i)];
    357 #endif
     350    return nt16_str(sequence(i));
    358351  }
    359352
     
    374367    // copy sequence
    375368    for (size_t i=0; i<seq.size(); ++i)
    376 #if YAT_HAVE_HTSLIB
    377       sequence(i, seq_nt16_table[static_cast<size_t>(seq[i])]);
    378 #else
    379       sequence(i, bam_nt16_table[static_cast<size_t>(seq[i])]);
    380 #endif
     369      sequence(i, nt16_table(seq[i]));
    381370    core().l_qseq = seq.size();
    382371    // copy quality
     
    442431  {
    443432    std::swap(bam_, other.bam_);
     433  }
     434
     435
     436  const unsigned char nt16_table(char c)
     437  {
     438#if YAT_HAVE_HTSLIB
     439    return seq_nt16_table[static_cast<uint8_t>(c)];
     440#else
     441    return bam_nt16_table[static_cast<uint8_t>(c)];
     442#endif
     443  }
     444
     445
     446  const char nt16_str(uint8_t x)
     447  {
     448    assert(x<16);
     449#if YAT_HAVE_HTSLIB
     450    return seq_nt16_str[x];
     451#elif HAVE_BAM_NT16_REV_TABLE
     452    return bam_nt16_rev_table[x];
     453#else
     454    char table[16] = "=ACMGRSVTWYHKDBN";
     455    return table[x];
     456#endif
    444457  }
    445458
  • trunk/yat/omic/BamRead.h

    r3395 r3398  
    325325    const int& data_size(void) const;
    326326  };
     327
     328  /**
     329     Convert nucleotide character to 4-bit encoding.  The result is
     330     encoded as 1/2/4/8 for A/C/G/T or combinations of these bits.
     331
     332     This is the same functionality that is provided in HTSLIB's
     333     global array \c seq_nt16_table, but this function works also when
     334     building against libbam. In libbam the array was called \c
     335     bam_nt16_table.
     336
     337     This is the inverse of function nt16_str.
     338
     339     \since New in yat 0.13
     340  */
     341  const unsigned char nt16_table(char);
     342
     343  /**
     344     Convert a 4-bit encoded nucleotide to a character.
     345
     346     This is the same functionality that is provided in HTSLIB's
     347     global array seq_nt16_str, but this function works also when
     348     building against libbam. In libbam the array was called \c
     349     bam_nt16_rev_table.
     350
     351     This is the inverse of function nt16_table.
     352
     353     \since New in yat 0.13
     354  */
     355  const char nt16_str(uint8_t);
    327356
    328357  /**
Note: See TracChangeset for help on using the changeset viewer.