libStatGen Software  1
BaseComposition.cpp
00001 /*
00002  *  Copyright (C) 2010  Regents of the University of Michigan
00003  *
00004  *   This program is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #include <iomanip>
00019 #include "BaseComposition.h"
00020 
00021 // Constructor
00022 // Initialize the base to ascii map based on the specified maptype.
00023 BaseComposition::BaseComposition():
00024    myBaseAsciiMap()
00025 {
00026 }
00027 
00028 
00029 // Update the composition for the specified index with the specified character.
00030 // Return false if the character is not a valid raw sequence character.
00031 // Return true if it is valid.
00032 bool BaseComposition::updateComposition(unsigned int rawSequenceCharIndex, 
00033                                         char baseChar)
00034 {
00035    bool validIndex  = true;
00036 
00037    // Each time we return to index 0, reset the primer count in the base/ascii
00038    // map.
00039    if(rawSequenceCharIndex == 0)
00040    {
00041       myBaseAsciiMap.resetPrimerCount();
00042    }
00043 
00044    // Check to see if the vector size is already sized to include this 
00045    // index.  If it is not sized appropriately, add entries until it contains
00046    // the rawSequenceCharIndex.
00047    while(rawSequenceCharIndex >= myBaseCountVector.size())
00048    {
00049       // Add an entry of the base count array object to the vector.
00050       BaseCount baseCountEntry;
00051       myBaseCountVector.push_back(baseCountEntry);
00052    }
00053 
00054    // Get the base info for the specified character. 
00055    int baseIndex = myBaseAsciiMap.getBaseIndex(baseChar);
00056    
00057    // Increment the count for the given character.  This method returns false
00058    // if the character's index falls outside the range of the base array.
00059    // This relies on the myBaseAsciiMap indexes and the BaseCOunt object array
00060    // to use the same indexing values for valid bases.
00061    validIndex = 
00062       myBaseCountVector[rawSequenceCharIndex].incrementCount(baseIndex);
00063    
00064    // Return whether or not the specified character was valid.
00065    return(validIndex);
00066 }
00067 
00068 
00069 // Print the composition.
00070 void BaseComposition::print()
00071 {
00072    std::cout << std::endl << "Base Composition Statistics:" << std::endl;
00073    std::cout.precision(2);
00074    // This assumes the relationship between indexes that are printed
00075    // by a BaseCount object to be in a specific order based on ATGCN.
00076    std::cout << std::fixed << "Read Index" 
00077              << "\t%A" << "\t%C" << "\t%G" << "\t%T" << "\t%N" << "\tTotal Reads At Index" 
00078              << std::endl;
00079    for(unsigned int i = 0; i < myBaseCountVector.size(); i++)
00080    {
00081       std::cout << std::setw(10) << i << " ";
00082       myBaseCountVector[i].printPercent();
00083    }
00084    std::cout << std::endl;
00085 }
00086 
00087 
00088 // Clear the vector.
00089 void BaseComposition::clear()
00090 {
00091    myBaseCountVector.clear();
00092 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends