/** ** Copyright (c) Solexa 2005, 2006 ** 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 lib/common/Tiling.cpp ** ** \brief Tiling structure and runfolder names for a data analysis run ** ** Set the tiling structure and runfolder names for a data analysis run. ** This object is used to generate suitable filenames for output files, ** according to the run-folder specification. Internally, the image ** analysis does not need to know about these conventions; tiles (positions ** on the chip) are simply numbered sequentially. ** ** \author Klaus Maisinger **/ #if defined(__BORLANDC__) #include #else #include #endif #include #include "common/Tiling.h" RunFolderFileName::RunFolderFileName(const char prefix[]) : nchannel(0), tileoffset(0) { path = prefix; typestring[POSITION_FILE] = "pos"; typestring[INDEX_FILE] = "idx", typestring[INTENSITY_FILE] = "int"; typestring[NOISE_FILE] = "nse"; typestring[OFFSET_FILE] = "off"; typestring[CLUSTER_FILE] = "clu"; typestring[QC_FILE] = "qcm"; typestring[SIGNAL_FILE] = "sig"; typestring[Q_SEQUENCE_FILE] = "qseq"; typestring[SEQUENCE_FILE] = "seq"; typestring[PROBABILITY_FILE]= "prb"; typestring[SIGNAL2_FILE] = "sig2"; typestring[SCORE_FILE] = "score"; typestring[RESCORE_FILE] = "rescore"; } RunFolderFileName::~RunFolderFileName() { if (nchannel > 0) { delete [] channelidx; delete [] channelcount; } } /** * use lanes with indices given by the -dim * array . Each lane has tiles. * * @todo: remove or fix the memory leak */ void RunFolderFileName::setLanes(const int *laneIndex, const int *laneNumTiles, const int numLanes) { nchannel = numLanes; channelcount = new int [nchannel]; channelidx = new int [nchannel]; int i; for (i = 0; i < nchannel; i++) { channelcount[i] = laneNumTiles[i]; channelidx[i] = laneIndex[i]; } } /** * only use one lane with index . there are tiles, * counting starts from * * @todo fix the memory leak */ void RunFolderFileName::setLane(const int lane, const int tileIndex, const int numTiles) { nchannel = 1; channelcount = new int [nchannel]; channelidx = new int [nchannel]; channelcount[0] = numTiles+tileIndex; channelidx[0] = lane; tileoffset = tileIndex; } int RunFolderFileName::getLane(const int idx) const { int i = 0, total = 0; while (i < nchannel) { total += channelcount[i]; if (idx < total) return channelidx[i]; } return 0; } int RunFolderFileName::getTile(const int idx) const { int i = 0, total = 0; while (i < nchannel) { total += channelcount[i]; if (idx < total) return idx-(total-channelcount[i]) + tileoffset; } return idx+tileoffset; } int RunFolderFileName::getIndex(const int lane, const int tile) const { int i = 0, total = 0; while ((i < nchannel) && (channelidx[i] < lane)) total += channelcount[i]; return tile+total; } std::string RunFolderFileName::getTileFilename(const RunFolderFileName::filename_type type, const int lane, const int tile, const int cycle, const int channel) const { char filename[FILENAME_MAX]; const std::map::const_iterator iterator = typestring.find(type); const std::string litteral(iterator == typestring.end() ? std::string("unknown_type") : iterator->second); if (type == QC_FILE) { snprintf(filename, FILENAME_MAX, "%s_%01d_%04d_%02d_%s.xml", path.c_str(), lane + 1, tile + 1, cycle + 1, litteral.c_str()); return std::string(filename); } if (cycle < 0) { snprintf(filename, FILENAME_MAX, "%s_%01d_%04d_%s.txt", path.c_str(), lane + 1, tile + 1, litteral.c_str()); } else { if (channel < 0) snprintf(filename, FILENAME_MAX, "%s_%01d_%04d_%02d_%s.txt", path.c_str(), lane + 1, tile + 1, cycle + 1, litteral.c_str()); else snprintf(filename, FILENAME_MAX, "%s_%01d_%04d_%02d_%1d_%s.txt", path.c_str(), lane + 1, tile + 1, cycle + 1, channel + 1, litteral.c_str()); } return std::string(filename); } /*****************************************************************************/ // Possibly temporary method pending file distinction by subdirectory. std::string RunFolderFileName::getQualifiedTileFilename(const filename_type type, const std::string& qualifier_str, const int lane, const int tile) const { boost::format fmt("%s_%01d_%04d%s_%s.txt"); const std::map::const_iterator iterator = typestring.find(type); const std::string litteral(iterator == typestring.end() ? std::string("unknown_type") : iterator->second); return ((fmt % path.c_str() % (lane + 1) % (tile + 1) % qualifier_str.c_str() % litteral.c_str()).str()); } /*****************************************************************************/ std::string RunFolderFileName::getIndexFilename(const RunFolderFileName::filename_type type, const int idx, const int cycle, const int channel) const { return getTileFilename(type, getLane(idx), getTile(idx), cycle, channel); } std::string RunFolderFileName::getFilePrefix() const { return path; }