/** ** Copyright (c) 2007-2010 Illumina, Inc. ** ** This software is covered by the "Illumina Genome Analyzer Software ** License Agreement" and the "Illumina Source Code License Agreement", ** and certain third party copyright/licenses, and any user of this ** source file is bound by the terms therein (see accompanying files ** Illumina_Genome_Analyzer_Software_License_Agreement.pdf and ** Illumina_Source_Code_License_Agreement.pdf and third party ** copyright/license notices). ** ** This file is part of the Consensus Assessment of Sequence And VAriation ** (CASAVA) software package. ** ** \file variance/indelReadsStats.cpp ** ** \brief ** ** ** ** \author **/ #include "variance/indelReadsStats.h" /* ----- ----- ----- ----- ----- ----- * * ----- Auxillary funcitons ----- * * ----- ----- ----- ----- ----- ----- */ /* ----- ----- ----- ----- ----- ----- * * ----- Manipulation Functions ----- * * ----- ----- ----- ----- ----- ----- */ void IndelReadsStats::load(string file) { // Clear all previous data this->machineNames.clear(); this->runNums.clear(); this->laneNums.clear(); this->meanInsSize.clear(); this->sdInsSize.clear(); this->keys.clear(); ifstream fileStream; fileStream.open(file.c_str(), ios_base::in); string line; while(! fileStream.eof()) { getline(fileStream, line); if (line.substr(0, 1).compare("#") == 0 || line.length() == 0) { continue; } vector data; Export::tsvToArray(line, data, '\t'); //this->machineNames.push_back(data[STAT_MACHINE_NAME_IDX]); //this->runNums.push_back(atoi(data[STAT_RUN_NUM_IDX].c_str())); //this->laneNums.push_back(atoi(data[STAT_LANE_NUM_IDX].c_str())); //this->meanInsSize.push_back(atof(data[STAT_INS_SIZE_MEAN_IDX].c_str())); //this->sdInsSize.push_back(atof(data[STAT_INS_SIZE_SD_IDX].c_str())); // Get key string stringstream skey; skey << data[STAT_MACHINE_NAME_IDX] << ":" << data[STAT_RUN_NUM_IDX] << ":" << data[STAT_LANE_NUM_IDX]; string key = skey.str(); // Make sure key does not already exist //if (this->meanInsSize.find(key)->compare(map::end)) { //} else { // We should throw some kind of an error or warning... //} // Simply just write over previous value for now... // Assign key value pairs this->machineNames[key] = data[STAT_MACHINE_NAME_IDX]; this->runNums[key] = atoi(data[STAT_RUN_NUM_IDX].c_str()); this->laneNums[key] = atoi(data[STAT_LANE_NUM_IDX].c_str()); this->meanInsSize[key] = atof(data[STAT_INS_SIZE_MEAN_IDX].c_str()); this->sdInsSize[key] = atof(data[STAT_INS_SIZE_SD_IDX].c_str()); // Add key to keys vector this->keys.push_back(key); } fileStream.close(); } /* ----- ----- ----- ----- ----- * * ----- Access Functions ----- * * ----- ----- ----- ----- ----- */ double IndelReadsStats::getMeanInsSize(string m, int r, int l) { stringstream skey; skey << m << ":" << r << ":" << l; string key = skey.str(); // Return -1 if key not found /* if (this->meanInsSize.find(key) == map::end) { return(-1); } */ return(this->meanInsSize[key]); /* int len = this->machineNames.size(); for (int idx = 0; idx < len; idx++) { if (this->machineNames[idx].compare(m) == 0 && this->runNums[idx] == r && this->laneNums[idx] == l) { return(this->meanInsSize[idx]); } } cerr << "[Warning]: Unable to find mean index for: " << m << ", " << r << ", " << l << endl; return(-1); */ } double IndelReadsStats::getSdInsSize(string m, int r, int l) { stringstream skey; skey << m << ":" << r << ":" << l; string key = skey.str(); // Return -1 if key not found /* if (this->sdInsSize.find(key) == map::end) { return(-1); } */ return(this->sdInsSize[key]); /* int len = this->machineNames.size(); for (int idx = 0; idx < len; idx++) { if (this->machineNames[idx].compare(m) == 0 && this->runNums[idx] == r && this->laneNums[idx] == l) { return(this->sdInsSize[idx]); } } cerr << "[Warning]: Unable to find mean index for: " << m << ", " << r << ", " << l << endl; return(-1); */ } string IndelReadsStats::toString() { stringstream con; const unsigned int numKeys = this->keys.size(); for (unsigned int ii = 0; ii < numKeys; ii++) { string key = keys[ii]; con << machineNames[key] << "\t" << runNums[key] << "\t" << laneNums[key] << "\t" << meanInsSize[key] << "\t" << sdInsSize[key] << "\n"; } return(con.str()); } /* ----- ----- ----- ----- ----- * * ----- Test Functions -- ----- * * ----- ----- ----- ----- ----- */ /* int main( int numArgs, char* args [] ) { return(0); } */ // END OF FILE