NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
output_file.cpp
Go to the documentation of this file.
1 /*
2  * nvbio
3  * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
32 
33 namespace nvbio {
34 namespace io {
35 
36 OutputFile::OutputFile(const char *_file_name, AlignmentType _alignment_type, BNT _bnt)
37  : file_name(_file_name),
38  alignment_type(_alignment_type),
39  bnt(_bnt),
40  mapq_filter(-1)
41 {
42 }
43 
45 {
46 }
47 
49 {
51 }
52 
54 {
55 }
56 
58 {
59  return iostats;
60 }
61 
62 OutputFile *OutputFile::open(const char *file_name, AlignmentType aln_type, BNT bnt)
63 {
64  // parse out file extension; look for .sam, .bam suffixes
65  uint32 len = uint32(strlen(file_name));
66 
67  if (strcmp(file_name, "/dev/null") == 0)
68  {
69  return new OutputFile(file_name, aln_type, bnt);
70  }
71 
72  if (len >= strlen(".sam"))
73  {
74  if (strcmp(&file_name[len - strlen(".sam")], ".sam") == 0)
75  {
76  return new SamOutput(file_name, aln_type, bnt);
77  }
78  }
79 
80  if (len >= strlen(".bam"))
81  {
82  if (strcmp(&file_name[len - strlen(".bam")], ".bam") == 0)
83  {
84  return new BamOutput(file_name, aln_type, bnt);
85  }
86  }
87 
88  if (len >= strlen(".dbg"))
89  {
90  if (strcmp(&file_name[len - strlen(".dbg")], ".dbg") == 0)
91  {
92  return new DebugOutput(file_name, aln_type, bnt);
93  }
94  }
95 
96  log_warning(stderr, "could not determine file type for %s; guessing SAM\n", file_name);
97  return new SamOutput(file_name, aln_type, bnt);
98 }
99 
100 } // namespace io
101 } // namespace nvbio