ʻOhana
Population structure, admixture history, and selection using learning methods.
Data Structures | Public Types | Public Member Functions | Static Public Member Functions
jade::basic_neoscan< TValue > Class Template Reference

A template for a class implementing the neoscan algorithm. This algorithm scans for positive selection between ancient and modern data. It can take advantage of the dating for each individual ancient sample. More...

#include <jade.neoscan.hpp>

+ Collaboration diagram for jade::basic_neoscan< TValue >:

Data Structures

struct  output
 Output for one column. More...
 

Public Types

typedef TValue value_type
 The value type. More...
 
typedef basic_matrix< value_typematrix_type
 The matrix type. More...
 
typedef basic_verification< value_typeverification_type
 The verification type. More...
 
typedef basic_genotype_matrix< value_typegenotype_matrix_type
 The genotype matrix type. More...
 
typedef basic_genotype_matrix_factory< value_typegenotype_matrix_factory_type
 The genotype matrix factory type. More...
 

Public Member Functions

 basic_neoscan (const genotype_matrix_type &g, const matrix_type &q, const matrix_type &f, const matrix_type &years)
 Initializes a new instance of the class. Memory for the specified G, Q, and Fa matrices must remain valid for the lifetime of this instance. More...
 
template<typename TOutputAction >
void execute (const TOutputAction &output_action) const
 Executes the algorithm using the specified action for the output of each column. More...
 

Static Public Member Functions

static void run (args &a)
 Runs the program based on command-line arguments. More...
 

Detailed Description

template<typename TValue>
class jade::basic_neoscan< TValue >

A template for a class implementing the neoscan algorithm. This algorithm scans for positive selection between ancient and modern data. It can take advantage of the dating for each individual ancient sample.

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

Member Typedef Documentation

◆ genotype_matrix_factory_type

The genotype matrix factory type.

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

◆ genotype_matrix_type

template<typename TValue >
typedef basic_genotype_matrix<value_type> jade::basic_neoscan< TValue >::genotype_matrix_type

The genotype matrix type.

Definition at line 38 of file jade.neoscan.hpp.

◆ matrix_type

template<typename TValue >
typedef basic_matrix<value_type> jade::basic_neoscan< TValue >::matrix_type

The matrix type.

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

◆ value_type

template<typename TValue >
typedef TValue jade::basic_neoscan< TValue >::value_type

The value type.

Definition at line 29 of file jade.neoscan.hpp.

◆ verification_type

template<typename TValue >
typedef basic_verification<value_type> jade::basic_neoscan< TValue >::verification_type

The verification type.

Definition at line 35 of file jade.neoscan.hpp.

Constructor & Destructor Documentation

◆ basic_neoscan()

template<typename TValue >
jade::basic_neoscan< TValue >::basic_neoscan ( const genotype_matrix_type g,
const matrix_type q,
const matrix_type f,
const matrix_type years 
)
inline

Initializes a new instance of the class. Memory for the specified G, Q, and Fa matrices must remain valid for the lifetime of this instance.

Parameters
gThe G matrix.
qThe Q matrix.
fThe F matrix.
yearsThe years matrix.

Definition at line 89 of file jade.neoscan.hpp.

94  : _g (g)
95  , _q (q)
96  , _f (f)
97  , _y (_init_y(years, q))
98  , _f_j (f.get_height(), 1)
99  {
101  }
+ Here is the call graph for this function:

Member Function Documentation

◆ execute()

template<typename TValue >
template<typename TOutputAction >
void jade::basic_neoscan< TValue >::execute ( const TOutputAction &  output_action) const
inline

Executes the algorithm using the specified action for the output of each column.

Parameters
output_actionThe action to perform for the output; this function or lambda must take one argument of type, output.

Definition at line 112 of file jade.neoscan.hpp.

113  {
114  const auto J = _g.get_width();
115 
116  for (size_t j = 0; j < J; j++)
117  {
118  value_type col_min = 0;
119  value_type col_max = 0;
120  _f.get_min_max_column(j, col_min, col_max);
121 
122  const auto range_low = -col_max;
123  const auto range_high = value_type(1.0) - col_min;
124 
125  output out;
126  out.delta = value_type(0.0);
127  out.global_lle = _compute_lle_j(j, out.delta);
128  out.local_lle = out.global_lle;
129 
130  static const auto tol = value_type(0.000001);
131  static const auto phi = value_type(0.5 * (sqrt(5.0) + 1.0));
132 
133  const auto dr_phi = (range_high - range_low) / phi;
134 
135  auto a = range_low;
136  auto b = range_high;
137  auto c = range_high - dr_phi;
138  auto d = range_low + dr_phi;
139 
140  while (std::abs(c - d) > tol)
141  {
142  if (_compute_lle_j(j, c) > _compute_lle_j(j, d))
143  b = d;
144  else
145  a = c;
146 
147  c = b - (b - a) / phi;
148  d = a + (b - a) / phi;
149  }
150 
151  const auto gss_delta = value_type(0.5) * (a + b);
152  const auto gss_lle = _compute_lle_j(j, gss_delta);
153 
154  if (gss_lle > out.local_lle)
155  {
156  out.delta = gss_delta;
157  out.local_lle = gss_lle;
158  }
159 
160  output_action(out);
161  }
162  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

template<typename TValue >
static void jade::basic_neoscan< TValue >::run ( args a)
inlinestatic

Runs the program based on command-line arguments.

Parameters
aThe command-line arguments.

Definition at line 168 of file jade.neoscan.hpp.

169  {
170  const std::unique_ptr<genotype_matrix_type> g_ptr (
171  genotype_matrix_factory_type::create(a.pop<std::string>()));
172 
173  const matrix_type q (a.pop<std::string>());
174  const matrix_type f (a.pop<std::string>());
175  const matrix_type y (a.pop<std::string>());
176  a.validate_empty();
177 
178  std::cout << "d\tglobal_lle\tlocal_lle\tlle_ratio\n";
179 
180  const basic_neoscan neoscan (*g_ptr, q, f, y);
181 
182  neoscan.execute([](const output & out)
183  {
184  std::cout << out.to_string() << std::endl;
185  });
186  }
+ Here is the call graph for this function:

The documentation for this class was generated from the following file:
jade::basic_genotype_matrix_factory::create
static genotype_matrix_type * create(const std::string &path)
Creates a genotype matrix based on values from a file. This function determines what kind of genotype...
Definition: jade.genotype_matrix_factory.hpp:48
jade::basic_matrix::get_min_max_column
bool get_min_max_column(const size_t column, value_type &min, value_type &max) const
Returns the minimum and maximum elements in a column. If the matrix is empty, this method returns fal...
Definition: jade.matrix.hpp:686
jade::basic_genotype_matrix::get_width
virtual size_t get_width() const =0
jade::basic_neoscan::value_type
TValue value_type
The value type.
Definition: jade.neoscan.hpp:29
jade::basic_verification::validate_gqf_sizes
static bool validate_gqf_sizes(const genotype_matrix_type &g, const matrix_type &q, const matrix_type &f)
Validates the sizes of the G, Q, and F matrices and throws an exception if validation fails.
Definition: jade.verification.hpp:211
jade::basic_neoscan::matrix_type
basic_matrix< value_type > matrix_type
The matrix type.
Definition: jade.neoscan.hpp:32