A library for working with phylogenetic and population genetic data.
v0.32.0
sync_common.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2024 Lucas Czech
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Contact:
19  Lucas Czech <lucas.czech@sund.ku.dk>
20  University of Copenhagen, Globe Institute, Section for GeoGenetics
21  Oster Voldgade 5-7, 1350 Copenhagen K, Denmark
22 */
23 
32 
33 #include <iostream>
34 #include <stdexcept>
35 
36 namespace genesis {
37 namespace population {
38 
39 // =================================================================================================
40 // PoPoolation2 Synchronized File Helper Functions
41 // =================================================================================================
42 
43 std::ostream& to_sync( SampleCounts const& bs, std::ostream& os, bool use_status_and_missing )
44 {
45  if( use_status_and_missing && ! bs.status.passing() ) {
46  os << ".:.:.:.:.:.";
47  } else {
48  os << bs.a_count << ":" << bs.t_count << ":" << bs.c_count << ":" << bs.g_count;
49  os << ":" << bs.n_count << ":" << bs.d_count;
50  }
51  return os;
52 }
53 
54 std::ostream& to_sync( Variant const& var, std::ostream& os, bool use_status_and_missing )
55 {
56  os << var.chromosome << "\t" << var.position << "\t" << var.reference_base;
57  if( use_status_and_missing && ! var.status.passing() ) {
58  for( auto const& bs : var.samples ) {
59  (void) bs;
60  os << "\t";
61  os << ".:.:.:.:.:.";
62  }
63  } else {
64  for( auto const& bs : var.samples ) {
65  os << "\t";
66  to_sync( bs, os, use_status_and_missing );
67  }
68  }
69  os << "\n";
70  return os;
71 }
72 
73 } // namespace population
74 } // namespace genesis
genesis::population::SampleCounts
One set of nucleotide sample counts, for example for a given sample that represents a pool of sequenc...
Definition: sample_counts.hpp:56
genesis::population::SampleCounts::a_count
size_type a_count
Count of all A nucleotides that are present in the sample.
Definition: sample_counts.hpp:66
genesis::population::Variant::position
size_t position
Definition: variant.hpp:74
sync_common.hpp
genesis::population::Variant::reference_base
char reference_base
Definition: variant.hpp:79
genesis::population::SampleCounts::status
FilterStatus status
Status to indicate whether any applied filters failed to pass.
Definition: sample_counts.hpp:96
genesis::population::SampleCounts::t_count
size_type t_count
Count of all T nucleotides that are present in the sample.
Definition: sample_counts.hpp:81
genesis::population::to_sync
std::ostream & to_sync(SampleCounts const &bs, std::ostream &os, bool use_status_and_missing)
Output a SampleCounts instance to a stream in the PoPoolation2 sync format.
Definition: sync_common.cpp:43
genesis::population::SampleCounts::n_count
size_type n_count
Count of all N (undetermined/any) nucleotides that are present in the sample.
Definition: sample_counts.hpp:86
genesis::population::SampleCounts::c_count
size_type c_count
Count of all C nucleotides that are present in the sample.
Definition: sample_counts.hpp:71
genesis::population::Variant
A single variant at a position in a chromosome, along with SampleCounts for a set of samples.
Definition: variant.hpp:65
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::population::FilterStatus::passing
bool passing() const
Definition: filter_status.hpp:75
genesis::population::Variant::samples
std::vector< SampleCounts > samples
Definition: variant.hpp:82
genesis::population::SampleCounts::d_count
size_type d_count
Count of all deleted (*) nucleotides that are present in the sample.
Definition: sample_counts.hpp:91
genesis::population::Variant::status
FilterStatus status
Definition: variant.hpp:76
genesis::population::Variant::chromosome
std::string chromosome
Definition: variant.hpp:73
genesis::population::SampleCounts::g_count
size_type g_count
Count of all G nucleotides that are present in the sample.
Definition: sample_counts.hpp:76