43 namespace population {
51 auto const pi_w_finite = std::isfinite( entry.
pi_within );
52 auto const pi_b_finite = std::isfinite( entry.
pi_between );
53 auto const pi_t_finite = std::isfinite( entry.
pi_total );
54 return pi_w_finite && pi_b_finite && pi_t_finite;
74 if( value_count_ == 0 ) {
75 throw std::runtime_error(
76 "FstCathedralAccumulator: Cannot dissipate with value_count_==0"
88 if( value_count_ == 0 ) {
96 switch( fst_estimator_ ) {
98 result = 1.0 - ( pi_within_sum_ / pi_total_sum_ );
102 result = 1.0 - ( pi_within_sum_ / pi_between_sum_ );
106 throw std::invalid_argument(
107 "FstCathedralAccumulator: Invalid FstPoolCalculatorUnbiased::Estimator"
116 pi_within_sum_ = 0.0;
117 pi_between_sum_ = 0.0;
126 std::string
const& chromosome,
129 std::vector<std::string>
const& sample_names
135 std::vector<FstCathedralPlotRecord> result;
136 result.resize( processor.
size() );
141 assert( sample_name_pairs.empty() || sample_name_pairs.size() == processor.
size() );
148 for(
size_t i = 0; i < result.size(); ++i ) {
149 auto& record = result[i];
151 record.chromosome_name = chromosome;
152 record.fst_estimator = fst_estimator;
155 if( !sample_name_pairs.empty() ) {
156 assert( sample_name_pairs.size() == result.size() );
157 record.sample_name_1 = std::move( sample_name_pairs[i].first );
158 record.sample_name_2 = std::move( sample_name_pairs[i].second );
163 record.title =
"Fst (" + fst_name +
")";
164 if( !record.sample_name_1.empty() && !record.sample_name_2.empty() ) {
165 record.title +=
" " + record.sample_name_1 +
" vs " + record.sample_name_2;
166 record.plot_name = record.sample_name_1 +
"." + record.sample_name_2;
168 record.plot_name =
"plot";
170 if( !record.chromosome_name.empty() ) {
171 record.title +=
", chromosome: " + record.chromosome_name;
179 std::vector<FstCathedralPlotRecord>& records,
185 assert( processor.
size() == records.size() );
186 for(
size_t i = 0; i < processor.
size(); ++i ) {
190 throw std::runtime_error(
191 "In compute_fst_cathedral_records_for_chromosome(): "
192 "Invalid FstPoolCalculator that is not FstPoolCalculatorUnbiased"
201 throw std::runtime_error(
202 "In compute_fst_cathedral_records_for_chromosome(): "
203 "Invalid FstPoolCalculator that is not using WindowAveragePolicy::kSum"
212 auto const pis = fst_calc->get_pi_values();
213 records[i].entries.emplace_back(
214 position, pis.pi_within, pis.pi_between, pis.pi_total
223 std::vector<std::string>
const& sample_names,
224 std::shared_ptr<genesis::sequence::SequenceDict>
const& sequence_dict
232 std::string
const chromosome = iterator->chromosome;
234 chromosome, processor, fst_estimator, sample_names
236 assert( result.size() == processor.
size() );
241 while( iterator && iterator->chromosome == chromosome ) {
244 auto const& variant = *iterator;
249 if( variant.position <= cur_pos ) {
250 throw std::runtime_error(
251 "Unsorted positions in input: On chromosome \"" + chromosome +
"\", position " +
256 cur_pos = variant.position;
265 if( sequence_dict && sequence_dict->
contains( chromosome )) {
266 cur_pos = sequence_dict->
get( chromosome ).
length;
268 for(
auto& data : result ) {
269 data.chromosome_length = cur_pos;
279 std::vector<std::string>
const& sample_names,
280 std::shared_ptr<genesis::sequence::SequenceDict>
const& sequence_dict
283 std::vector<FstCathedralPlotRecord> result;
286 auto it = iterator.
begin();
289 it, processor, fst_estimator, sample_names, sequence_dict
291 assert( chr_result.size() == processor.
size() );
294 result.reserve( result.size() + chr_result.size() );
295 for(
size_t i = 0; i < chr_result.size(); ++i ) {
296 result.push_back( std::move( chr_result[i] ));
299 assert( it == iterator.
end() );
316 auto& obj = document.get_object();
318 obj[
"sampleName1"] = JsonDocument::string( record.
sample_name_1 );
319 obj[
"sampleName2"] = JsonDocument::string( record.
sample_name_2 );
320 obj[
"fstEstimator"] = JsonDocument::string( fst_name );
321 obj[
"entryCount"] = JsonDocument::number_unsigned( record.
entries.size() );