mapgd  0.4
A program for the Maximum-likelihood analysis of population genomic data.
 All Data Structures Functions Variables Friends Groups Pages
plink_pheno.h
1 #ifndef _PLINK_PHENO_H_
2 #define _PLINK_PHENO_H_
3 
4 #include <iostream>
5 #include <cfloat>
6 #include <iomanip>
7 #include <vector>
8 
9 #include "external-file.h"
10 #include "external-data.h"
11 
12 #include "typedef.h"
13 #include "datatypes.h"
14 #include "phenotype.h"
15 #include "error_codes.h"
16 
17 enum Binary { missing, unaffected, affected};
18 enum Sex { unknown, male, female};
19 
20 template <typename T>
22 {
23  public:
24  uint32_t family_id;
25  uint32_t individual_id;
26  uint32_t maternal_id;
27  uint32_t paternal_id;
28  size_t n_values;
29  Sex sex;
30  T *values;
31 
32  Plink_record()
33  {
34  n_values=0;
35  values=NULL;
36  }
37 
38  Plink_record(size_t n)
39  {
40  n_values=n;
41  values=new T[n_values];
42  }
43 
44  void
45  resize(size_t n)
46  {
47  if(n_values!=n)
48  {
49  if (values!=NULL)
50  {
51  delete values;
52  values=NULL;
53  }
54  n_values=n;
55  values=new T[n_values];
56  }
57  }
58 
59  ~Plink_record()
60  {
61  if (values!=NULL)
62  {
63  delete values;
64  values=NULL;
65  }
66  }
67 
68  Plink_record& operator =(const Plink_record& rhs)
69  {
70  if (&rhs != this)
71  {
72  family_id=rhs.family_id;
73  individual_id=rhs.individual_id;
74  maternal_id=rhs.maternal_id;
75  paternal_id=rhs.paternal_id;
76  sex=rhs.sex;
77  if (n_values!=rhs.n_values)
78  {
79  if (values!=NULL)
80  {
81  delete values;
82  }
83  values=new T[n_values];
84  n_values=rhs.n_values;
85  }
86  memcpy(values, rhs.values, n_values*sizeof(T) );
87  }
88  return *this;
89  }
90 };
91 
92 class Plink_data : public External_data {
93 private:
94  Plink_record <real_t> record_;
95  std::vector <std::string > sample_names_;
96  real_t missing_value;
97  size_t n_samples_;
98 public:
99  Plink_data(const size_t &);
100 
101  Plink_data(){};
102 
103  void set_family_id(const std::string &);
104  void set_individual_id(const std::string &);
105  int set_values(const std::vector <std::string> &);
106  int set_values(const real_t *);
107  size_t trait_size(void) const;
108 
109  void put (const Data *, ...);
110  void get (Data *, ...) const;
111 
112  void put (const Phenotype &);
113  void get (Phenotype &) const;
114 
115  std::vector<std::string> get_sample_names (void) const;
116 };
117 
118 //'FID' and 'IID
119 
120 class Plink_file : public External_file <Plink_data> {
121 private:
122  using Base_file::in_;
123  using Base_file::out_;
124  using Base_file::open_;
127 public:
128  void open(const std::ios_base::openmode &);
129  void open(const char *, const std::ios_base::openmode &);
130  void close(void);
131  void read (Plink_data &);
132  void write (const Plink_data &);
133  void write_header (const Plink_data &);
134  Plink_data read_header();
135 };
136 
137 #endif
void open_no_extention(const char *, const std::ios::openmode &)
The function that opens a indexed_file (if file).
Definition: map_file.cc:59
An interface for reading and writing data specified outside of mapgd.
Definition: external-file.h:36
char delim_column_
The delimiter which separates columns.
Definition: map_file.h:77
std::istream * in_
All data is read from in.
Definition: map_file.h:85
An interface used to read/write data from outside of mapgd.
Definition: external-data.h:17
std::ostream * out_
All data is written is written to out.
Definition: map_file.h:86
bool open_
indicates whether the iostream opened succesfully
Definition: map_file.h:60
A class which can be written as flat text file or into an SQL database.
Definition: data.h:34
Phenotype data.
Definition: phenotype.h:21