src/c++/lib/genotyping/Genotype.cpp
// output allele name instead of indexes
output allele name instead of indexes
output allele name instead of indexes
Json::Value Genotype::toJson(vector<string> const& allele_names) const
{
    Json::Value json_result;
    json_result["GT"] = toString(&allele_names);
    if (!gl.empty())
    {
        json_result["GL"] = Json::Value();
        for (size_t i = 0; i < gl.size(); ++i)
        {
            string gl_str = allele_names[gl_name[i][0]];
            for (size_t j = 1; j < gl_name[i].size(); j++)
            {
                gl_str += "/" + allele_names[gl_name[i][j]];
            }
            json_result["GL"][gl_str] = gl[i];
        }
    }
    if (gq != -1)
    {
        json_result["GQ"] = gq;
    }
    if (!allele_fractions.empty())
    {
        json_result["allele_fractions"] = Json::objectValue;
        assert(allele_names.size() == allele_fractions.size());
        for (size_t allele = 0; allele < allele_fractions.size(); ++allele)
        {
            const std::string& allele_name = allele_names[allele];
            const double& allele_fraction = allele_fractions[allele];
            json_result["allele_fractions"][allele_name] = allele_fraction;
        }
    }
    if (!filters.empty())
    {
        json_result["filters"] = Json::arrayValue;
        for (auto f : filters)
        {
            json_result["filters"].append(f);
        }
    }
    if (!gt.empty())
    {
        json_result["num_reads"] = num_reads;
        if (coverage_test_pvalue != -1)
        {
            json_result["coverage_test_pvalue"] = coverage_test_pvalue;
        }
    }
    return json_result;
}
Json :: Value Genotype :: toJson ( vector < string > const & allele_names ) const { Json :: Value json_result ; json_result [ " " ] = toString ( & allele_names ) ; if ( ! gl . empty ( ) ) { json_result [ " " ] = Json :: Value ( ) ; for ( size_t i = 0 ; i < gl . size ( ) ; ++ i ) { string gl_str = allele_names [ gl_name [ i ] [ 0 ] ] ; for ( size_t j = 1 ; j < gl_name [ i ] . size ( ) ; j ++ ) { gl_str += " " + allele_names [ gl_name [ i ] [ j ] ] ; } json_result [ " " ] [ gl_str ] = gl [ i ] ; } } if ( gq != -1 ) { json_result [ " " ] = gq ; } if ( ! allele_fractions . empty ( ) ) { json_result [ " " ] = Json :: objectValue ; assert ( allele_names . size ( ) == allele_fractions . size ( ) ) ; for ( size_t allele = 0 ; allele < allele_fractions . size ( ) ; ++ allele ) { const std :: string & allele_name = allele_names [ allele ] ; const double & allele_fraction = allele_fractions [ allele ] ; json_result [ " " ] [ allele_name ] = allele_fraction ; } } if ( ! filters . empty ( ) ) { json_result [ " " ] = Json :: arrayValue ; for ( auto f : filters ) { json_result [ " " ] . append ( f ) ; } } if ( ! gt . empty ( ) ) { json_result [ " " ] = num_reads ; if ( coverage_test_pvalue != -1 ) { json_result [ " " ] = coverage_test_pvalue ; } } return json_result ; }
output allele name instead of indexes
output allele name instead of indexes