mapgd  0.4
A program for the Maximum-likelihood analysis of population genomic data.
 All Data Structures Functions Variables Friends Groups Pages
locus.h
1 #ifndef LOCUS_H_
2 #define LOCUS_H_
3 
4 #include <iostream>
5 #include <vector>
6 
7 #include "quartet.h"
8 #include "base.h"
9 #include "stream_tools.h"
10 #include "data.h"
11 #include "file_index.h"
12 
13 /* This is the record stored in a pro file*/
14 class Locus : virtual public Indexed_data{
15 private:
16  //NOT READ READ/WRITE!!
17  std::vector <std::string> sample_names_;
18 
19  //READ READ/WRITE!!
20  using Indexed_data::abs_pos_;
21 
22  static const Registration registered;
23  static Data * create(const std::vector <std::string> & Columns){
24  return new Locus(Columns);
25  }
26  void write (std::ostream& out) const;
27  void read (std::istream& in);
28 public:
29  void write_binary (std::ostream& out) const;
30  void read_binary (std::istream& in);
31  /* BEGIN DATA BLOCK */
32  /* these need to be changed to private */
33  gt_t sorted_[5];
34  std::vector <quartet_t> sample;
35  Base ref;
36  /* END DATA BLOCK */
37 
38  static const gt_t default_order[5];
39 //public:
40 
41  Locus (const count_t &);
42  Locus ();
43  Locus (const std::vector<std::string> &);
44 
45  /*BASIC OPERATORS*/
46  Locus & operator=(const Locus&);
47  Locus & operator+=(const Locus&);
48  const Locus operator+(const Locus&) const;
51  const count_t getindex(count_t) const;
52 
53  count_t getcoverage(count_t) const;
54  count_t getcoverage(void) const;
55 
56  count_t getcount(count_t) const;
57  count_t getcount(count_t, count_t) const;
58 
59  void swap(count_t, count_t);
60  void sort(count_t);
61  void sort(void);
62 
63  /* \defgroup QUARTET Quartet
64  * The set of functions dealing with quartets
65  * @{
66  */
67  void set_quartet(const quartet_t &, const count_t &);
68  const quartet_t & get_quartet(const count_t &) const;
69  quartet_t & get_quartet(const count_t &);
70 
72  /* \defgroup MASKING Masking
73  * Functions which set or unset the masked flag, quartets which are
74  * masked are ignored by calculations, and are printed as 0's.
75  * @{
76  */
77  count_t maskedcount(void) const;
78  void maskall(void);
79  void unmaskall(void);
80  void mask(const std::vector <size_t> &);
81  void unmask(const std::vector <size_t> &);
82  void mask_low_cov(const count_t &dp);
83 
85  /* \defgroup DEPRICATED depricated
86  * Functions that were once used, but are no longer usful.
87  * @{
88  */
89  char getname( const count_t &) const;
90  char getname_gt( const count_t &) const;
91  count_t get_extraid(const size_t &) const;
92  void set_extraid(const count_t &, const size_t &);
93  /* this will definetly by dropped */
100 
101  void resize(const size_t &);
102 
103  /* \defgroup iterators Iterators
104  * Locus can return the iterators foir the quartets.
105  * @{
106  */
107  inline std::vector <quartet_t>::iterator begin(void) {return sample.begin();};
108 
110  inline std::vector <quartet_t>::iterator
111  end(void) {
112  return sample.end();
113  };
114 
116  inline std::vector <quartet_t>::const_iterator
117  cbegin(void) const {
118  return sample.cbegin();
119  };
120 
122  inline std::vector <quartet_t>::const_iterator
123  cend(void) const {
124  return sample.cend();
125  };
128  inline std::vector <std::string>
130  get_sample_names(void) const
131  {
132  return sample_names_;
133  };
134 
136  inline void
137  set_sample_names(const std::vector <std::string>& sample_names)
138  {
139  sample_names_=sample_names;
140  if (sample_names_.size()!=sample.size() ) sample.assign(sample_names_.size(), quartet() );
141  };
142 
143  /* \defgroup LOCUS_DATA Inherited members
144  * These members are inherited from Data
145  * @{
146  */
147  std::string header(void) const;
148  size_t size(void) const;
149 
150  static const std::string file_name;
151  static const std::string table_name;
152  static const bool binary;
153 
154  const std::string get_file_name(void) const;
155  const std::string get_table_name(void) const;
156  const bool get_binary(void) const;
157 
158  const std::string sql_header(void) const;
159  const std::string sql_column_names(void) const;
160  const std::string sql_values(void) const;
161 
162  void sql_read(std::istream &) override;
165  friend std::istream& mpileup (std::istream& in, Locus& x, const int &, const int &);
166  friend void scan(const Locus & site, const std::string &str, quartet_t &q);
167 };
168 
169 
170 #endif
std::vector< quartet_t >::const_iterator cend(void) const
Return an iterator to the quartet_t s stored at this Locus.
Definition: locus.h:122
A class converts human readable bases to bit flags.
Definition: base.h:16
const quartet_t & get_quartet(const count_t &) const
Returns the N'th quartet at the Locus.
Definition: locus.cc:253
void write(std::ostream &out) const
The write function must be defined in the child class.
Definition: locus.cc:280
void resize(const size_t &)
< Set the absolute position of the Locus.
Definition: locus.cc:267
std::vector< quartet_t >::iterator end(void)
Return an iterator to the quartet_t s stored at this Locus.
Definition: locus.h:110
A class that stores quartet information.
Definition: quartet.h:16
const std::string sql_column_names(void) const
Return the names of the columns.
Definition: locus.cc:407
Locus()
Locus is initialized to abs_pos_=0, id1=0, and set to contain 0 samples.
Definition: locus.cc:12
void unmaskall(void)
Unmask all lines.
Definition: locus.cc:97
std::vector< std::string > get_sample_names(void) const
names of the samples sequenced
Definition: locus.h:129
Data which has an absolute position.
Definition: data.h:144
std::vector< quartet_t > sample
The five bases A/C/G/T/N;.
Definition: locus.h:34
void set_extraid(const count_t &, const size_t &)
Set the extraid of the Locus. Just used to represent the reference call.
std::vector< quartet_t >::const_iterator cbegin(void) const
Return an iterator to the quartet_t s stored at this Locus.
Definition: locus.h:116
void swap(count_t, count_t)
Exchange the alleles.
Definition: locus.cc:184
count_t getcoverage(void) const
Returns total coverage.
Definition: locus.cc:231
std::vector< std::string > sample_names_
names of the samples sequenced.
Definition: locus.h:17
void sql_read(std::istream &) override
Reads the values...
Definition: locus.cc:412
char getname(const count_t &) const
Get the nucleotide represented by the count at the N'th indexed quartet_t.
count_t getcount(count_t) const
Returns the count of allele in all individuals in the population.
Definition: locus.cc:204
void set_abs_pos(const id1_t &)
Indexed data needs to associate each datum with a position in the genome.
Definition: data.cc:138
void unmask(const std::vector< size_t > &)
Unmask all lines.
Definition: locus.cc:116
gt_t sorted_[5]
an array to allow sorted access to quartets.
Definition: locus.h:33
void mask(const std::vector< size_t > &)
Mask all lines.
Definition: locus.cc:127
void set_quartet(const quartet_t &, const count_t &)
Sets the quartet_t array (unsorted).
Definition: locus.cc:246
void mask_low_cov(const count_t &dp)
Mask site with coverage stricktly lt dp;.
Definition: locus.cc:273
void read(std::istream &in)
The read function must be defined in the child class.
Definition: locus.cc:303
count_t maskedcount(void) const
Returns the count of the number of individuals that are masked.
Definition: locus.cc:136
const std::string sql_values(void) const
Return the values to be placed in columns.
Definition: locus.cc:430
id1_t get_abs_pos(void) const
Indexed data needs to associate each datum with a position in the genome.
Definition: data.cc:123
const count_t getindex(count_t) const
Returns the index of the alleles in order a sorted order.
Definition: locus.cc:197
count_t get_extraid(const size_t &) const
Get the extraid of the Locus. Used to represent the reference call.
A class which registers a child of Data in Data::new_data_.
Definition: data.h:222
void maskall(void)
Mask all lines.
Definition: locus.cc:107
const std::string sql_header(void) const
Return the names of the columns, along with variable type.
Definition: locus.cc:402
A class which can be written as flat text file or into an SQL database.
Definition: data.h:34
size_t size(void) const
The size of the class in bytes.
Definition: locus.cc:362
char getname_gt(const count_t &) const
Get the nucleotide represented by the count at the N'th indexed quartet_t, return * if the count equa...
Definition: locus.h:14
void sort(void)
Sort counts from most common to least common (among all non-masked sites).
Definition: locus.cc:144
void set_sample_names(const std::vector< std::string > &sample_names)
names of the samples sequenced.
Definition: locus.h:136