Skip to content

Commit 4ec9390

Browse files
clang changes
Signed-off-by: AdityaPandeyCN <adityapand3y666@gmail.com>
1 parent 4cdb6f3 commit 4ec9390

File tree

3 files changed

+57
-42
lines changed

3 files changed

+57
-42
lines changed

src/ramcore/SamToNTuple.cxx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
#include <cstdint>
77
#include <cstdio>
88
#include <map>
9-
#include <memory> // NOLINT(misc-include-cleaner) - used for std::unique_ptr
9+
#include <memory>
1010
#include <mutex>
1111
#include <string>
12-
#include <thread> // NOLINT(misc-include-cleaner) - used for std::thread
13-
#include <unordered_set> // NOLINT(misc-include-cleaner) - used for std::unordered_set
14-
#include <vector> // NOLINT(misc-include-cleaner) - used for std::vector
12+
#include <thread>
13+
#include <unordered_set>
14+
#include <vector>
1515

1616
#include <ROOT/RNTupleModel.hxx>
1717
#include <ROOT/RNTupleWriter.hxx>
@@ -25,8 +25,8 @@
2525
#include <TROOT.h>
2626

2727
void samtoramntuple(const char *datafile, const char *treefile, bool index,
28-
bool split, // NOLINT(misc-use-internal-linkage) - public API function
29-
bool cache, int compression_algorithm, uint32_t quality_policy)
28+
bool split, bool cache, int compression_algorithm,
29+
uint32_t quality_policy) // NOLINT(misc-use-internal-linkage) - public API function
3030
{
3131
(void)split;
3232
(void)cache;
@@ -300,3 +300,4 @@ void samtoramntuple_split_by_chromosome(const char *datafile, const char *output
300300
}
301301
}
302302
}
303+

test/ramcoretests.cxx

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,43 @@
1313

1414
#include "../tools/ramview.cxx"
1515

16+
namespace {
17+
1618
class ramcoreTest : public ::testing::Test {
1719
protected:
18-
void SetUp() override // NOLINT(readability-convert-member-functions-to-static) - virtual method in Google Test
20+
const int m_num_reads_for_test = 100;
21+
const std::string m_samFile = "samexample.sam";
22+
const std::string m_ttreeFile = "test_ttree.root";
23+
const std::string m_rntupleFile = "test_rntuple.root";
24+
25+
void SetUp() override
1926
{
20-
const int num_reads_for_test = 100;
21-
GenerateSAMFile("samexample.sam", num_reads_for_test);
27+
GenerateSAMFile(m_samFile.c_str(), m_num_reads_for_test);
2228

23-
std::remove("test_ttree.root");
24-
std::remove("test_rntuple.root");
29+
std::remove(m_ttreeFile.c_str());
30+
std::remove(m_rntupleFile.c_str());
2531
}
2632

27-
void TearDown() override // NOLINT(readability-convert-member-functions-to-static) - virtual method in Google Test
33+
void TearDown() override
2834
{
29-
std::remove("test_ttree.root");
30-
std::remove("test_rntuple.root");
35+
std::remove(m_ttreeFile.c_str());
36+
std::remove(m_rntupleFile.c_str());
3137
}
3238
};
3339

34-
TEST_F(ramcoreTest, ConversionProducesEqualEntries) // NOLINT(misc-use-internal-linkage) - TEST_F is a macro
40+
TEST_F(ramcoreTest, ConversionProducesEqualEntries)
3541
{
36-
const char *samFile = "samexample.sam";
37-
const char *ttreeFile = "test_ttree.root";
38-
const char *rntupleFile = "test_rntuple.root";
39-
40-
samtoram(samFile, ttreeFile, true, true, true, 1, 0);
41-
samtoramntuple(samFile, rntupleFile, true, true, true, 505, 0);
42+
samtoram(m_samFile.c_str(), m_ttreeFile.c_str(), true, true, true, 1, 0);
43+
samtoramntuple(m_samFile.c_str(), m_rntupleFile.c_str(), true, true, true, 505, 0);
4244

43-
auto ft = std::unique_ptr<TFile>(TFile::Open(ttreeFile));
45+
auto ft = std::unique_ptr<TFile>(TFile::Open(m_ttreeFile.c_str()));
4446
ASSERT_TRUE(ft && !ft->IsZombie()) << "Failed to open TTree file";
4547

4648
auto ttree = dynamic_cast<TTree *>(ft->Get("RAM"));
4749
ASSERT_NE(ttree, nullptr) << "Failed to get TTree";
4850
Long64_t ttreeEntries = ttree->GetEntries();
4951

50-
auto reader = ROOT::RNTupleReader::Open("RAM", rntupleFile);
52+
auto reader = ROOT::RNTupleReader::Open("RAM", m_rntupleFile.c_str());
5153
ASSERT_NE(reader, nullptr) << "Failed to open RNTuple";
5254
Long64_t rntupleEntries = reader->GetNEntries();
5355

@@ -58,14 +60,19 @@ TEST_F(ramcoreTest, ConversionProducesEqualEntries) // NOLINT(misc-use-internal-
5860
const char *region = "chrM:1-100000000";
5961

6062
testing::internal::CaptureStdout();
61-
ramview(ttreeFile, region, /*cache=*/true, /*perfstats=*/false, /*perfstatsfilename=*/nullptr);
62-
std::string ramview_output = testing::internal::GetCapturedStdout();
63+
ramview(m_ttreeFile.c_str(), region, /*cache=*/true, /*perfstats=*/false, /*perfstatsfilename=*/nullptr);
64+
std::string ramview_output{};
65+
ramview_output = testing::internal::GetCapturedStdout();
6366

6467
testing::internal::CaptureStdout();
65-
ramntupleview(rntupleFile, region, /*cache=*/true, /*perfstats=*/false, /*perfstatsfilename=*/nullptr);
66-
std::string ramntupleview_output = testing::internal::GetCapturedStdout();
68+
ramntupleview(m_rntupleFile.c_str(), region, /*cache=*/true, /*perfstats=*/false, /*perfstatsfilename=*/nullptr);
69+
std::string ramntupleview_output{};
70+
ramntupleview_output = testing::internal::GetCapturedStdout();
6771

6872
EXPECT_TRUE(ramview_output.find("Found") != std::string::npos);
6973
EXPECT_TRUE(ramntupleview_output.find("Found") != std::string::npos);
7074
EXPECT_TRUE(ramntupleview_output.find("records in region") != std::string::npos);
7175
}
76+
77+
} // namespace
78+

tools/samtoramntuple.cxx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
#include "ramcore/SamToNTuple.h"
22
#include "rntuple/RAMNTupleRecord.h"
3+
#include <algorithm>
4+
#include <cstring>
35
#include <exception>
46
#include <iostream>
57
#include <string>
6-
#include <cstring>
78
#include <vector>
89

910
int main(int argc, char *argv[])
1011
{
11-
if (argc < 2) {
12-
std::cout << "Usage: " << argv[0]
13-
<< " <input.sam> [output]\n"; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
12+
std::vector<std::string> args;
13+
args.reserve(static_cast<size_t>(argc));
14+
std::for_each_n(argv, static_cast<size_t>(argc),
15+
[&](char *arg) { args.emplace_back(arg); });
16+
17+
if (args.size() < 2) {
18+
std::cout << "Usage: " << args[0]
19+
<< " <input.sam> [output]\n";
1420
std::cout << "Options:\n";
1521
std::cout << " -split Split by chromosome\n";
1622
std::cout << " -only <chr> When used with -split, emit only the specified chromosome (repeatable)\n";
@@ -20,34 +26,34 @@ int main(int argc, char *argv[])
2026
return 1;
2127
}
2228

23-
const char *input = argv[1]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
29+
const char *input = args[1].c_str();
2430
const char *output = nullptr;
2531

2632
bool do_split = false;
2733
bool do_index = true;
2834
uint32_t quality_mode = RAMNTupleRecord::kPhred33;
2935
std::vector<std::string> only_chromosomes;
3036

31-
for (int i = 2; i < argc; i++) {
32-
std::string arg = argv[i]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
37+
for (int i = 2; i < static_cast<int>(args.size()); i++) {
38+
std::string arg = args[static_cast<size_t>(i)];
3339
if (arg == "-split") {
3440
do_split = true;
3541
} else if (arg == "-only") {
36-
if (i + 1 < argc) {
42+
if (i + 1 < static_cast<int>(args.size())) {
3743

38-
only_chromosomes.emplace_back(argv[++i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
44+
only_chromosomes.emplace_back(args[static_cast<size_t>(++i)]);
3945
} else {
4046
std::cerr << "-only expects a chromosome name\n";
4147
return 1;
4248
}
4349
} else if (arg == "-noindex") {
4450
do_index = false;
45-
} else if (arg == "-illumina") {
46-
quality_mode = RAMNTupleRecord::kIlluminaBinning;
47-
} else if (arg == "-dropqual") { // NOLINT(bugprone-branch-clone) - different values assigned
48-
quality_mode = RAMNTupleRecord::kDrop;
49-
} else if (arg[0] != '-') {
50-
output = argv[i]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
51+
} else if (arg == "-illumina" || arg == "-dropqual") {
52+
quality_mode = (arg == "-illumina")
53+
? RAMNTupleRecord::kIlluminaBinning
54+
: RAMNTupleRecord::kDrop;
55+
} else if (!arg.empty() && arg[0] != '-') {
56+
output = args[static_cast<size_t>(i)].c_str();
5157
}
5258
}
5359

@@ -78,3 +84,4 @@ int main(int argc, char *argv[])
7884

7985
return 0;
8086
}
87+

0 commit comments

Comments
 (0)