Commit 304c9e88 authored by RomainFeron's avatar RomainFeron
Browse files

Simplified output in process function

parent 4f714804
#include "output.h"
void output_process(std::string& output_file_path, std::vector<std::string>& individuals, std::unordered_map<std::string, std::unordered_map<std::string, uint16_t>>& results, uint min_depth) {
/* Input:
* - Path to an output file
* - A list of individual names
* - A matrix of results [Individual: [Sequence, Coverage]]
* Output:
* - A matrix of depth [Individual: [Sequence, Coverage]]
*/
FILE* output_file;
output_file = fopen(output_file_path.c_str(), "w");
uint id = 0;
// Comment lines
std::fprintf(output_file, "#Number of markers : %i\n", static_cast<int>(results.size()));
// Header
std::fprintf(output_file, "id\tsequence");
for (auto i: individuals) {
std::fprintf(output_file, "\t%s", i.c_str());
}
std::fprintf(output_file, "\n");
bool print = false;
// Fill line by line
for (auto r: results) {
for (auto i: r.second) {
if (i.second >= min_depth) {
print = true;
break;
}
}
if (print) {
std::fprintf(output_file, "%i\t%s", id, r.first.c_str());
for (auto i: individuals) {
std::fprintf(output_file, "\t%i", r.second[i]);
}
std::fprintf(output_file, "\n");
++id;
}
print = false;
}
fclose(output_file);
}
void output_distrib_matrix(std::string& output_file_path, sd_table& results, uint n_group1, uint n_group2) {
/* Input:
......
......@@ -7,9 +7,6 @@
#include "stats.h"
#include "utils.h"
// Generate an output file for "process"
void output_process(std::string& output_file_path, std::vector<std::string>& individuals, std::unordered_map<std::string, std::unordered_map<std::string, uint16_t>>& results, uint min_depth);
// Generate an output file for "distrib" in matrix format
void output_distrib_matrix(std::string& output_file_path, sd_table& results, uint n_group1, uint n_group2);
......
......@@ -88,10 +88,42 @@ void process(Parameters& parameters) {
std::vector<std::string> individuals;
for (auto i: input_files) individuals.push_back(i.individual_name);
std::ofstream output_file;
output_file.open(parameters.output_file_path);
output_file << "#Number of markers : " << results.size() << "\n";
output_file << "id\tsequence";
for (auto& i: individuals) output_file << "\t" << i;
output_file << "\n";
std::cerr << "**Info: writing marker depths to output file" << std::endl;
uint id = 0;
uint64_t n_markers = results.size();
uint64_t log_tick = static_cast<uint64_t>(n_markers / 10);
bool print = true;
// Fill line by line
for (auto r: results) {
if (parameters.min_depth > 1) {
print = false;
for (auto i: r.second) {
if (i.second >= parameters.min_depth) {
print = true;
break;
}
}
}
// Generate the output file
output_process(parameters.output_file_path, individuals, results, parameters.min_depth);
if (print) {
output_file << id << "\t" << r.first;
for (auto i: individuals) output_file << "\t" << r.second[i];
output_file << "\n";
++id;
}
if (id % log_tick == 0) std::cerr << "**Info: wrote " << id / 1000 << " K. markers (" << 10 * id / log_tick << " %)" << std::endl;
}
}
......
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