src/c++/lib/variant/RefVar.cpp
/**
 * @brief Decompose a RefVar into primitive variants (subst / ins / del)
 *
 * @param rv the RefVar record
 * @param vars the primitive records
 */
@brief Decompose a RefVar into primitive variants (subst / ins / del)
@param rv the RefVar record
@param vars the primitive records
@brief Decompose a RefVar into primitive variants ( subst / ins / del ) @param rv the RefVar record @param vars the primitive records
int toPrimitives(FastaFile const& f, const char* chr, RefVar const& rv, std::list<variant::RefVar>& vars)
{
    int64_t rstart = rv.start, rend = rv.end, reflen = rend - rstart + 1;
    int64_t altlen = (int64_t)rv.alt.size();
    std::string refseq;
    std::string altseq(rv.alt);
    if (reflen > 0)
    {
        refseq = f.query(chr, rstart, rend);
    }
    size_t pos = 0;
    int count = 0;
    while (reflen > 0 && altlen > 0)
    {
        char r = refseq[pos];
        char a = altseq[pos];
        if (r != a)
        {
            vars.push_back(RefVar{ rstart, rstart, std::string(1, a), rv.flags });
            count++;
        }
        ++rstart;
        ++pos;
        --reflen;
        --altlen;
    }
    if (reflen > 0)
    {
        vars.push_back(RefVar{ rstart, rend, "", rv.flags });
        count++;
    }
    else if (altlen > 0)
    {
        vars.push_back(RefVar{ rstart, rstart - 1, altseq.substr(pos), rv.flags });
        count++;
    }
    return (count);
}
int toPrimitives ( FastaFile const & f , const char * chr , RefVar const & rv , std :: list < variant :: RefVar > & vars ) { int64_t rstart = rv . start , rend = rv . end , reflen = rend - rstart + 1 ; int64_t altlen = ( int64_t ) rv . alt . size ( ) ; std :: string refseq ; std :: string altseq ( rv . alt ) ; if ( reflen > 0 ) { refseq = f . query ( chr , rstart , rend ) ; } size_t pos = 0 ; int count = 0 ; while ( reflen > 0 && altlen > 0 ) { char r = refseq [ pos ] ; char a = altseq [ pos ] ; if ( r != a ) { vars . push_back ( RefVar { rstart , rstart , std :: string ( 1 , a ) , rv . flags } ) ; count ++ ; } ++ rstart ; ++ pos ; -- reflen ; -- altlen ; } if ( reflen > 0 ) { vars . push_back ( RefVar { rstart , rend , " " , rv . flags } ) ; count ++ ; } else if ( altlen > 0 ) { vars . push_back ( RefVar { rstart , rstart - 1 , altseq . substr ( pos ) , rv . flags } ) ; count ++ ; } return ( count ) ; }
@brief Decompose a RefVar into primitive variants (subst / ins / del)
 @param rv the RefVar record
 @param vars the primitive records
@brief Decompose a RefVar into primitive variants ( subst / ins / del ) @param rv the RefVar record @param vars the primitive records
// from the left, split off SNPs / matches // now either reflen == 0 or altlen == 0 // del // ins // else nothing left