Loading...
Searching...
No Matches
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.
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.
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.
int32_t | getReferenceLength (int index) const
| Return the reference length at the specified index, returning 0 if the index is out of bounds.
void | clear ()
| Reset this reference info.
SamReferenceInfo & | operator= (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.

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

: myReferenceContigs(),
myReferenceHash(),
myReferenceLengths()
{
clear();
}
SamReferenceInfo::clear
void clear()
Reset this reference info.
Definition SamReferenceInfo.cpp:123

References clear().

Referenced by operator=().

## ~SamReferenceInfo()

SamReferenceInfo::~SamReferenceInfo | ( |  | ) |

Destructor.

Definition at line 29 of file SamReferenceInfo.cpp.

{
clear();
}

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.

{
myReferenceHash.Add(referenceSequenceName,
myReferenceContigs.Length());
myReferenceContigs.Push(referenceSequenceName);
myReferenceLengths.Push(referenceSequenceLength);
}

## clear()

void SamReferenceInfo::clear | ( |  | ) |

Reset this reference info.

Definition at line 123 of file SamReferenceInfo.cpp.

{
myReferenceContigs.Clear();
myReferenceHash.Clear();
myReferenceLengths.Clear();
}

Referenced by SamReferenceInfo(), ~SamReferenceInfo(), 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.

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

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.

{
String referenceNameString = referenceName;
return(getReferenceID(referenceNameString, addID));
}
SamReferenceInfo::getReferenceID
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 ...
Definition SamReferenceInfo.cpp:45

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.

{
if (referenceName == "*")
return -1;
int id = myReferenceHash.Find(referenceName);
if (id >= 0)
return myReferenceHash.Integer(id);
if(!addID)
{
// Don't add the id, so return NO_REF_ID
return(NO_REF_ID);
}
id = myReferenceContigs.Length();
myReferenceContigs.Push(referenceName);
myReferenceLengths.Push(0);
myReferenceHash.Add(referenceName, id);
return id;
}
SamReferenceInfo::NO_REF_ID
static const int NO_REF_ID
Constant for the value returned if a reference id does not exist for a queried reference name.
Definition SamReferenceInfo.h:77

References NO_REF_ID.

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

{
static String noname("*");
if ((id < 0) || (id >= myReferenceContigs.Length()))
{
return noname;
}
return myReferenceContigs[id];
}

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

{
if((index >= 0) && (index < getNumEntries()))
{
return(myReferenceLengths[index]);
}
// Out of bounds, return 0
return(0);
}
SamReferenceInfo::getNumEntries
int32_t getNumEntries() const
Get the number of entries contained here.
Definition SamReferenceInfo.cpp:93

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.

{
if((index >= 0) && (index < getNumEntries()))
{
return(myReferenceContigs[index].c_str());
}
// Out of range, return blank
return("");
}

References getNumEntries().

## operator!=()

bool SamReferenceInfo::operator!= | ( | const SamReferenceInfo & | rhs | ) | const

inline

Definition at line 70 of file SamReferenceInfo.h.

{
return(!operator==(rhs));
}

## operator=()

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

Copy the reference information.

Definition at line 131 of file SamReferenceInfo.cpp.

{
clear();
// Copy Reference contigs, hash, lengths.
myReferenceContigs = newInfo.myReferenceContigs;
myReferenceHash = newInfo.myReferenceHash;
myReferenceLengths = newInfo.myReferenceLengths;
return(*this);
}

References SamReferenceInfo(), and clear().

## operator==()

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

Definition at line 142 of file SamReferenceInfo.cpp.

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

## 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:

- bam/SamReferenceInfo.h
- bam/SamReferenceInfo.cpp