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>

List of all members.

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

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

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(), and SamFileHeader::getReferenceID().

{
    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;
}
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().

{
    String referenceNameString = referenceName;

    return(getReferenceID(referenceNameString, addID));
}
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.

Referenced by SamFileHeader::getReferenceLabel().

{
    static String noname("*");

    if ((id < 0) || (id >= myReferenceContigs.Length()))
    {
        return noname;
    }

    return myReferenceContigs[id];
}
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().

{
    if((index >= 0) && (index < getNumEntries()))
    {
        return(myReferenceLengths[index]);
    }
    
    // Out of bounds, return 0
    return(0);
}
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().

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

Member Data Documentation

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:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends