/** ** Copyright (c) 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 AnomalousReadMgr.cpp ** ** \brief Encapsulation of the concept of a read pair relative orientation. ** ** Encapsulation of the concept of a read pair relative orientation. ** ** \author Richard Shaw **/ /*****************************************************************************/ #include #include #include #include #include #define foreach BOOST_FOREACH #include "common/Exceptions.hh" #include "variance/AnomalousReadMgr.hh" /*****************************************************************************/ namespace ca { namespace variance_detection { /*****************************************************************************/ using boost::assign::list_of; /*****************************************************************************/ AnomalousReadMgr::AnomalousReadMgr(long clusterMaxInterBreakPtDist) : myClusterMaxInterBreakPtDist(clusterMaxInterBreakPtDist) { ; } /*****************************************************************************/ AnomalousReadMgr::~AnomalousReadMgr() { ; } /*****************************************************************************/ void AnomalousReadMgr::addRead(AnomalousRead::Type anomalousReadType, Singleton* singletonPtr) { myTypeSingletonPtrVecMap[anomalousReadType].push_back(singletonPtr); } /*****************************************************************************/ unsigned long AnomalousReadMgr::totalNumReadsAdded() const { unsigned int numReadsAdded(0); foreach(const TypeSingletonPtrVecMap::value_type& typeSingletonPtrVecPair, myTypeSingletonPtrVecMap) { numReadsAdded += typeSingletonPtrVecPair.second.size(); } return numReadsAdded; } /*****************************************************************************/ AnomalousReadMgr::SingletonPtrVec& AnomalousReadMgr::getVec(AnomalousRead::Type anomalousReadType) { return myTypeSingletonPtrVecMap[anomalousReadType]; } /*****************************************************************************/ const AnomalousReadMgr::SingletonPtrVec& AnomalousReadMgr::getVec(AnomalousRead::Type anomalousReadType) const { TypeSingletonPtrVecMapCIter typeSingletonPtrVecMapCIter = myTypeSingletonPtrVecMap.find(anomalousReadType); if (typeSingletonPtrVecMapCIter == myTypeSingletonPtrVecMap.end()) { return myEmptySingletonPtrVec; } return typeSingletonPtrVecMapCIter->second; } /*****************************************************************************/ void AnomalousReadMgr::getAnomPairTypeVec(TypeVec& typeVec) const { typeVec = list_of (AnomalousRead::InsertionPair) (AnomalousRead::DeletionPair) (AnomalousRead::DuplicationPair) (AnomalousRead::InversionPair) (AnomalousRead::ChimericPair); } /*****************************************************************************/ class SorterByMostLikelyBreakPt { public: bool operator()(const SingletonEvent& eventA, const SingletonEvent& eventB) { return (((dynamic_cast(eventA.pRead_)) ->mostLikelyBreakPt()) < ((dynamic_cast(eventB.pRead_)) ->mostLikelyBreakPt())); } }; /*****************************************************************************/ void AnomalousReadMgr::getSortedAnomReads(AnomalousRead::Type anomalousReadType, SingletonEventVec& sortedAnomReads) const { // ShadowOrSemiAligned not yet supported assert(anomalousReadType != AnomalousRead::ShadowOrSemiAligned); const SingletonPtrVec& anomReadPtrVec(getVec(anomalousReadType)); for (SingletonPtrVecCIter anomReadCIter(anomReadPtrVec.begin()); anomReadCIter != anomReadPtrVec.end(); ++anomReadCIter) { AnomalousRead* anomReadPtr(dynamic_cast(*anomReadCIter)); // Simplified form of the numLeadingMatches filter in // ClusterFinderImpl::operator() since do not need in-read // breakpoint prediction :- // if (isdigit(anomReadPtr->alignment_[0])) { // Assuming not needed at all for Anom Pair reads? sortedAnomReads. push_back(SingletonEvent(anomReadPtr->mostLikelyBreakPt(), anomReadPtr)); } // Do the sort. sort(sortedAnomReads.begin(), sortedAnomReads.end(), SorterByMostLikelyBreakPt()); } /*****************************************************************************/ void AnomalousReadMgr::clusterAnomPairReads(AnomalousRead::Type anomReadType, SingletonEventVec& sortedEvents, AnomReadGroupVec& clusters) { long lastMostLikelyBreakPt(-500000); for (SingletonEventVecCIter eventCIter(sortedEvents.begin()); eventCIter != sortedEvents.end(); ++eventCIter) { AnomalousRead* anomReadPtr(dynamic_cast(eventCIter->pRead_)); const long mostLikelyBreakPt(anomReadPtr->mostLikelyBreakPt()); if ((mostLikelyBreakPt - lastMostLikelyBreakPt) > myClusterMaxInterBreakPtDist) { clusters.push_back(AnomReadGroup(anomReadType)); } clusters.back().insert(anomReadPtr); clusters.back().positionStats_.update(mostLikelyBreakPt); lastMostLikelyBreakPt = mostLikelyBreakPt; } } /*****************************************************************************/ } // namespace variance_detection } // namespace ca /*****************************************************************************/