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

Added header to group loci output

parent e14f2962
......@@ -13,11 +13,12 @@ void group_loci(Parameters& parameters) {
int min_cov = parameters.get_value_from_name<int>(par) - 1; // -1 to compare with > instead of >= later
std::cout << " - Loading coverage matrix :\n" << std::endl;
std::vector<Locus> coverage_matrix = load_coverage_matrix(coverage_matrix_path, min_cov, true);
std::vector<std::string> header;
std::vector<Locus> coverage_matrix = load_coverage_matrix(coverage_matrix_path, min_cov, true, header);
par = "input_file_path";
std::string input_file_path = parameters.get_value_from_name<std::string>(par);
std::vector<Locus> sequences = load_coverage_matrix(input_file_path, 1, false);
std::vector<Locus> sequences = load_coverage_matrix(input_file_path, 1, false, header);
par = "max_distance";
int max_distance = parameters.get_value_from_name<int>(par) + 1; // +1 to compare with < instead of <= later
......@@ -37,12 +38,12 @@ void group_loci(Parameters& parameters) {
par = "output_file_path";
std::string output_file_path = parameters.get_value_from_name<std::string>(par);
output_group_loci(output_file_path, results);
output_group_loci(output_file_path, results, header);
}
std::vector<Locus> load_coverage_matrix(std::string& file_path, int min_cov, bool print) {
std::vector<Locus> load_coverage_matrix(std::string& file_path, int min_cov, bool print, std::vector<std::string>& header) {
/* Load a coverage matrix in memory
*/
......@@ -52,9 +53,10 @@ std::vector<Locus> load_coverage_matrix(std::string& file_path, int min_cov, boo
if (input_file) {
// First line is the header. The header is not used here.
// First line is the header. The header is used when printing the output.
std::string temp;
std::getline(input_file, temp);
if (print) header = split(temp,"\t");
temp = "";
// Define variables used to read the file
......
......@@ -16,7 +16,7 @@
void group_loci(Parameters& parameters);
// Load the coverage matrix in memory
std::vector<Locus> load_coverage_matrix(std::string& file_path, int min_cov, bool print);
std::vector<Locus> load_coverage_matrix(std::string& file_path, int min_cov, bool print, std::vector<std::string>& header);
// Pick the next sequence from the sequences vector and process it
void sequence_processor(std::vector<Locus>::iterator& sequence, std::vector<Locus>& sequences, std::vector<Locus>& coverage_matrix,
......
......@@ -79,19 +79,26 @@ void output_sex_distribution(std::string& output_file_path, std::unordered_map<u
void output_group_loci(std::string& output_file_path, std::unordered_map<std::string, std::vector<Locus>>& results) {
void output_group_loci(std::string& output_file_path, std::unordered_map<std::string, std::vector<Locus>>& results, std::vector<std::string>& header) {
/* Input:
* - Path to an output file
* - A matrix of loci [Sequence ID: [Associated sequences]]
* Output:
* - A table with following columns:
* Locus ID | Sequence ID | Sequence Status | Sequence | Cov Ind. 1 | Cov Ind. 2 ...
* Locus ID | Marker ID | Sequence | Origin | Cov Ind. 1 | Cov Ind. 2 ...
*/
std::ofstream output_file;
output_file.open(output_file_path);
output_file << "Locus" << "\t" << "Marker" << "\t" << "Sequence" << "\t" << "Origin" << "\t";
for (uint i=2; i<header.size(); ++i) {
output_file << header[i];
if (i < header.size() - 1) output_file << "\t";
}
output_file << "\n";
std::string seq_id;
uint locus_id = 0;
......
......@@ -13,4 +13,4 @@ void output_process_reads(std::string& output_file_path, std::vector<std::string
void output_sex_distribution(std::string& output_file_path, std::unordered_map<uint, std::unordered_map<uint, uint64_t>>& results, uint n_males, uint n_females);
// Create output file for the group_loci analysis
void output_group_loci(std::string& output_file_path, std::unordered_map<std::string, std::vector<Locus>>& results);
void output_group_loci(std::string& output_file_path, std::unordered_map<std::string, std::vector<Locus>>& results, std::vector<std::string>& header);
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