Commit 91c28d79 authored by Romain Feron's avatar Romain Feron
Browse files

Implemented utility function to print containers, fixed header not printed in signif / subset

parent d89e7597
......@@ -18,7 +18,7 @@ void depth(Parameters& parameters) {
MarkersQueue markers_queue;
std::mutex queue_mutex;
std::thread parsing_thread(table_parser, std::ref(parameters), std::ref(popmap), std::ref(markers_queue), std::ref(queue_mutex), std::ref(header), std::ref(parsing_ended), true, true);
std::thread parsing_thread(table_parser, std::ref(parameters), std::ref(popmap), std::ref(markers_queue), std::ref(queue_mutex), std::ref(parsing_ended), true, true);
std::thread processing_thread(processor, std::ref(markers_queue), std::ref(parameters), std::ref(queue_mutex), std::ref(depths), std::ref(n_markers), std::ref(parsing_ended), BATCH_SIZE, popmap.n_individuals);
parsing_thread.join();
......
#include "depth_table.h"
void table_parser(Parameters& parameters, const Popmap& popmap, MarkersQueue& markers_queue, std::mutex& queue_mutex, Header& header, bool& parsing_ended, bool no_seq, bool no_group) {
void table_parser(Parameters& parameters, const Popmap& popmap, MarkersQueue& markers_queue, std::mutex& queue_mutex, bool& parsing_ended, bool no_seq, bool no_group) {
std::ifstream input_file;
input_file.open(parameters.markers_table_path);
......@@ -12,6 +12,7 @@ void table_parser(Parameters& parameters, const Popmap& popmap, MarkersQueue& ma
}
Header header;
std::string temp = "";
// First line (in depth table) is a comment with number of markers in the table
......@@ -85,7 +86,7 @@ void table_parser(Parameters& parameters, const Popmap& popmap, MarkersQueue& ma
++marker_n;
if (marker_n % TMP_QUEUE_SIZE == 0) { // Merge temporary queue with shared queue after 1000 blocks
do {
marker_queue_size = markers_queue.markers.size();
marker_queue_size = static_cast<uint>(markers_queue.markers.size());
if (marker_queue_size > MAX_QUEUE_SIZE) std::this_thread::sleep_for(std::chrono::microseconds(10));
} while (marker_queue_size > MAX_QUEUE_SIZE);
queue_mutex.lock();
......
......@@ -51,7 +51,7 @@ struct MarkersQueue {
typedef std::vector<std::string> Header;
void table_parser(Parameters& parameters, const Popmap& popmap, MarkersQueue& markers_queue, std::mutex& queue_mutex, Header& header, bool& parsing_ended, bool no_seq = true, bool no_group = false);
void table_parser(Parameters& parameters, const Popmap& popmap, MarkersQueue& markers_queue, std::mutex& queue_mutex, bool& parsing_ended, bool no_seq = true, bool no_group = false);
std::vector<Marker> get_batch(MarkersQueue& markers_queue, std::mutex& queue_mutex, ulong batch_size=1000);
......
......@@ -15,7 +15,7 @@ void distrib(Parameters& parameters) {
log("RADSex distrib started");
log("Comparing groups \"" + parameters.group1 + "\" and \"" + parameters.group2 + "\"");
Header header;
Header header = get_header(parameters.markers_table_path);
sd_table results;
......@@ -23,7 +23,7 @@ void distrib(Parameters& parameters) {
MarkersQueue markers_queue;
std::mutex queue_mutex;
std::thread parsing_thread(table_parser, std::ref(parameters), std::ref(popmap), std::ref(markers_queue), std::ref(queue_mutex), std::ref(header), std::ref(parsing_ended), true, false);
std::thread parsing_thread(table_parser, std::ref(parameters), std::ref(popmap), std::ref(markers_queue), std::ref(queue_mutex), std::ref(parsing_ended), true, false);
std::thread processing_thread(processor, std::ref(markers_queue), std::ref(parameters), std::ref(queue_mutex), std::ref(results), std::ref(parsing_ended), BATCH_SIZE);
parsing_thread.join();
......
......@@ -21,7 +21,7 @@ void freq(Parameters& parameters) {
std::vector<uint32_t> frequencies(n_individuals, 0);
std::thread parsing_thread(table_parser, std::ref(parameters), std::ref(popmap), std::ref(markers_queue), std::ref(queue_mutex), std::ref(header), std::ref(parsing_ended), true, true);
std::thread parsing_thread(table_parser, std::ref(parameters), std::ref(popmap), std::ref(markers_queue), std::ref(queue_mutex), std::ref(parsing_ended), true, true);
std::thread processing_thread(processor, std::ref(markers_queue), std::ref(queue_mutex), std::ref(frequencies), std::ref(parsing_ended), BATCH_SIZE);
parsing_thread.join();
......
......@@ -27,7 +27,7 @@ void map(Parameters& parameters) {
log("RADSex map started");
log("Comparing groups \"" + parameters.group1 + "\" and \"" + parameters.group2 + "\"");
Header header;
Header header = get_header(parameters.markers_table_path);
std::vector<AlignedMarker> aligned_markers;
......@@ -40,7 +40,7 @@ void map(Parameters& parameters) {
// Check if bwa index files exist for the genome and build index if it's missing
build_bwa_index(parameters);
std::thread parsing_thread(table_parser, std::ref(parameters), std::ref(popmap), std::ref(markers_queue), std::ref(queue_mutex), std::ref(header), std::ref(parsing_ended), false, false);
std::thread parsing_thread(table_parser, std::ref(parameters), std::ref(popmap), std::ref(markers_queue), std::ref(queue_mutex), std::ref(parsing_ended), false, false);
std::thread processing_thread(processor, std::ref(markers_queue), std::ref(parameters), std::ref(popmap), std::ref(queue_mutex), std::ref(aligned_markers), std::ref(parsing_ended), BATCH_SIZE);
parsing_thread.join();
......
......@@ -14,7 +14,7 @@ void signif(Parameters& parameters) {
log("RADSex signif started");
log("Comparing groups \"" + parameters.group1 + "\" and \"" + parameters.group2 + "\"");
Header header;
Header header = get_header(parameters.markers_table_path);
std::vector<Marker> candidate_markers;
uint n_markers;
......@@ -23,7 +23,7 @@ void signif(Parameters& parameters) {
MarkersQueue markers_queue;
std::mutex queue_mutex;
std::thread parsing_thread(table_parser, std::ref(parameters), std::ref(popmap), std::ref(markers_queue), std::ref(queue_mutex), std::ref(header), std::ref(parsing_ended), false, false);
std::thread parsing_thread(table_parser, std::ref(parameters), std::ref(popmap), std::ref(markers_queue), std::ref(queue_mutex), std::ref(parsing_ended), false, false);
std::thread processing_thread(processor, std::ref(markers_queue), std::ref(popmap), std::ref(parameters), std::ref(queue_mutex), std::ref(candidate_markers), std::ref(n_markers), std::ref(parsing_ended), BATCH_SIZE);
parsing_thread.join();
......@@ -31,6 +31,8 @@ void signif(Parameters& parameters) {
std::ofstream output_file = open_output(parameters.output_file_path);
if (not parameters.output_fasta) output_file << print_list(header, "\t") << "\n";
if (not parameters.disable_correction) parameters.signif_threshold /= n_markers; // Bonferroni correction: divide threshold by number of tests
// Second pass: filter markers with threshold corrected p < 0.05
......
......@@ -13,7 +13,7 @@ void subset(Parameters& parameters) {
log("RADSex subset started");
log("Comparing groups \"" + parameters.group1 + "\" and \"" + parameters.group2 + "\"");
Header header;
Header header = get_header(parameters.markers_table_path);
bool parsing_ended = false;
MarkersQueue markers_queue;
......@@ -21,7 +21,9 @@ void subset(Parameters& parameters) {
std::ofstream output_file = open_output(parameters.output_file_path);
std::thread parsing_thread(table_parser, std::ref(parameters), std::ref(popmap), std::ref(markers_queue), std::ref(queue_mutex), std::ref(header), std::ref(parsing_ended), false, false);
if (not parameters.output_fasta) output_file << print_list(header, "\t") << "\n";
std::thread parsing_thread(table_parser, std::ref(parameters), std::ref(popmap), std::ref(markers_queue), std::ref(queue_mutex), std::ref(parsing_ended), false, false);
std::thread processing_thread(processor, std::ref(markers_queue), std::ref(popmap), std::ref(parameters), std::ref(queue_mutex), std::ref(output_file), std::ref(parsing_ended), BATCH_SIZE);
parsing_thread.join();
......
......@@ -163,11 +163,11 @@ inline std::string get_runtime(const std::chrono::steady_clock::time_point t_beg
inline void log_progress_bar(uint64_t& n_processed_markers, const uint32_t marker_processed_tick, char symbol = '#', uint16_t ticks = 50) {
uint tick_size = 100 / ticks;;
uint tick_size = 100 / ticks;
if (++n_processed_markers % (tick_size * marker_processed_tick) != 0) return; // Not a step
uint16_t progress = n_processed_markers / (tick_size * marker_processed_tick);
uint16_t progress = static_cast<uint16_t>(n_processed_markers / (tick_size * marker_processed_tick));
std::string bar = "Progress: [";
......@@ -182,3 +182,20 @@ inline void log_progress_bar(uint64_t& n_processed_markers, const uint32_t marke
log(bar, LOG_INFO, false);
}
template<typename T>
inline std::string print_list(const T& list, const std::string& sep = ", ") {
uint n = 0;
std::string output = "";
for (auto& field: list) {
output += field;
if (++n < list.size()) output += sep;
}
return output;
}
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