]> git.donarmstrong.com Git - bamtools.git/blob - src/api/SamHeader.cpp
Added explicit copy ctors to SamHeader data structures
[bamtools.git] / src / api / SamHeader.cpp
1 // ***************************************************************************
2 // SamHeader.cpp (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 23 December 2010 (DB)
7 // ---------------------------------------------------------------------------
8 // Provides functionality for querying/manipulating SAM header data
9 // **************************************************************************
10
11 #include <api/SamHeader.h>
12 #include <api/internal/SamFormatParser_p.h>
13 #include <api/internal/SamFormatPrinter_p.h>
14 #include <api/internal/SamHeaderValidator_p.h>
15 using namespace BamTools;
16 using namespace BamTools::Internal;
17 using namespace std;
18
19 // ctor
20 SamHeader::SamHeader(const string& headerText)
21     : Version("")
22     , SortOrder("")
23     , GroupOrder("")
24     , ProgramName("")
25     , ProgramVersion("")
26     , ProgramCommandLine("")
27 {
28     SamFormatParser parser(*this);
29     parser.Parse(headerText);
30 }
31
32 // copy ctor
33 SamHeader::SamHeader(const SamHeader& other)
34     : Version(other.Version)
35     , SortOrder(other.SortOrder)
36     , GroupOrder(other.GroupOrder)
37     , Sequences(other.Sequences)
38     , ReadGroups(other.ReadGroups)
39     , ProgramName(other.ProgramName)
40     , ProgramVersion(other.ProgramVersion)
41     , ProgramCommandLine(other.ProgramCommandLine)
42 { }
43
44 // dtor
45 SamHeader::~SamHeader(void) {
46     Clear();
47 }
48
49 void SamHeader::Clear(void) {
50     Version.clear();
51     SortOrder.clear();
52     GroupOrder.clear();
53     Sequences.Clear();
54     ReadGroups.Clear();
55     ProgramName.clear();
56     ProgramVersion.clear();
57     ProgramCommandLine.clear();
58     Comments.clear();
59 }
60
61 // retrieve the SAM header, with any local modifications
62 string SamHeader::ToString(void) const {
63     SamFormatPrinter printer(*this);
64     return printer.ToString();
65 }
66
67 // query if header contains @HD ID:<Version>
68 bool SamHeader::HasVersion(void) const {
69     return (!Version.empty());
70 }
71
72 // query if header contains @HD SO:<SortOrder>
73 bool SamHeader::HasSortOrder(void) const {
74     return (!SortOrder.empty());
75 }
76
77 // query if header contains @HD GO:<GroupOrder>
78 bool SamHeader::HasGroupOrder(void) const {
79     return (!GroupOrder.empty());
80 }
81
82 // query if header contains @SQ entries
83 bool SamHeader::HasSequences(void) const {
84     return (!Sequences.IsEmpty());
85 }
86
87 // query if header contains @RG entries
88 bool SamHeader::HasReadGroups(void) const {
89     return (!ReadGroups.IsEmpty());
90 }
91
92 // query if header contains @PG ID:<ProgramName>
93 bool SamHeader::HasProgramName(void) const {
94     return (!ProgramName.empty());
95 }
96
97 // query if header contains @HD VN:<ProgramVersion>
98 bool SamHeader::HasProgramVersion(void) const {
99     return (!ProgramVersion.empty());
100 }
101
102 // query if header contains @HD CL:<ProgramCommandLine>
103 bool SamHeader::HasProgramCommandLine(void) const {
104     return (!ProgramCommandLine.empty());
105 }
106
107 // query if header contains @CO entries
108 bool SamHeader::HasComments(void) const {
109     return (!Comments.empty());
110 }
111
112 // validation
113 bool SamHeader::IsValid(bool verbose) const {
114     SamHeaderValidator validator(*this);
115     return validator.Validate(verbose);
116 }