ʻOhana
Population structure, admixture history, and selection using learning methods.
Public Types | Public Member Functions
jade::basic_rema< TChar > Class Template Reference

A template for a class that reduces columns of matrices given to it. The columns to keep are chosen at random, but their relative order is not changed. More...

#include <jade.rema.hpp>

+ Collaboration diagram for jade::basic_rema< TChar >:

Public Types

typedef TChar char_type
 A character. More...
 
typedef std::basic_istream< char_typeistream
 An input stream. More...
 
typedef std::basic_ostream< char_typeostream
 An output stream. More...
 

Public Member Functions

 basic_rema (jade::args &a)
 Initializes a new instance of the class, reading the command-line arguments. More...
 
void execute (istream &in, ostream &out)
 Executes the filter through the specified streams. More...
 

Detailed Description

template<typename TChar>
class jade::basic_rema< TChar >

A template for a class that reduces columns of matrices given to it. The columns to keep are chosen at random, but their relative order is not changed.

Definition at line 21 of file jade.rema.hpp.

Member Typedef Documentation

◆ char_type

template<typename TChar >
typedef TChar jade::basic_rema< TChar >::char_type

A character.

Definition at line 24 of file jade.rema.hpp.

◆ istream

template<typename TChar >
typedef std::basic_istream<char_type> jade::basic_rema< TChar >::istream

An input stream.

Definition at line 25 of file jade.rema.hpp.

◆ ostream

template<typename TChar >
typedef std::basic_ostream<char_type> jade::basic_rema< TChar >::ostream

An output stream.

Definition at line 26 of file jade.rema.hpp.

Constructor & Destructor Documentation

◆ basic_rema()

template<typename TChar >
jade::basic_rema< TChar >::basic_rema ( jade::args a)
inlineexplicit

Initializes a new instance of the class, reading the command-line arguments.

Parameters
aThe command-line arguments.

Definition at line 32 of file jade.rema.hpp.

34  : _engine ()
35  , _seed (_read_seed(a))
36  , _num_markers (_read_num_markers(a))
37  {
38  }

Member Function Documentation

◆ execute()

template<typename TChar >
void jade::basic_rema< TChar >::execute ( istream in,
ostream out 
)
inline

Executes the filter through the specified streams.

Parameters
inThe input stream.
outThe output stream.

Definition at line 43 of file jade.rema.hpp.

46  {
47  //
48  // Read the dimensions of the matrix; this must be successful for
49  // the first matrix.
50  //
51  size_t row_count, col_count;
52  if (!(in >> row_count >> col_count))
53  throw jade::error("error reading matrix dimensions");
54 
55  //
56  // Do not try to keep more markers than the number of columns in
57  // the input matrix.
58  //
59  const auto marker_count = std::min(col_count, _num_markers);
60 
61  //
62  // Using the appropriate seed, randomly shuffle a vector that
63  // contains all the possible indices of the matrix; then record a
64  // set of bits to mark the columns to keep.
65  //
66  std::vector<bool> filter_flags;
67  filter_flags.resize(col_count, true);
68  {
69  typedef std::vector<size_t> vector_type;
70  vector_type indices (col_count);
71  std::iota(indices.begin(), indices.end(), 0);
72  _engine.seed(_seed);
73  std::shuffle(indices.begin(), indices.end(), _engine);
74  indices.resize(marker_count);
75  for (const auto index : indices)
76  filter_flags[index] = false;
77  }
78 
79  //
80  // Filter the first matrix.
81  //
82  _filter(in, out, row_count, col_count, marker_count, filter_flags);
83 
84  //
85  // Attempt to read a row; if this fails, assume this is the end of
86  // the data (a discrete genotype matrix), but otherwise, require
87  // the column, require consistent dimensions, and then read the
88  // second matrix.
89  //
90  size_t r, c;
91  if (!(in >> r) && in.eof())
92  return;
93  if (!(in >> c))
94  throw jade::error("error reading second matrix dimensions");
95  if (r != row_count || c != col_count)
96  throw jade::error("inconsistent second matrix dimensions");
97 
98  out << char_type('\n');
99  _filter(in, out, row_count, col_count, marker_count, filter_flags);
100 
101  //
102  // Require the third matrix of a consistent size.
103  //
104  if (!(in >> r >> c))
105  throw jade::error("error reading third matrix dimensions");
106  if (r != row_count || c != col_count)
107  throw jade::error("inconsistent third matrix dimensions");
108 
109  out << char_type('\n');
110  _filter(in, out, row_count, col_count, marker_count, filter_flags);
111 
112  //
113  // Require the end of the data.
114  //
115  for (;;)
116  {
117  const auto ch = in.get();
118  if (ch < 0)
119  return;
120  if (!std::isspace(ch))
121  throw jade::error("unexpected symbol after matrix data");
122  }
123  }

The documentation for this class was generated from the following file:
jade::basic_rema::char_type
TChar char_type
A character.
Definition: jade.rema.hpp:24
jade::basic_error
A template for a class representing an exception thrown from this namespace.
Definition: jade.error.hpp:20