Changeset 3160


Ignore:
Timestamp:
Jan 13, 2014, 8:08:30 AM (8 years ago)
Author:
Peter
Message:

closes #775

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/bam.cc

    r3055 r3160  
    11// $Id$
    22//
    3 // Copyright (C) 2013 Peter Johansson
     3// Copyright (C) 2013, 2014 Peter Johansson
    44//
    55// This program is free software; you can redistribute it and/or modify
     
    192192
    193193
     194void test_open3(test::Suite& suite, const BamHeader& header)
     195{
     196  OutBamFile out("yaya.bam", header, 0);
     197  out.close();
     198  out.open("yaya.bam", header, 9);
     199  out.close();
     200  try {
     201    out.open("yaya.bam", header, 10);
     202    suite.add(false);
     203    suite.err() << "open(\"yaya.bam\", header, 10): did not throw\n";
     204  }
     205  catch (std::invalid_argument& e) {
     206    suite.err() << "expected exception: " << e.what() << "\n";
     207  }
     208  out.close();
     209}
     210
     211
    194212void test1(test::Suite& suite)
    195213{
     
    239257  test_sequence(suite, bam);
    240258  test_name(suite, bam);
    241 }
    242 #endif
     259  test_open3(suite, in.header());
     260}
     261#endif
  • trunk/yat/omic/BamFile.cc

    r3080 r3160  
    22
    33/*
    4   Copyright (C) 2012, 2013 Peter Johansson
     4  Copyright (C) 2012, 2013, 2014 Peter Johansson
    55
    66  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    132132
    133133
     134  OutBamFile::OutBamFile(const std::string& fn, const BamHeader& header,
     135                         unsigned int c)
     136  {
     137    open(fn, header, c);
     138  }
     139
     140
    134141  void OutBamFile::open(const std::string& fn, const BamHeader& h)
    135142  {
    136143    open_base(fn, "wb", h.header_);
     144  }
     145
     146
     147  void OutBamFile::open(const std::string& fn, const BamHeader& h,
     148                        unsigned int compression)
     149  {
     150    std::string mode("wb");
     151    if (compression > 9) {
     152      std::stringstream oss;
     153      oss << "OutBamFile::open( " << fn << ", <header>, " << compression
     154          << "): incorrect compression level\n";
     155      throw std::invalid_argument(oss.str());
     156    }
     157    mode.push_back('0'+compression);
     158    open_base(fn, mode, h.header_);
    137159  }
    138160
  • trunk/yat/omic/BamFile.h

    r3078 r3160  
    55
    66/*
    7   Copyright (C) 2012, 2013 Peter Johansson
     7  Copyright (C) 2012, 2013, 2014 Peter Johansson
    88
    99  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    193193
    194194    /**
     195       \brief Create an output bam file.
     196
     197       Equivalent to default constructor followed by a call to open(3).
     198
     199       \see open(const std::string&, const BamHeader&, unsigned int)
     200
     201       \since yat 0.12
     202     */
     203    OutBamFile(const std::string&, const BamHeader& header,
     204               unsigned int compression);
     205
     206    /**
    195207       \brief Open an output bam file.
    196208
     
    202214     */
    203215    void open(const std::string& fn, const BamHeader& hdr);
     216
     217    /**
     218       \brief Open an output bam file.
     219
     220       Opens an output bam file and writes the header contained in \a
     221       hdr. If \a fn is "-", \c stdout is used.
     222
     223       \param fn string specifying the filename
     224       \param hdr header
     225       \param compression a number [0,9] indicating level of
     226       compression. 9 gives highest compression and 0 indicates no
     227       compression (suitable for piping between applications)
     228
     229       \since yat 0.12
     230     */
     231    void open(const std::string& fn, const BamHeader& hdr,
     232              unsigned int compression);
    204233
    205234    /**
Note: See TracChangeset for help on using the changeset viewer.