Commit f4b39ca8 authored by Romain Feron's avatar Romain Feron
Browse files

Added min_individuals and max_individuals parameters to subset

parent 96d147c7
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.2.1, 2018-02-09T17:20:03. -->
<!-- Written by QtCreator 4.2.1, 2018-02-16T16:20:42. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
......@@ -14,7 +14,7 @@ struct Parameters {
// Initialize all possible parameters to be used in the analyses
// Arguments: name, help message, flag, default value, type, internal type, value, required
// Flags : -h, -f, -d, -o, -u, -t, -c, -p, -b, -a, -m, --min-males, --min-females, --max-males, --max-females
// Flags : -h, -f, -d, -o, -u, -t, -c, -p, -b, -a, -m, --min-males, --min-females, --max-males, --max-females, --min-individuals
std::vector<Parameter> list {Parameter("help", "Prints this message", "-h", "0", "bool", "bool", "", false),
Parameter("input_file_path", "Path to an input file", "-f", "", "string", "ifile", "", true),
Parameter("input_dir_path", "Path to an input directory", "-d", "", "string", "dir", "", true),
......@@ -29,7 +29,9 @@ struct Parameters {
Parameter("min_males", "Minimum number of males in the subset", "--min-males", "0", "int", "int", "", false),
Parameter("min_females", "Minimum number of females in the subset", "--min-females", "0", "int", "int", "", false),
Parameter("max_males", "Maximum number of males in the subset", "--max-males", "n.males", "int", "int", "", false),
Parameter("max_females", "Maximum number of females in the subset", "--max-females", "n.females", "int", "int", "", false)
Parameter("max_females", "Maximum number of females in the subset", "--max-females", "n.females", "int", "int", "", false),
Parameter("min_individuals", "Minimum number of individuals in the subset (overrides sex parameters)", "--min-individuals", "0", "int", "int", "", false),
Parameter("max_individuals", "Maxmimum number of individuals in the subset (overrides sex parameters)", "--max-individuals", "n.individual", "int", "int", "", false),
};
......
......@@ -115,12 +115,16 @@ void RadSex::parse() {
for (auto i: popmap) { if (i.second) ++_n_males; else ++_n_females;}
std::string n_males = std::to_string(_n_males);
std::string n_females = std::to_string(_n_females);
std::string n_individuals = std::to_string(popmap.size());
std::string par = "max_males";
option = this->parameters.get_from_name(par);
if (option.value == option.default_value) this->parameters.set_value_from_name(par, n_males);
par = "max_females";
option = this->parameters.get_from_name(par);
if (option.value == option.default_value) this->parameters.set_value_from_name(par, n_females);
par = "max_individuals";
option = this->parameters.get_from_name(par);
if (option.value == option.default_value) this->parameters.set_value_from_name(par, n_individuals);
}
this->parameters.simple_print(this->analysis.options);
......
......@@ -31,7 +31,7 @@ class RadSex {
process_reads)},
{"subset", Analysis("subset", "Extract a subset of the coverage matrix",
std::vector<std::string> {"input_file_path", "output_file_path", "popmap_file_path", "min_cov",
"min_males", "min_females", "max_males", "max_females"},
"min_males", "min_females", "max_males", "max_females", "min_individuals", "max_individuals"},
subset)},
{"frequencies", Analysis("frequencies", "Calculate the frequency of markers in the population",
std::vector<std::string> {"input_file_path", "output_file_path", "min_cov"},
......
......@@ -29,6 +29,12 @@ void subset(Parameters& parameters) {
par = "max_females";
int max_females = parameters.get_value_from_name<int>(par) + 1; // +1 allows comparison with < instead of <=
par = "min_individuals";
int min_individuals = parameters.get_value_from_name<int>(par) - 1; // -1 allows comparison with > instead of >=
par = "max_individuals";
int max_individuals = parameters.get_value_from_name<int>(par) + 1; // +1 allows comparison with < instead of <=
if (input_file) {
par = "output_file_path";
......@@ -45,6 +51,7 @@ void subset(Parameters& parameters) {
// Map with column number --> index of sex_count (0 = male, 1 = female, 2 = no sex)
std::unordered_map<uint, uint> sex_columns;
// Detection of individuals is based on the popmap, so individuals without sex should still be in the popmap
for (uint i=0; i<line.size(); ++i) {
if (popmap.find(line[i]) != popmap.end()) {
if (popmap[line[i]]) {
......@@ -62,6 +69,7 @@ void subset(Parameters& parameters) {
std::string temp_line;
uint k = 0, field_n = 0;
int sex_count[3] = {0, 0, 0}; // Index: 0 = male, 1 = female, 2 = no sex
int n_individuals = 0;
do {
......@@ -84,7 +92,9 @@ void subset(Parameters& parameters) {
break;
case '\n': // New line (also a new field)
if (sex_columns[field_n] != 2 and std::stoi(temp) > min_cov) ++sex_count[sex_columns[field_n]]; // Increment the appropriate counter
if (sex_count[0] > min_males and sex_count[0] < max_males and sex_count[1] > min_females and sex_count[1] < max_females) {
n_individuals = sex_count[0] + sex_count[1] + sex_count[2];
if (sex_count[0] > min_males and sex_count[0] < max_males and sex_count[1] > min_females and sex_count[1] < max_females and
n_individuals > min_individuals and n_individuals < max_individuals) {
output_file << temp_line << "\n";
}
// Reset variables
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment