libStatGen Software  1
SamReferenceInfo.h
1 /*
2  * Copyright (C) 2010 Regents of the University of Michigan
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __SAM_REFERENCE_INFO_H__
19 #define __SAM_REFERENCE_INFO_H__
20 
21 #include "StringArray.h"
22 #include "StringHash.h"
23 #include "IntArray.h"
24 
25 /// Class for tracking the reference information mapping between the
26 /// reference ids and the reference names.
28 {
29 public:
30  /// Constructor.
32  /// Destructor.
34  /// Add reference sequence name and reference sequence length.
35  void add(const char* referenceSequenceName,
36  int32_t referenceSequenceLength);
37 
38  /// Get the reference ID for the specified name, if addID is set to true,
39  /// a reference id will be created for the referenceName if one does not
40  /// already exist, while if addID is set to false (default), it will return
41  /// NO_REF_ID if the reference name does not exist.
42  int getReferenceID(const String & referenceName, bool addID = false);
43  /// Get the reference ID for the specified name, if addID is set to true,
44  /// a reference id will be created for the referenceName if one does not
45  /// already exist, while if addID is set to false (default), it will return
46  /// NO_REF_ID if the reference name does not exist.
47  int getReferenceID(const char* referenceName, bool addID = false);
48  /// Get the reference name for the specified id, if the id is not found,
49  /// return "*".
50  const String & getReferenceLabel(int id) const;
51 
52  /// Get the number of entries contained here.
53  int32_t getNumEntries() const;
54 
55  /// Return the reference name at the specified index, returning "" if the
56  /// index is out of bounds.
57  const char* getReferenceName(int index) const;
58 
59  /// Return the reference length at the specified index, returning 0 if the
60  /// index is out of bounds.
61  int32_t getReferenceLength(int index) const;
62 
63  /// Reset this reference info.
64  void clear();
65 
66  /// Copy the reference information.
68 
69  bool operator== (const SamReferenceInfo& rhs) const;
70  bool operator!= (const SamReferenceInfo& rhs) const
71  {
72  return(!operator==(rhs));
73  }
74 
75  /// Constant for the value returned if a reference id does not exist
76  /// for a queried reference name.
77  static const int NO_REF_ID = -3;
78 
79 private:
80  // Reference Name information
81  StringArray myReferenceContigs;
82  StringIntHash myReferenceHash;
83  IntArray myReferenceLengths;
84 };
85 
86 #endif
87 
int32_t getReferenceLength(int index) const
Return the reference length at the specified index, returning 0 if the index is out of bounds...
static const int NO_REF_ID
Constant for the value returned if a reference id does not exist for a queried reference name...
void clear()
Reset this reference info.
void add(const char *referenceSequenceName, int32_t referenceSequenceLength)
Add reference sequence name and reference sequence length.
SamReferenceInfo & operator=(const SamReferenceInfo &rhs)
Copy the reference information.
~SamReferenceInfo()
Destructor.
int getReferenceID(const String &referenceName, bool addID=false)
Get the reference ID for the specified name, if addID is set to true, a reference id will be created ...
SamReferenceInfo()
Constructor.
Class for tracking the reference information mapping between the reference ids and the reference name...
const String & getReferenceLabel(int id) const
Get the reference name for the specified id, if the id is not found, return "*".
int32_t getNumEntries() const
Get the number of entries contained here.
const char * getReferenceName(int index) const
Return the reference name at the specified index, returning "" if the index is out of bounds...