libStatGen Software 1
BaseCount Class Reference

This class is a wrapper around an array that has one index per base and an extra index for a total count of all bases. More...

#include <BaseCount.h>

Public Member Functions

 BaseCount ()
 Constructor, initializes the array to be all 0s. More...
 
bool incrementCount (int baseIndex)
 Update the count for the specified index as well as the overall count (The last index). More...
 
void printPercent ()
 

Detailed Description

This class is a wrapper around an array that has one index per base and an extra index for a total count of all bases.

This class is used to keep a count of the number of times each index has occurred. It can print a percentage of the occurrence of each base against the total number of bases.

Definition at line 27 of file BaseCount.h.

Constructor & Destructor Documentation

◆ BaseCount()

BaseCount::BaseCount ( )

Constructor, initializes the array to be all 0s.

Definition at line 23 of file BaseCount.cpp.

24{
25 // Init each element of the array to 0.
26 for(int i = 0; i < myBaseSize; i++)
27 {
28 myBaseCount[i] = 0;
29 }
30}

Member Function Documentation

◆ incrementCount()

bool BaseCount::incrementCount ( int  baseIndex)

Update the count for the specified index as well as the overall count (The last index).

Returns
false if the specified index is < 0 or >= myBaseSize-1, otherwise returns true. The reason it returns false if it is equal to the size-1 is because the last index is used to track an overall count.

Definition at line 38 of file BaseCount.cpp.

39{
40 // Check to see if the index is within range (>=0 & < myBaseSize-1)
41 // The last entry of the array is invalid since it is used to track
42 // total occurrence of all other entries.
43 if((baseIndex < myBaseSize-1) && (baseIndex >= 0))
44 {
45 // Valid index, so increment that index as well as the overall
46 // count (index myBaseSize-1) and return true.
47 myBaseCount[baseIndex]++;
48 myBaseCount[myBaseSize-1]++;
49 return true;
50 }
51 else
52 {
53 // Invalid index, return false
54 return false;
55 }
56}

◆ printPercent()

void BaseCount::printPercent ( )

Definition at line 62 of file BaseCount.cpp.

63{
64 // Do not divide by 0, so check to see if there are any bases by checking
65 // the last index of the array.
66 if(myBaseCount[myBaseSize-1] == 0)
67 {
68 // No entries for any index.
69 std::cout << "No Valid Bases found.";
70 }
71 else
72 {
73 // Print the percentage for each index.
74 for(int i = 0; i < myBaseSize -1; i++)
75 {
76 double percentage =
77 (myBaseCount[i]/(double)myBaseCount[myBaseSize-1]) * 100;
78 std::cout << " " << std::setw(7) << percentage;
79 }
80 // Print the total number of bases.
81 std::cout << "\t" << myBaseCount[myBaseSize-1];
82 }
83 std::cout << std::endl;
84}

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