1 /*
2  *  Copyright (C) 2010-2012  Regents of the University of Michigan,
3  *                           Hyun Min Kang, Matthew Flickenger, Matthew Snyder,
4  *                           and Goncalo Abecasis
5  *
6  *   This program is free software: you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation, either version 3 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "VcfFileWriter.h"
21 
VcfFileWriter()22 VcfFileWriter::VcfFileWriter()
23     : VcfFile()
24 {
25 }
26 
27 
~VcfFileWriter()28 VcfFileWriter::~VcfFileWriter()
29 {
30 }
31 
32 
open(const char * filename,VcfHeader & header,InputFile::ifileCompression compressionMode)33 bool VcfFileWriter::open(const char* filename, VcfHeader& header,
34                          InputFile::ifileCompression compressionMode)
35 {
36     myStatus = StatGenStatus::SUCCESS;
37     if(VcfFile::open(filename, "w", compressionMode))
38     {
39         // Successfully opened, so write the header.
40         if(!header.write(myFilePtr))
41         {
42             // Failed, so copy the status.
43             myStatus = header.getStatus();
44             return(false);
45         }
46     }
47     else
48     {
49         // Failed, status set by VcfFile::open.
50         return(false);
51     }
52 
53     // Successfully opened and read the header.
54     return(true);
55 }
56 
57 
open(const char * filename,VcfHeader & header)58 bool VcfFileWriter::open(const char* filename, VcfHeader& header)
59 {
60     return(open(filename, header, InputFile::BGZF));
61 }
62 
63 
writeRecord(VcfRecord & record)64 bool VcfFileWriter::writeRecord(VcfRecord& record)
65 {
66     if(!record.write(myFilePtr, mySiteOnly))
67     {
68         myStatus = record.getStatus();
69         return(false);
70     }
71     ++myNumRecords;
72     return(true);
73 }
74