Changeset 3409


Ignore:
Timestamp:
Apr 17, 2015, 3:07:04 AM (8 years ago)
Author:
Peter
Message:

refs #817. Fix bug that struct was not updated in text(1) function (in libbam mode); add test to catch bug.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/bam_header.cc

    r3408 r3409  
    11// $Id$
    22//
    3 // Copyright (C) 2013, 2014 Peter Johansson
     3// Copyright (C) 2013, 2014, 2015 Peter Johansson
    44//
    55// This program is free software; you can redistribute it and/or modify
     
    100100  }
    101101
     102  int32_t n_chr = hdr.n_targets();
     103
     104  // check that we can add another chromosomevia a @SG field
     105  std::stringstream ss(hdr.text());
     106  std::string str3;
     107  std::string line;
     108  int32_t n_targ = 0;
     109  while (getline(ss, line)) {
     110    str3 += line + "\n";
     111    if (line.substr(0,3) == "@SQ") {
     112      ++n_targ;
     113      if (n_targ == n_chr)
     114        str3 += "@SQ\tSN:Zbababababa\tLN:123\n";
     115    }
     116  }
     117  hdr.text(str3);
     118
     119  int32_t n = hdr.n_targets();
     120  if (n != n_chr+1) {
     121    suite.add(false);
     122    suite.err() << "error: incorrect number of targets: " << n
     123                << " expected " << (n_chr+1) << "\n";
     124    suite.err() << "header text:\n" << hdr.text() << "===\n";
     125  }
     126
    102127#endif
    103128}
  • trunk/yat/omic/BamHeader.cc

    r3408 r3409  
    2525
    2626#include "yat/utility/Exception.h"
     27
     28// we need to include 'sam_header.h' when compiling against libbam
     29#ifndef YAT_HAVE_HTSLIB
     30  #if YAT_HAVE_SAM_H
     31  #include <sam_header.h>
     32  #elif YAT_HAVE_BAM_BAM_H
     33  #include <bam/sam_header.h>
     34  #elif YAT_HAVE_SAMTOOLS_SAM_H
     35  #include <samtools/sam_header.h>
     36  #else
     37  #error cannot end up here
     38  #endif
     39#endif
    2740
    2841#include <cassert>
     
    118131  }
    119132
     133
    120134  void BamHeader::text(const std::string& txt)
    121135  {
     
    130144    memcpy(header_->text, txt.c_str(), txt.size()+1);
    131145#ifndef YAT_HAVE_HTSLIB
     146    // destroy dict to ensure that things are updated during parsing
     147    if (header_->dict) {
     148      sam_header_free(header_->dict);
     149      header_->dict = 0;
     150    }
    132151    sam_header_parse(header_);
    133152#endif
Note: See TracChangeset for help on using the changeset viewer.