src/c++/lib/variant/Variant.cpp
/**
 * Append coverage values to JSON value
 *
 * This will append to arrays like this:
 *
 * {
 *    "ref": <ref-matching depth>
 *    "ref:FWD": <...>
 *    "other": non-ref-matching
 *    ...
 * }
 *
 * @param coords coordinate system on the graph to add position information
 * @param node_name which node name to write + use for the Graph coordinates
 * @param coverage coverage JSON. If entries are present already, this function will append
 */
Append coverage values to JSON value
This will append to arrays like this.



@param coords coordinate system on the graph to add position information
@param node_name which node name to write + use for the Graph coordinates
@param coverage coverage JSON. If entries are present already, this function will append
Append coverage values to JSON value This will append to arrays like this . @param coords coordinate system on the graph to add position information @param node_name which node name to write + use for the Graph coordinates @param coverage coverage JSON . If entries are present already this function will append
void VariantCandidateList::appendCoverage(
    graphtools::GraphCoordinates const& coords, std::string const& node_name, Json::Value& coverage) const
{
    static const std::list<std::string> fields = {
        "cpos",      "node",      "offset", "base",     "ref",      "ref:FWD", "ref:REV",    "other",
        "other:FWD", "other:REV", "wref",   "wref:FWD", "wref:REV", "wother",  "wother:FWD", "wother:REV",
    };
    auto s = static_cast<size_t>(-1);
    for (auto const& f : fields)
    {
        if (coverage.isMember(f))
        {
            if (s == static_cast<size_t>(-1))
            {
                s = coverage.size();
            }
            else
            {
                assert(s == coverage.size());
            }
        }
        else
        {
            coverage[f] = Json::Value(Json::ValueType::arrayValue);
            if (s == static_cast<size_t>(-1))
            {
                s = 0;
            }
            else
            {
                assert(s == 0);
            }
        }
    }
    auto node_start = coords.canonicalPos(node_name);
    for (auto pos = static_cast<size_t>(0); pos < _impl->reference.size(); ++pos)
    {
        auto const& ref_pileup = getRefPileup(static_cast<int>(pos));
        auto const& other_pileup = getNonrefPileup(static_cast<int>(pos));
        coverage["cpos"].append((Json::Value::UInt64)node_start + pos);
        coverage["node"].append(node_name);
        coverage["offset"].append((Json::UInt64)pos);
        coverage["base"].append(std::string(1, (char)_impl->reference[pos]));
        coverage["ref"].append(ref_pileup.stranded_DP[0] + ref_pileup.stranded_DP[1]);
        coverage["ref:FWD"].append(ref_pileup.stranded_DP[0]);
        coverage["ref:REV"].append(ref_pileup.stranded_DP[1]);
        coverage["other"].append(other_pileup.stranded_DP[0] + other_pileup.stranded_DP[1]);
        coverage["other:FWD"].append(other_pileup.stranded_DP[0]);
        coverage["other:REV"].append(other_pileup.stranded_DP[1]);
        coverage["wref"].append(ref_pileup.qual_weighted_DP[0] + ref_pileup.qual_weighted_DP[1]);
        coverage["wref:FWD"].append(ref_pileup.qual_weighted_DP[0]);
        coverage["wref:REV"].append(ref_pileup.qual_weighted_DP[1]);
        coverage["wother"].append(other_pileup.qual_weighted_DP[0] + other_pileup.qual_weighted_DP[1]);
        coverage["wother:FWD"].append(other_pileup.qual_weighted_DP[0]);
        coverage["wother:REV"].append(other_pileup.qual_weighted_DP[1]);
    }
}
void VariantCandidateList :: appendCoverage ( graphtools :: GraphCoordinates const & coords , std :: string const & node_name , Json :: Value & coverage ) const { static const std :: list < std :: string > fields = { " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , } ; auto s = static_cast < size_t > ( -1 ) ; for ( auto const & f : fields ) { if ( coverage . isMember ( f ) ) { if ( s == static_cast < size_t > ( -1 ) ) { s = coverage . size ( ) ; } else { assert ( s == coverage . size ( ) ) ; } } else { coverage [ f ] = Json :: Value ( Json :: ValueType :: arrayValue ) ; if ( s == static_cast < size_t > ( -1 ) ) { s = 0 ; } else { assert ( s == 0 ) ; } } } auto node_start = coords . canonicalPos ( node_name ) ; for ( auto pos = static_cast < size_t > ( 0 ) ; pos < _impl -> reference . size ( ) ; ++ pos ) { auto const & ref_pileup = getRefPileup ( static_cast < int > ( pos ) ) ; auto const & other_pileup = getNonrefPileup ( static_cast < int > ( pos ) ) ; coverage [ " " ] . append ( ( Json :: Value :: UInt64 ) node_start + pos ) ; coverage [ " " ] . append ( node_name ) ; coverage [ " " ] . append ( ( Json :: UInt64 ) pos ) ; coverage [ " " ] . append ( std :: string ( 1 , ( char ) _impl -> reference [ pos ] ) ) ; coverage [ " " ] . append ( ref_pileup . stranded_DP [ 0 ] + ref_pileup . stranded_DP [ 1 ] ) ; coverage [ " " ] . append ( ref_pileup . stranded_DP [ 0 ] ) ; coverage [ " " ] . append ( ref_pileup . stranded_DP [ 1 ] ) ; coverage [ " " ] . append ( other_pileup . stranded_DP [ 0 ] + other_pileup . stranded_DP [ 1 ] ) ; coverage [ " " ] . append ( other_pileup . stranded_DP [ 0 ] ) ; coverage [ " " ] . append ( other_pileup . stranded_DP [ 1 ] ) ; coverage [ " " ] . append ( ref_pileup . qual_weighted_DP [ 0 ] + ref_pileup . qual_weighted_DP [ 1 ] ) ; coverage [ " " ] . append ( ref_pileup . qual_weighted_DP [ 0 ] ) ; coverage [ " " ] . append ( ref_pileup . qual_weighted_DP [ 1 ] ) ; coverage [ " " ] . append ( other_pileup . qual_weighted_DP [ 0 ] + other_pileup . qual_weighted_DP [ 1 ] ) ; coverage [ " " ] . append ( other_pileup . qual_weighted_DP [ 0 ] ) ; coverage [ " " ] . append ( other_pileup . qual_weighted_DP [ 1 ] ) ; } }
Append coverage values to JSON value
 This will append to arrays like this:
Append coverage values to JSON value This will append to arrays like this :
// make sure sizes are the same + arrays are present