src/c++/lib/variant/RefVar.cpp
/**
 * Convert a list of RefVar records to allele strings
 */
Convert a list of RefVar records to allele strings
Convert a list of RefVar records to allele strings
extern void toAlleles(FastaFile const& f, const char* chr, std::vector<RefVar> const& in, std::vector<std::string>& out)
{
    int64_t minpos = std::numeric_limits<int64_t>::max(), maxpos = 0;
    if (in.size() == 0)
    {
        return;
    }
    for (size_t s = 0; s < in.size(); ++s)
    {
        RefVar const& rv = in[s];
        minpos = std::min(minpos, rv.start);
        minpos = std::min(minpos, rv.end);
        if (rv.start > rv.end)
        {
            maxpos = std::max(maxpos, rv.end);
        }
        else
        {
            maxpos = std::max(maxpos, rv.start);
            maxpos = std::max(maxpos, rv.end);
        }
    }
    std::string ref = f.query(chr, minpos, maxpos);
    if ((signed)ref.size() != maxpos - minpos + 1)
    {
        error("Cannot query reference sequence at %s:%i-%i", ref.c_str(), minpos, maxpos);
    }
    out.resize(in.size() + 1);
    out[0] = ref;
    for (size_t i = 0; i < in.size(); ++i)
    {
        int64_t refstart = in[i].start - minpos;
        int64_t reflen = in[i].end - in[i].start + 1;
        if (reflen == (signed)ref.size() && refstart == 0)
        {
            out[i + 1] = in[i].alt;
        }
        else
        {
            out[i + 1] = ref;
            out[i + 1].replace(refstart, reflen, in[i].alt);
        }
        if (out[i + 1].size() == 0)
        {
            out[i + 1] = "<DEL>";
        }
    }
}
extern void toAlleles ( FastaFile const & f , const char * chr , std :: vector < RefVar > const & in , std :: vector < std :: string > & out ) { int64_t minpos = std :: numeric_limits < int64_t > :: max ( ) , maxpos = 0 ; if ( in . size ( ) == 0 ) { return ; } for ( size_t s = 0 ; s < in . size ( ) ; ++ s ) { RefVar const & rv = in [ s ] ; minpos = std :: min ( minpos , rv . start ) ; minpos = std :: min ( minpos , rv . end ) ; if ( rv . start > rv . end ) { maxpos = std :: max ( maxpos , rv . end ) ; } else { maxpos = std :: max ( maxpos , rv . start ) ; maxpos = std :: max ( maxpos , rv . end ) ; } } std :: string ref = f . query ( chr , minpos , maxpos ) ; if ( ( signed ) ref . size ( ) != maxpos - minpos + 1 ) { error ( " " , ref . c_str ( ) , minpos , maxpos ) ; } out . resize ( in . size ( ) + 1 ) ; out [ 0 ] = ref ; for ( size_t i = 0 ; i < in . size ( ) ; ++ i ) { int64_t refstart = in [ i ] . start - minpos ; int64_t reflen = in [ i ] . end - in [ i ] . start + 1 ; if ( reflen == ( signed ) ref . size ( ) && refstart == 0 ) { out [ i + 1 ] = in [ i ] . alt ; } else { out [ i + 1 ] = ref ; out [ i + 1 ] . replace ( refstart , reflen , in [ i ] . alt ) ; } if ( out [ i + 1 ] . size ( ) == 0 ) { out [ i + 1 ] = " " ; } } }
Convert a list of RefVar records to allele strings
Convert a list of RefVar records to allele strings
// insertions // ref allele for this one: // ref.substr(in[i].start - minpos, in[i].end - in[i].start + 1); // create alt allele by replacing