A library for working with phylogenetic and population genetic data.
v0.27.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-2022 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 <lczech@carnegiescience.edu>
20  Department of Plant Biology, Carnegie Institution For Science
21  260 Panama Street, Stanford, CA 94305, USA
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( BaseCounts const& bs, std::ostream& os )
44 {
45  os << bs.a_count << ":" << bs.t_count << ":" << bs.c_count << ":" << bs.g_count;
46  os << ":" << bs.n_count << ":" << bs.d_count;
47  return os;
48 }
49 
50 std::ostream& to_sync( Variant const& var, std::ostream& os )
51 {
52  os << var.chromosome << "\t" << var.position << "\t" << var.reference_base;
53  for( auto const& bs : var.samples ) {
54  os << "\t";
55  to_sync( bs, os );
56  }
57  os << "\n";
58  return os;
59 }
60 
61 } // namespace population
62 } // namespace genesis
genesis::population::BaseCounts::d_count
size_t d_count
Count of all deleted (*) nucleotides that are present in the sample.
Definition: base_counts.hpp:84
genesis::population::BaseCounts::t_count
size_t t_count
Count of all T nucleotides that are present in the sample.
Definition: base_counts.hpp:74
genesis::population::Variant::position
size_t position
Definition: variant.hpp:65
genesis::population::BaseCounts::g_count
size_t g_count
Count of all G nucleotides that are present in the sample.
Definition: base_counts.hpp:69
sync_common.hpp
genesis::population::BaseCounts::a_count
size_t a_count
Count of all A nucleotides that are present in the sample.
Definition: base_counts.hpp:59
genesis::population::Variant::reference_base
char reference_base
Definition: variant.hpp:66
genesis::population::BaseCounts::n_count
size_t n_count
Count of all N (undetermined/any) nucleotides that are present in the sample.
Definition: base_counts.hpp:79
genesis::population::Variant::samples
std::vector< BaseCounts > samples
Definition: variant.hpp:69
genesis::population::Variant
A single variant at a position in a chromosome, along with BaseCounts for a set of samples.
Definition: variant.hpp:62
genesis::population::BaseCounts::c_count
size_t c_count
Count of all C nucleotides that are present in the sample.
Definition: base_counts.hpp:64
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::BaseCounts
One set of nucleotide base counts, for example for a given sample that represents a pool of sequenced...
Definition: base_counts.hpp:54
genesis::population::to_sync
std::ostream & to_sync(BaseCounts const &bs, std::ostream &os)
Output a BaseCounts instance to a stream in the PoPoolation2 sync format.
Definition: sync_common.cpp:43
genesis::population::Variant::chromosome
std::string chromosome
Definition: variant.hpp:64