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.
 
 ~SamReferenceInfo ()
 Destructor.
 
void add (const char *referenceSequenceName, int32_t referenceSequenceLength)
 Add reference sequence name and reference sequence length.
 
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.
 
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.
 
SamReferenceInfooperator= (const SamReferenceInfo &rhs)
 Copy the reference information.
 
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.

Member Function Documentation

◆ getReferenceID() [1/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.

References NO_REF_ID.

Referenced by getReferenceID().

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...

◆ getReferenceID() [2/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.

References getReferenceID().

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 ...

◆ 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 }

◆ 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.

References getNumEntries().

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.

◆ 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.

References getNumEntries().

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 }
int32_t getNumEntries() const
Get the number of entries contained here.

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(), and SamFile::validateSortOrder().


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