src/c++/lib/grm/KlibAligner.cpp
/**
 * \return best path id
 * \precondition non-empty candidates list
 */
\return best path id
\precondition non-empty candidates list
\ return best path id \ precondition non - empty candidates list
void KlibAlignerImpl::pickBest(
    const std::string& bases, const std::string& rvBases, const Candidates& candidates, common::Read& read) const
{
    assert(!candidates.empty());
    const auto bestIt = std::min_element(candidates.begin(), candidates.end(), Candidate::betterScore);
    const Candidate& best = *bestIt;
    const Path& path = paths_[best.pathId_];
    updateAlignment(best, rvBases, bases, path, read);
    for (auto secondBestIt = std::min_element(bestIt + 1, candidates.end(), Candidate::betterScore);
         candidates.end() != secondBestIt;
         secondBestIt = std::min_element(secondBestIt + 1, candidates.end(), Candidate::betterScore))
    {
        const Candidate& secondBest = *secondBestIt;
        if (secondBest.score_ == best.score_)
        {
            common::Read secondBestRead = read;
            const Path& secondBestPath = paths_[secondBest.pathId_];
            updateAlignment(secondBest, rvBases, bases, secondBestPath, secondBestRead);
            if (secondBestRead.graph_cigar() != read.graph_cigar() || secondBestRead.graph_pos() != read.graph_pos())
            {
                read.set_graph_mapq(0);
                read.set_is_graph_alignment_unique(false);
                read.set_graph_mapping_status(common::Read::BAD_ALIGN);
                break;
            }
        }
        else
        {
            break;
        }
    }
}
void KlibAlignerImpl :: pickBest ( const std :: string & bases , const std :: string & rvBases , const Candidates & candidates , common :: Read & read ) const { assert ( ! candidates . empty ( ) ) ; const auto bestIt = std :: min_element ( candidates . begin ( ) , candidates . end ( ) , Candidate :: betterScore ) ; const Candidate & best = * bestIt ; const Path & path = paths_ [ best . pathId_ ] ; updateAlignment ( best , rvBases , bases , path , read ) ; for ( auto secondBestIt = std :: min_element ( bestIt + 1 , candidates . end ( ) , Candidate :: betterScore ) ; candidates . end ( ) != secondBestIt ; secondBestIt = std :: min_element ( secondBestIt + 1 , candidates . end ( ) , Candidate :: betterScore ) ) { const Candidate & secondBest = * secondBestIt ; if ( secondBest . score_ == best . score_ ) { common :: Read secondBestRead = read ; const Path & secondBestPath = paths_ [ secondBest . pathId_ ] ; updateAlignment ( secondBest , rvBases , bases , secondBestPath , secondBestRead ) ; if ( secondBestRead . graph_cigar ( ) != read . graph_cigar ( ) || secondBestRead . graph_pos ( ) != read . graph_pos ( ) ) { read . set_graph_mapq ( 0 ) ; read . set_is_graph_alignment_unique ( false ) ; read . set_graph_mapping_status ( common :: Read :: BAD_ALIGN ) ; break ; } } else { break ; } } }
\return best path id
 \precondition non-empty candidates list
\ return best path id \ precondition non - empty candidates list
// no more as good candidates