src/c++/lib/variant/RefVar.cpp
/**
 * Append 1 char to RefVar.
 *
 * Return false if this is not possible because the variants are incompatible
 */
Append 1 char to RefVar.
Return false if this is not possible because the variants are incompatible
Append 1 char to RefVar . Return false if this is not possible because the variants are incompatible
bool appendToRefVar(int64_t refpos, char refchr, char altchr, RefVar& rv)
{
#ifdef DEBUG_REFVAR
    std::cerr << "\t" << refpos << " " << refchr << " " << altchr << " " << rv << "\n";
#endif
    if (refchr == altchr)
    {
        return false;
    }
    if ((refpos == rv.start - 1 || refpos == rv.start) && rv.end == rv.start - 1
        && rv.alt.size() > 0) 
    {
        if (refchr == '-') 
        {
            rv.alt += altchr;
        }
        else if (refchr != '-' && altchr != '-')
        {
            if (rv.start > refpos)
            {
                rv.start = refpos;
                rv.end = refpos;
            }
            else
            {
                rv.end++;
            }
            rv.alt += altchr;
        }
        else if (altchr == '-') 
        {
            if (rv.start > refpos)
            {
                rv.start = refpos;
                rv.end = refpos;
            }
            else
            {
                rv.end++;
            }
        }
        else
        {
            return false;
        }
        return true;
    }
    if (refpos != rv.end + 1)
    {
        return false;
    }
    if (rv.end >= rv.start && rv.alt.size() > 0) 
    {
        if (refchr != '-' && altchr != '-')
        {
            rv.end++;
            rv.alt += altchr;
        }
        else if (refchr == '-') 
        {
            rv.alt += altchr;
        }
        else if (altchr == '-') 
        {
            rv.end++;
        }
        else
        {
            return false;
        }
    }
    else if (rv.end >= rv.start && rv.alt.size() == 0) 
    {
        if (refchr != '-' && altchr != '-')
        {
            rv.end++;
            rv.alt += altchr;
        }
        else if (refchr == '-') 
        {
            rv.alt += altchr;
        }
        else if (altchr == '-') 
        {
            rv.end++;
        }
        else
        {
            return false;
        }
    }
    return true;
}
bool appendToRefVar ( int64_t refpos , char refchr , char altchr , RefVar & rv ) { #ifdef DEBUG_REFVAR std :: cerr << " \t " << refpos << " " << refchr << " " << altchr << " " << rv << " \n " ; #endif if ( refchr == altchr ) { return false ; } if ( ( refpos == rv . start - 1 || refpos == rv . start ) && rv . end == rv . start - 1 && rv . alt . size ( ) > 0 ) { if ( refchr == ' ' ) { rv . alt += altchr ; } else if ( refchr != ' ' && altchr != ' ' ) { if ( rv . start > refpos ) { rv . start = refpos ; rv . end = refpos ; } else { rv . end ++ ; } rv . alt += altchr ; } else if ( altchr == ' ' ) { if ( rv . start > refpos ) { rv . start = refpos ; rv . end = refpos ; } else { rv . end ++ ; } } else { return false ; } return true ; } if ( refpos != rv . end + 1 ) { return false ; } if ( rv . end >= rv . start && rv . alt . size ( ) > 0 ) { if ( refchr != ' ' && altchr != ' ' ) { rv . end ++ ; rv . alt += altchr ; } else if ( refchr == ' ' ) { rv . alt += altchr ; } else if ( altchr == ' ' ) { rv . end ++ ; } else { return false ; } } else if ( rv . end >= rv . start && rv . alt . size ( ) == 0 ) { if ( refchr != ' ' && altchr != ' ' ) { rv . end ++ ; rv . alt += altchr ; } else if ( refchr == ' ' ) { rv . alt += altchr ; } else if ( altchr == ' ' ) { rv . end ++ ; } else { return false ; } } return true ; }
Append 1 char to RefVar.
Append 1 char to RefVar .
// already checked in function just below actually // we test anyway in case we ever want to expose this // function // see what we have currently // rv is an insertion just before refpos, or a complex insertion ending at refpos // we've been passed an insertion and we can extend? //  -> && altchr != '-' since refchr != altchr // we've been passed a substitution? // first subst after insertion -- fix start and end //  -> && refchr != '-'; would have caught this above otherwise // we've been passed a deletion // first deletion after insertion -- fix start and end // here, we append only // block substitution // we've been passed a substitution? //  -> && altchr != '-' since refchr != altchr // we've been passed an insertion //  -> && refchr != '-' since refchr != altchr // we've been passed a deletion // deletion // we've been passed a substitution? //  -> && altchr != '-' since refchr != altchr // we've been passed an insertion //  -> && refchr != '-' since refchr != altchr // we've been passed a deletion