<commit_before>#include <assert.h>
#include <algorithm>
#include <kstring.h>
#include <vcf.h>
#include "BCFSerialize.h"
#include "residuals.h"

using namespace std;

namespace GLnexus {

static string concat(const std::vector<std::string>& samples) {
    return std::accumulate(samples.begin(), samples.end(), std::string(),
                    [](const std::string& a, const std::string& b) -> std::string {
                        return a + (a.length() > 0 ? "\t" : "") + b;
                    } );
}


Status residuals_gen_record(const unified_site& site,
                            const bcf_hdr_t *gl_hdr,
                            const bcf1_t *gl_call,
                            const std::vector<DatasetSiteInfo> &sites,
                            const MetadataCache& cache,
                            const std::vector<std::string>& samples,
                            std::string &ynode) {
    Status s;
    YAML::Emitter out;
    out << YAML::BeginMap;
    out << YAML::Key << "input";
    out << YAML::BeginMap;
    out << YAML::Key << "body";
    out << YAML::BeginSeq;

    // for each dataset
    for (const auto& ds_info : sites) {
        ostringstream records_text;
        // line with sample name(s)
        for (int i = 0; i < bcf_hdr_nsamples(gl_hdr); i++) {
            if (i > 0) {
                records_text << '\t';
            }
            records_text << bcf_hdr_int2id(gl_hdr, BCF_DT_SAMPLE, i);
        }
        // gVCF records, one per line
        for (const auto& rec : ds_info.records) {
            records_text << "\n" << *(bcf1_to_string(ds_info.header.get(), rec.get()));
        }
        out << YAML::BeginMap;
        out << YAML::Key << ds_info.name;
        out << YAML::Value << YAML::Literal << records_text.str();
        out << YAML::EndMap;
    }
    out << YAML::EndSeq;
    out << YAML::EndMap;

    // write the unified site
    out << YAML::Key << "unified_site";<commit_msg>residuals: correct header emitted with lost input records.<commit_after>#include <assert.h>
#include <algorithm>
#include <kstring.h>
#include <vcf.h>
#include "BCFSerialize.h"
#include "residuals.h"

using namespace std;

namespace GLnexus {

static string concat(const std::vector<std::string>& samples) {
    return std::accumulate(samples.begin(), samples.end(), std::string(),
                    [](const std::string& a, const std::string& b) -> std::string {
                        return a + (a.length() > 0 ? "\t" : "") + b;
                    } );
}


Status residuals_gen_record(const unified_site& site,
                            const bcf_hdr_t *gl_hdr,
                            const bcf1_t *gl_call,
                            const std::vector<DatasetSiteInfo> &sites,
                            const MetadataCache& cache,
                            const std::vector<std::string>& samples,
                            std::string &ynode) {
    Status s;
    YAML::Emitter out;
    out << YAML::BeginMap;
    out << YAML::Key << "input";
    out << YAML::BeginMap;
    out << YAML::Key << "body";
    out << YAML::BeginSeq;

    // for each dataset
    for (const auto& ds_info : sites) {
        ostringstream records_text;
        // line with sample name(s)
        for (int i = 0; i < bcf_hdr_nsamples(ds_info.header); i++) {
            if (i > 0) {
                records_text << '\t';
            }
            records_text << bcf_hdr_int2id(ds_info.header, BCF_DT_SAMPLE, i);
        }
        // gVCF records, one per line
        for (const auto& rec : ds_info.records) {
            records_text << "\n" << *(bcf1_to_string(ds_info.header.get(), rec.get()));
        }
        out << YAML::BeginMap;
        out << YAML::Key << ds_info.name;
        out << YAML::Value << YAML::Literal << records_text.str();
        out << YAML::EndMap;
    }
    out << YAML::EndSeq;
    out << YAML::EndMap;

    // write the unified site
    out << YAML::Key << "unified_site";
{'fraction_non_alphanumeric': 0.14397972116603294, 'fraction_numerical': 0.003041825095057034, 'mean_word_length': 1.9164818920916482, 'pattern_counts': {'":': 0, '<': 107, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '183086', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1224, 'n_words': 290}