libStatGen Software 1
BaseComposition.cpp
1/*
2 * Copyright (C) 2010 Regents of the University of Michigan
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <iomanip>
19#include "BaseComposition.h"
20
21// Constructor
22// Initialize the base to ascii map based on the specified maptype.
24 myBaseAsciiMap()
25{
26}
27
28
29// Update the composition for the specified index with the specified character.
30// Return false if the character is not a valid raw sequence character.
31// Return true if it is valid.
32bool BaseComposition::updateComposition(unsigned int rawSequenceCharIndex,
33 char baseChar)
34{
35 bool validIndex = true;
36
37 // Each time we return to index 0, reset the primer count in the base/ascii
38 // map.
39 if(rawSequenceCharIndex == 0)
40 {
41 myBaseAsciiMap.resetPrimerCount();
42 }
43
44 // Check to see if the vector size is already sized to include this
45 // index. If it is not sized appropriately, add entries until it contains
46 // the rawSequenceCharIndex.
47 while(rawSequenceCharIndex >= myBaseCountVector.size())
48 {
49 // Add an entry of the base count array object to the vector.
50 BaseCount baseCountEntry;
51 myBaseCountVector.push_back(baseCountEntry);
52 }
53
54 // Get the base info for the specified character.
55 int baseIndex = myBaseAsciiMap.getBaseIndex(baseChar);
56
57 // Increment the count for the given character. This method returns false
58 // if the character's index falls outside the range of the base array.
59 // This relies on the myBaseAsciiMap indexes and the BaseCOunt object array
60 // to use the same indexing values for valid bases.
61 validIndex =
62 myBaseCountVector[rawSequenceCharIndex].incrementCount(baseIndex);
63
64 // Return whether or not the specified character was valid.
65 return(validIndex);
66}
67
68
69// Print the composition.
71{
72 std::cout << std::endl << "Base Composition Statistics:" << std::endl;
73 std::cout.precision(2);
74 // This assumes the relationship between indexes that are printed
75 // by a BaseCount object to be in a specific order based on ATGCN.
76 std::cout << std::fixed << "Read Index"
77 << "\t%A" << "\t%C" << "\t%G" << "\t%T" << "\t%N" << "\tTotal Reads At Index"
78 << std::endl;
79 for(unsigned int i = 0; i < myBaseCountVector.size(); i++)
80 {
81 std::cout << std::setw(10) << i << " ";
82 myBaseCountVector[i].printPercent();
83 }
84 std::cout << std::endl;
85}
86
87
88// Clear the vector.
90{
91 myBaseCountVector.clear();
92}
void resetPrimerCount()
Reset the number of primers to 0.
Definition: BaseAsciiMap.h:158
int getBaseIndex(const char &letter)
Returns the baseIndex value for the character passed in.
Definition: BaseAsciiMap.h:94
bool updateComposition(unsigned int rawSequenceCharIndex, char baseChar)
Update the composition for the specified index with the specified character.
void clear()
Clear the composition stored in the base count vector.
BaseComposition()
Constructor.
void print()
Print the composition.
This class is a wrapper around an array that has one index per base and an extra index for a total co...
Definition: BaseCount.h:28