src/c++/lib/genotyping/GraphGenotyper.cpp
/**
 * @return set of genotypes for all alignments that were added
 */
@return set of genotypes for all alignments that were added
@return set of genotypes for all alignments that were added
Json::Value GraphGenotyper::getGenotypes()
{
    runGenotyping();
    Json::Value result = _impl->basic_info;
    auto& samples = result["samples"];
    for (const auto& samplename : _impl->samplenames)
    {
        samples[samplename]["breakpoints"] = Json::objectValue;
    }
    map<string, GenotypeSet> genotypeSets; 
    for (size_t isample = 0; isample < _impl->samplenames.size(); ++isample)
    {
        const string& samplename = _impl->samplenames[isample];
        const BreakpointMap& breakpoints = _impl->breakpoint_maps[isample];
        static const std::vector<std::string> no_alleles;
        static const Genotype empty_genotype = Genotype();
        for (const auto& breakpoint : breakpoints)
        {
            const std::string& breakpointname = breakpoint.first;
            auto& this_set = genotypeSets[breakpointname];
            auto gt_it = _impl->graph_genotypes.find(std::make_pair(samplename, breakpointname));
            if (gt_it != _impl->graph_genotypes.end())
            {
                const auto& allele_names = alleleNames();
                this_set.add(allele_names, gt_it->second);
                samples[samplename]["breakpoints"][breakpointname] = Json::objectValue;
                auto& breakpoint_json = samples[samplename]["breakpoints"][breakpointname];
                breakpoint_json["gt"] = gt_it->second.toJson(allele_names);
                const auto breakpoint_it = _impl->breakpoint_maps[isample].find(breakpointname);
                if (breakpoint_it != _impl->breakpoint_maps[isample].end())
                {
                    breakpoint_json["counts"] = Json::objectValue;
                    breakpoint_json["counts"]["edges"] = Json::objectValue;
                    breakpoint_json["counts"]["alleles"] = Json::objectValue;
                    for (const auto& bp_edgename : breakpoint_it->second.edgeNames())
                    {
                        breakpoint_json["counts"]["edges"][bp_edgename] = breakpoint_it->second.getCount(bp_edgename);
                    }
                    for (const auto& bp_allelename : breakpoint_it->second.canonicalAlleleNames())
                    {
                        breakpoint_json["counts"]["alleles"][bp_allelename]
                            = breakpoint_it->second.getCount(bp_allelename);
                    }
                }
            }
            else
            {
                this_set.add(no_alleles, empty_genotype);
            }
        }
        auto gt_it = _impl->graph_genotypes.find(std::make_pair(samplename, ""));
        auto& this_set = genotypeSets[""];
        if (gt_it != _impl->graph_genotypes.end())
        {
            const auto& allele_names = alleleNames();
            this_set.add(allele_names, gt_it->second);
            samples[samplename]["gt"] = gt_it->second.toJson(allele_names);
        }
        else
        {
            this_set.add(no_alleles, empty_genotype);
            samples[samplename]["gt"] = empty_genotype.toJson(no_alleles);
        }
    }
    if (_impl->samplenames.size() > 1)
    {
        result["population"] = Json::objectValue;
        auto& pop = result["population"];
        for (auto& iset : genotypeSets)
        {
            PopulationStatistics ps(iset.second);
            if (iset.first.empty())
            {
                pop = ps.toJson();
            }
            else
            {
                if (!pop.isMember("breakpoints"))
                {
                    pop["breakpoints"] = Json::objectValue;
                }
                pop["breakpoints"][iset.first] = ps.toJson();
            }
        }
    }
    return result;
}
Json :: Value GraphGenotyper :: getGenotypes ( ) { runGenotyping ( ) ; Json :: Value result = _impl -> basic_info ; auto & samples = result [ " " ] ; for ( const auto & samplename : _impl -> samplenames ) { samples [ samplename ] [ " " ] = Json :: objectValue ; } map < string , GenotypeSet > genotypeSets ; for ( size_t isample = 0 ; isample < _impl -> samplenames . size ( ) ; ++ isample ) { const string & samplename = _impl -> samplenames [ isample ] ; const BreakpointMap & breakpoints = _impl -> breakpoint_maps [ isample ] ; static const std :: vector < std :: string > no_alleles ; static const Genotype empty_genotype = Genotype ( ) ; for ( const auto & breakpoint : breakpoints ) { const std :: string & breakpointname = breakpoint . first ; auto & this_set = genotypeSets [ breakpointname ] ; auto gt_it = _impl -> graph_genotypes . find ( std :: make_pair ( samplename , breakpointname ) ) ; if ( gt_it != _impl -> graph_genotypes . end ( ) ) { const auto & allele_names = alleleNames ( ) ; this_set . add ( allele_names , gt_it -> second ) ; samples [ samplename ] [ " " ] [ breakpointname ] = Json :: objectValue ; auto & breakpoint_json = samples [ samplename ] [ " " ] [ breakpointname ] ; breakpoint_json [ " " ] = gt_it -> second . toJson ( allele_names ) ; const auto breakpoint_it = _impl -> breakpoint_maps [ isample ] . find ( breakpointname ) ; if ( breakpoint_it != _impl -> breakpoint_maps [ isample ] . end ( ) ) { breakpoint_json [ " " ] = Json :: objectValue ; breakpoint_json [ " " ] [ " " ] = Json :: objectValue ; breakpoint_json [ " " ] [ " " ] = Json :: objectValue ; for ( const auto & bp_edgename : breakpoint_it -> second . edgeNames ( ) ) { breakpoint_json [ " " ] [ " " ] [ bp_edgename ] = breakpoint_it -> second . getCount ( bp_edgename ) ; } for ( const auto & bp_allelename : breakpoint_it -> second . canonicalAlleleNames ( ) ) { breakpoint_json [ " " ] [ " " ] [ bp_allelename ] = breakpoint_it -> second . getCount ( bp_allelename ) ; } } } else { this_set . add ( no_alleles , empty_genotype ) ; } } auto gt_it = _impl -> graph_genotypes . find ( std :: make_pair ( samplename , " " ) ) ; auto & this_set = genotypeSets [ " " ] ; if ( gt_it != _impl -> graph_genotypes . end ( ) ) { const auto & allele_names = alleleNames ( ) ; this_set . add ( allele_names , gt_it -> second ) ; samples [ samplename ] [ " " ] = gt_it -> second . toJson ( allele_names ) ; } else { this_set . add ( no_alleles , empty_genotype ) ; samples [ samplename ] [ " " ] = empty_genotype . toJson ( no_alleles ) ; } } if ( _impl -> samplenames . size ( ) > 1 ) { result [ " " ] = Json :: objectValue ; auto & pop = result [ " " ] ; for ( auto & iset : genotypeSets ) { PopulationStatistics ps ( iset . second ) ; if ( iset . first . empty ( ) ) { pop = ps . toJson ( ) ; } else { if ( ! pop . isMember ( " " ) ) { pop [ " " ] = Json :: objectValue ; } pop [ " " ] [ iset . first ] = ps . toJson ( ) ; } } } return result ; }
@return set of genotypes for all alignments that were added
@return set of genotypes for all alignments that were added
// produce genotypes // sample->breakpoints to breakpoint->samples. for popluation statistics // initialize blank GT // print breakpoint genotypes (breakpoint_maps doesn't have "" breakpoint) // output read counts // print whole variant genotypes // print population statistics for more than one sample