From c02d4b219d25cb81754e813b3ccb0fb2e675e977 Mon Sep 17 00:00:00 2001 From: maciejdlugosz Date: Tue, 20 Feb 2024 18:30:30 +0100 Subject: [PATCH 1/2] Compilation and code reuse improvements. --- kmc_CLI/kmc.cpp | 7 +++++-- kmc_api/kmer_api.h | 10 +++++----- py_kmc_api/libs/pybind11/include/pybind11/attr.h | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/kmc_CLI/kmc.cpp b/kmc_CLI/kmc.cpp index 15e579e..693a3a3 100644 --- a/kmc_CLI/kmc.cpp +++ b/kmc_CLI/kmc.cpp @@ -5,6 +5,7 @@ #include #include #include +#include using namespace std; struct CLIParams @@ -36,7 +37,7 @@ void usage() << " -sm - use strict memory mode (memory limit from -m switch will not be exceeded)\n" << " -hc - count homopolymer compressed k-mers (approximate and experimental)\n" << " -p - signature length (5, 6, 7, 8, 9, 10, 11); default: 9\n" - << " -f - input in FASTA format (-fa), FASTQ format (-fq), multi FASTA (-fm) or BAM (-fbam) or KMC(-fkmc); default: FASTQ\n" + << " -f - input in FASTA format (-fa), FASTQ format (-fq), multi FASTA (-fm) or BAM (-fbam) or KMC (-fkmc); default: FASTQ\n" << " -ci - exclude k-mers occurring less than times (default: 2)\n" << " -cs - maximal value of a counter (default: 255)\n" << " -cx - exclude k-mers occurring more of than times (default: 1e9)\n" @@ -264,7 +265,9 @@ bool parse_parameters(int argc, char* argv[], Params& params) input_file_names.push_back(s); in.close(); - std::random_shuffle(input_file_names.begin(), input_file_names.end()); + std::random_device rd; + std::mt19937 gen(rd()); + std::shuffle(input_file_names.begin(), input_file_names.end(), gen); } stage1Params.SetInputFiles(input_file_names); diff --git a/kmc_api/kmer_api.h b/kmc_api/kmer_api.h index a5a1ebe..4f99aae 100644 --- a/kmc_api/kmer_api.h +++ b/kmc_api/kmer_api.h @@ -99,7 +99,7 @@ class CKmerAPI // ---------------------------------------------------------------------------------- template - inline void to_string_impl(RandomAccessIterator iter) + inline void to_string_impl(RandomAccessIterator iter) const { uchar *byte_ptr; uchar c; @@ -431,7 +431,7 @@ class CKmerAPI // Convert kmer into string (an alphabet ACGT) // RET : string kmer //----------------------------------------------------------------------- - inline std::string to_string() + inline std::string to_string() const { std::string string_kmer; string_kmer.resize(kmer_length); @@ -442,14 +442,14 @@ class CKmerAPI // Convert kmer into string (an alphabet ACGT). The function assumes enough memory was allocated // OUT : str - string kmer. //----------------------------------------------------------------------- - inline void to_string(char *str) + inline void to_string(char *str) const { to_string_impl(str); str[kmer_length] = '\0'; }; - inline void to_long(std::vector& kmer) + inline void to_long(std::vector& kmer) const { kmer.resize(no_of_rows); uint32 offset = 62 - ((kmer_length - 1 + byte_alignment) & 31) * 2; @@ -473,7 +473,7 @@ class CKmerAPI // Convert kmer into string (an alphabet ACGT) // OUT : str - string kmer //----------------------------------------------------------------------- - inline void to_string(std::string &str) + inline void to_string(std::string &str) const { str.resize(kmer_length); to_string_impl(str.begin()); diff --git a/py_kmc_api/libs/pybind11/include/pybind11/attr.h b/py_kmc_api/libs/pybind11/include/pybind11/attr.h index 8732cfe..9981b2e 100644 --- a/py_kmc_api/libs/pybind11/include/pybind11/attr.h +++ b/py_kmc_api/libs/pybind11/include/pybind11/attr.h @@ -11,6 +11,7 @@ #pragma once #include "cast.h" +#include NAMESPACE_BEGIN(PYBIND11_NAMESPACE) From 193dd82e392fc9791d645f2216043aaf3eb963c3 Mon Sep 17 00:00:00 2001 From: maciejdlugosz Date: Tue, 5 Mar 2024 22:21:51 +0100 Subject: [PATCH 2/2] Keep reproducibility of a workflow. --- kmc_CLI/kmc.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kmc_CLI/kmc.cpp b/kmc_CLI/kmc.cpp index 693a3a3..d32ed10 100644 --- a/kmc_CLI/kmc.cpp +++ b/kmc_CLI/kmc.cpp @@ -265,8 +265,7 @@ bool parse_parameters(int argc, char* argv[], Params& params) input_file_names.push_back(s); in.close(); - std::random_device rd; - std::mt19937 gen(rd()); + std::mt19937 gen; std::shuffle(input_file_names.begin(), input_file_names.end(), gen); } stage1Params.SetInputFiles(input_file_names);