libStatGen Software 1
SamReferenceInfo Class Reference

Class for tracking the reference information mapping between the reference ids and the reference names. More...

#include <SamReferenceInfo.h>

Public Member Functions

 SamReferenceInfo ()
 Constructor. More...
 
 ~SamReferenceInfo ()
 Destructor. More...
 
void add (const char *referenceSequenceName, int32_t referenceSequenceLength)
 Add reference sequence name and reference sequence length. More...
 
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 for the referenceName if one does not already exist, while if addID is set to false (default), it will return NO_REF_ID if the reference name does not exist. More...
 
int getReferenceID (const char *referenceName, bool addID=false)
 Get the reference ID for the specified name, if addID is set to true, a reference id will be created for the referenceName if one does not already exist, while if addID is set to false (default), it will return NO_REF_ID if the reference name does not exist. More...
 
const StringgetReferenceLabel (int id) const
 Get the reference name for the specified id, if the id is not found, return "*". More...
 
int32_t getNumEntries () const
 Get the number of entries contained here. More...
 
const char * getReferenceName (int index) const
 Return the reference name at the specified index, returning "" if the index is out of bounds. More...
 
int32_t getReferenceLength (int index) const
 Return the reference length at the specified index, returning 0 if the index is out of bounds. More...
 
void clear ()
 Reset this reference info. More...
 
SamReferenceInfooperator= (const SamReferenceInfo &rhs)
 Copy the reference information. More...
 
bool operator== (const SamReferenceInfo &rhs) const
 
bool operator!= (const SamReferenceInfo &rhs) const
 

Static Public Attributes

static const int NO_REF_ID = -3
 Constant for the value returned if a reference id does not exist for a queried reference name. More...
 

Detailed Description

Class for tracking the reference information mapping between the reference ids and the reference names.

Definition at line 27 of file SamReferenceInfo.h.

Constructor & Destructor Documentation

◆ SamReferenceInfo()

SamReferenceInfo::SamReferenceInfo ( )

Constructor.

Definition at line 20 of file SamReferenceInfo.cpp.

21 : myReferenceContigs(),
22 myReferenceHash(),
23 myReferenceLengths()
24{
25 clear();
26}
void clear()
Reset this reference info.

References clear().

◆ ~SamReferenceInfo()

SamReferenceInfo::~SamReferenceInfo ( )

Destructor.

Definition at line 29 of file SamReferenceInfo.cpp.

30{
31 clear();
32}

References clear().

Member Function Documentation

◆ add()

void SamReferenceInfo::add ( const char *  referenceSequenceName,
int32_t  referenceSequenceLength 
)

Add reference sequence name and reference sequence length.

Definition at line 35 of file SamReferenceInfo.cpp.

37{
38 myReferenceHash.Add(referenceSequenceName,
39 myReferenceContigs.Length());
40 myReferenceContigs.Push(referenceSequenceName);
41 myReferenceLengths.Push(referenceSequenceLength);
42}

Referenced by SamFileHeader::addSQ(), and SamFileHeader::setSQTag().

◆ clear()

void SamReferenceInfo::clear ( )

Reset this reference info.

Definition at line 123 of file SamReferenceInfo.cpp.

124{
125 myReferenceContigs.Clear();
126 myReferenceHash.Clear();
127 myReferenceLengths.Clear();
128}

Referenced by SamReferenceInfo(), ~SamReferenceInfo(), SamFileHeader::copy(), operator=(), and SamFileHeader::resetHeader().

◆ getNumEntries()

int32_t SamReferenceInfo::getNumEntries ( ) const

Get the number of entries contained here.

Definition at line 93 of file SamReferenceInfo.cpp.

94{
95 // The number of entries is the size of referenceLengths.
96 return(myReferenceLengths.Length());
97}

Referenced by getReferenceLength(), getReferenceName(), and SamValidator::isValidRefID().

◆ getReferenceID() [1/2]

int SamReferenceInfo::getReferenceID ( const char *  referenceName,
bool  addID = false 
)

Get the reference ID for the specified name, if addID is set to true, a reference id will be created for the referenceName if one does not already exist, while if addID is set to false (default), it will return NO_REF_ID if the reference name does not exist.

Definition at line 71 of file SamReferenceInfo.cpp.

73{
74 String referenceNameString = referenceName;
75
76 return(getReferenceID(referenceNameString, addID));
77}
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 ...

References getReferenceID().

◆ getReferenceID() [2/2]

int SamReferenceInfo::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 for the referenceName if one does not already exist, while if addID is set to false (default), it will return NO_REF_ID if the reference name does not exist.

Definition at line 45 of file SamReferenceInfo.cpp.

47{
48 if (referenceName == "*")
49 return -1;
50
51 int id = myReferenceHash.Find(referenceName);
52
53 if (id >= 0)
54 return myReferenceHash.Integer(id);
55
56 if(!addID)
57 {
58 // Don't add the id, so return NO_REF_ID
59 return(NO_REF_ID);
60 }
61
62 id = myReferenceContigs.Length();
63 myReferenceContigs.Push(referenceName);
64 myReferenceLengths.Push(0);
65 myReferenceHash.Add(referenceName, id);
66
67 return id;
68}
static const int NO_REF_ID
Constant for the value returned if a reference id does not exist for a queried reference name.

References NO_REF_ID.

Referenced by getReferenceID(), and SamFileHeader::getReferenceID().

◆ getReferenceLabel()

const String & SamReferenceInfo::getReferenceLabel ( int  id) const

Get the reference name for the specified id, if the id is not found, return "*".

Definition at line 80 of file SamReferenceInfo.cpp.

81{
82 static String noname("*");
83
84 if ((id < 0) || (id >= myReferenceContigs.Length()))
85 {
86 return noname;
87 }
88
89 return myReferenceContigs[id];
90}

Referenced by SamFileHeader::getReferenceLabel().

◆ getReferenceLength()

int32_t SamReferenceInfo::getReferenceLength ( int  index) const

Return the reference length at the specified index, returning 0 if the index is out of bounds.

Definition at line 112 of file SamReferenceInfo.cpp.

113{
114 if((index >= 0) && (index < getNumEntries()))
115 {
116 return(myReferenceLengths[index]);
117 }
118
119 // Out of bounds, return 0
120 return(0);
121}
int32_t getNumEntries() const
Get the number of entries contained here.

References getNumEntries().

◆ getReferenceName()

const char * SamReferenceInfo::getReferenceName ( int  index) const

Return the reference name at the specified index, returning "" if the index is out of bounds.

Definition at line 100 of file SamReferenceInfo.cpp.

101{
102 if((index >= 0) && (index < getNumEntries()))
103 {
104 return(myReferenceContigs[index].c_str());
105 }
106
107 // Out of range, return blank
108 return("");
109}

References getNumEntries().

◆ operator!=()

bool SamReferenceInfo::operator!= ( const SamReferenceInfo rhs) const
inline

Definition at line 70 of file SamReferenceInfo.h.

71 {
72 return(!operator==(rhs));
73 }

◆ operator=()

SamReferenceInfo & SamReferenceInfo::operator= ( const SamReferenceInfo rhs)

Copy the reference information.

Definition at line 131 of file SamReferenceInfo.cpp.

132{
133 clear();
134 // Copy Reference contigs, hash, lengths.
135 myReferenceContigs = newInfo.myReferenceContigs;
136 myReferenceHash = newInfo.myReferenceHash;
137 myReferenceLengths = newInfo.myReferenceLengths;
138 return(*this);
139}

References clear().

◆ operator==()

bool SamReferenceInfo::operator== ( const SamReferenceInfo rhs) const

Definition at line 142 of file SamReferenceInfo.cpp.

143{
144 // Hash may be different, but if Contigs are the same, the hashes will
145 // contain the same basic info (maybe just at different indices.
146 return((myReferenceContigs == rhs.myReferenceContigs) &&
147 (myReferenceLengths == rhs.myReferenceLengths));
148}

Member Data Documentation

◆ NO_REF_ID

const int SamReferenceInfo::NO_REF_ID = -3
static

Constant for the value returned if a reference id does not exist for a queried reference name.

Definition at line 77 of file SamReferenceInfo.h.

Referenced by getReferenceID().


The documentation for this class was generated from the following files: