Skip to content

Commit

Permalink
Merge pull request #163 from GenSpectrum/staticAnalysis
Browse files Browse the repository at this point in the history
Reenable linter and code style standardization
  • Loading branch information
Taepper authored Jul 10, 2023
2 parents 20e1e99 + ed98d4c commit e0e2219
Show file tree
Hide file tree
Showing 180 changed files with 2,079 additions and 791 deletions.
4 changes: 1 addition & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ ContinuationIndentWidth: 3
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
PenaltyReturnTypeOnItsOwnLine: 1000
ReferenceAlignment: Left
PointerAlignment: Left
DerivePointerAlignment: false
QualifierAlignment: Left
4 changes: 3 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ Checks: >
clang-analyzer-cplusplus.NewDeleteLeaks,
-modernize-use-trailing-return-type,
-misc-non-private-member-variables-in-classes,
-misc-include-cleaner,
-google-readability-avoid-underscore-in-googletest-name,
-abseil-string-find-str-contains
-bugprone-easily-swappable-parameters
# TODO(someone): clean up misc-non-private-member-variables-in-classes and add option back in
# Not using google-readability-avoid-underscore-in-googletest-name because it also fails for test_name
# Not using abseil-string-find-str-contains because we don't want to include more libraries
Expand All @@ -34,6 +36,6 @@ CheckOptions:
- { key: readability-identifier-naming.TypeTemplateParameterIgnoredRegexp, value: expr-type }
- { key: readability-implicit-bool-conversion.AllowIntegerConditions, value: 1 }
- { key: readability-implicit-bool-conversion.AllowPointerConditions, value: 1 }
- { key: bugprone-easily-swappable-parameters.MinimumLength, value: 3 }
- { key: bugprone-easily-swappable-parameters.MinimumLength, value: 2 }

# readability-identifier-naming.TypeTemplateParameterIgnoredRegexp is workaround for error of clang-tidy with ubuntu (https://github.com/llvm/llvm-project/issues/46097)
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
!CMakeLists.txt
!build_with_conan.py
!conanprofile.docker
!conanprofile.ARMdocker
!conanfile.py
!.clang-tidy
!src/
Expand Down
18 changes: 12 additions & 6 deletions build_with_conan.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
import argparse
import os
import shutil
import argparse
import subprocess


def clean_build_folder(build_folder: str):
Expand Down Expand Up @@ -37,21 +38,26 @@ def main(args):
+ " ".join(conan_options))
print("----------------------------------")

os.system(
"conan install . --build=missing --profile ./conanprofile --profile:build ./conanprofile --output-folder=build "
+ " ".join(conan_options))
conan_install_cmd = "conan install . --build=missing --profile ./conanprofile --profile:build ./conanprofile --output-folder=build " + " ".join(
conan_options)
if subprocess.call(conan_install_cmd, shell=True) != 0:
raise Exception("Conan install command failed.")

print("----------------------------------")
print("cmake " + " ".join(cmake_options) + " -B build")
print("----------------------------------")

os.system("cmake " + " ".join(cmake_options) + " -B build")
cmake_cmd = "cmake " + " ".join(cmake_options) + " -B build"
if subprocess.call(cmake_cmd, shell=True) != 0:
raise Exception("CMake command failed.")

print("----------------------------------")
print(f"cmake --build build --parallel {args.parallel}")
print("----------------------------------")

os.system(f"cmake --build build --parallel {args.parallel}")
cmake_build_cmd = f"cmake --build build --parallel {args.parallel}"
if subprocess.call(cmake_build_cmd, shell=True) != 0:
raise Exception("CMake build command failed.")


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ class SiloRecipe(ConanFile):
settings = "os", "compiler", "build_type", "arch"

requires = [
"boost/1.81.0",
"boost/1.82.0",
"poco/1.12.4",
"onetbb/2021.7.0",
"onetbb/2021.9.0",
"nlohmann_json/3.11.2",
"gtest/cci.20210126",
"roaring/0.9.9",
"roaring/1.3.0",
"spdlog/1.11.0",
"vincentlaucsb-csv-parser/2.1.3",
"yaml-cpp/0.7.0",
Expand Down
2 changes: 1 addition & 1 deletion endToEndTests/test/queries/HasAAMutation.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"expectedQueryResult": [
{
"count": 3
"count": 1
}
]
}
33 changes: 33 additions & 0 deletions include/silo/common/aa_symbol_map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef SILO_AA_SYMBOL_MAP_H
#define SILO_AA_SYMBOL_MAP_H

#include <vector>

#include <boost/serialization/access.hpp>

#include "silo/common/aa_symbols.h"

namespace silo {

template <typename T>
class AASymbolMap {
friend class boost::serialization::access;

private:
template <class Archive>
[[maybe_unused]] void serialize(Archive& archive, const uint32_t /* version */) {
// clang-format off
archive& data;
// clang-format on
}

std::array<T, AA_SYMBOL_COUNT> data;

public:
inline T& operator[](AA_SYMBOL symbol) { return data.at(static_cast<uint8_t>(symbol)); }
inline const T& at(AA_SYMBOL symbol) const { return data.at(static_cast<uint8_t>(symbol)); }
};

} // namespace silo

#endif // SILO_AA_SYMBOL_MAP_H
138 changes: 101 additions & 37 deletions include/silo/common/aa_symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,115 @@
#include <array>
#include <iostream>
#include <optional>
#include <vector>

namespace silo {

/// https://www.bioinformatics.org/sms2/iupac.html
enum class AA_SYMBOL {
A, // Alanine
C, // Cysteine
D, // Aspartic Acid
E, // Glutamic Acid
F, // Phenylalanine
G, // Glycine
H, // Histidine
I, // Isoleucine
K, // Lysine
L, // Leucine
M, // Methionine
N, // Asparagine
P, // Proline
Q, // Glutamine
R, // Arginine
S, // Serine
T, // Threonine
V, // Valine
W, // Tryptophan
Y, // Tyrosine
B, // Aspartic acid or Asparagine
Z, // Glutamine or Glutamic acid
X, // Any amino acid
enum class AA_SYMBOL : char {
GAP, // - Gap in sequence
A, // Alanine
C, // Cysteine
D, // Aspartic Acid
E, // Glutamic Acid
F, // Phenylalanine
G, // Glycine
H, // Histidine
I, // Isoleucine
K, // Lysine
L, // Leucine
M, // Methionine
N, // Asparagine
P, // Proline
Q, // Glutamine
R, // Arginine
S, // Serine
T, // Threonine
V, // Valine
W, // Tryptophan
Y, // Tyrosine
B, // Aspartic acid or Asparagine
Z, // Glutamine or Glutamic acid
STOP, // Stop codon
X, // Any amino acid
};

static constexpr unsigned AA_SYMBOL_COUNT = static_cast<unsigned>(AA_SYMBOL::X) + 1;
static constexpr uint32_t AA_SYMBOL_COUNT = 25;
static constexpr uint32_t CODING_AA_SYMBOL_COUNT = 21;

static constexpr std::array<char, AA_SYMBOL_COUNT> AA_SYMBOL_REPRESENTATION{
'A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N',
'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y', 'B', 'Z', 'X',
static constexpr std::array<AA_SYMBOL, AA_SYMBOL_COUNT> AA_SYMBOLS{
AA_SYMBOL::GAP, AA_SYMBOL::A, AA_SYMBOL::C, AA_SYMBOL::D, AA_SYMBOL::E,
AA_SYMBOL::F, AA_SYMBOL::G, AA_SYMBOL::H, AA_SYMBOL::I, AA_SYMBOL::K,
AA_SYMBOL::L, AA_SYMBOL::M, AA_SYMBOL::N, AA_SYMBOL::P, AA_SYMBOL::Q,
AA_SYMBOL::R, AA_SYMBOL::S, AA_SYMBOL::T, AA_SYMBOL::V, AA_SYMBOL::W,
AA_SYMBOL::Y, AA_SYMBOL::B, AA_SYMBOL::Z, AA_SYMBOL::X, AA_SYMBOL::STOP,
};

static constexpr std::array<AA_SYMBOL, AA_SYMBOL_COUNT> AA_SYMBOLS{
AA_SYMBOL::A, AA_SYMBOL::C, AA_SYMBOL::D, AA_SYMBOL::E, AA_SYMBOL::F, AA_SYMBOL::G,
AA_SYMBOL::H, AA_SYMBOL::I, AA_SYMBOL::K, AA_SYMBOL::L, AA_SYMBOL::M, AA_SYMBOL::N,
AA_SYMBOL::P, AA_SYMBOL::Q, AA_SYMBOL::R, AA_SYMBOL::S, AA_SYMBOL::T, AA_SYMBOL::V,
AA_SYMBOL::W, AA_SYMBOL::Y, AA_SYMBOL::B, AA_SYMBOL::Z, AA_SYMBOL::X,
static constexpr std::array<AA_SYMBOL, CODING_AA_SYMBOL_COUNT> VALID_AA_SYMBOL_READS{
AA_SYMBOL::GAP, AA_SYMBOL::A, AA_SYMBOL::C, AA_SYMBOL::D, AA_SYMBOL::E, AA_SYMBOL::F,
AA_SYMBOL::G, AA_SYMBOL::H, AA_SYMBOL::I, AA_SYMBOL::K, AA_SYMBOL::L, AA_SYMBOL::M,
AA_SYMBOL::N, AA_SYMBOL::P, AA_SYMBOL::Q, AA_SYMBOL::R, AA_SYMBOL::S, AA_SYMBOL::T,
AA_SYMBOL::V, AA_SYMBOL::W, AA_SYMBOL::Y,
};

inline std::optional<AA_SYMBOL> toAASymbol(char character) {
inline char aaSymbolToChar(AA_SYMBOL symbol) {
switch (symbol) {
case AA_SYMBOL::GAP:
return '-';
case AA_SYMBOL::A:
return 'A';
case AA_SYMBOL::C:
return 'C';
case AA_SYMBOL::D:
return 'D';
case AA_SYMBOL::E:
return 'E';
case AA_SYMBOL::F:
return 'F';
case AA_SYMBOL::G:
return 'G';
case AA_SYMBOL::H:
return 'H';
case AA_SYMBOL::I:
return 'I';
case AA_SYMBOL::K:
return 'K';
case AA_SYMBOL::L:
return 'L';
case AA_SYMBOL::N:
return 'N';
case AA_SYMBOL::M:
return 'M';
case AA_SYMBOL::P:
return 'P';
case AA_SYMBOL::Q:
return 'Q';
case AA_SYMBOL::R:
return 'R';
case AA_SYMBOL::S:
return 'S';
case AA_SYMBOL::T:
return 'T';
case AA_SYMBOL::V:
return 'V';
case AA_SYMBOL::W:
return 'W';
case AA_SYMBOL::Y:
return 'Y';
case AA_SYMBOL::B:
return 'B';
case AA_SYMBOL::Z:
return 'Z';
case AA_SYMBOL::X:
return 'X';
case AA_SYMBOL::STOP:
return '*';
}
}

inline std::optional<AA_SYMBOL> charToAASymbol(char character) {
switch (character) {
case '-':
return AA_SYMBOL::GAP;
case 'A':
return AA_SYMBOL::A;
case 'C':
Expand All @@ -71,10 +133,10 @@ inline std::optional<AA_SYMBOL> toAASymbol(char character) {
return AA_SYMBOL::K;
case 'L':
return AA_SYMBOL::L;
case 'M':
return AA_SYMBOL::M;
case 'N':
return AA_SYMBOL::N;
case 'M':
return AA_SYMBOL::M;
case 'P':
return AA_SYMBOL::P;
case 'Q':
Expand All @@ -97,6 +159,8 @@ inline std::optional<AA_SYMBOL> toAASymbol(char character) {
return AA_SYMBOL::Z;
case 'X':
return AA_SYMBOL::X;
case '*':
return AA_SYMBOL::STOP;
default:
return std::nullopt;
}
Expand Down
11 changes: 8 additions & 3 deletions include/silo/common/bidirectional_map.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
#ifndef SILO_BIDIRECTIONAL_MAP_H
#define SILO_BIDIRECTIONAL_MAP_H

#include <mutex>
#include <cstdint>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>

#include <boost/serialization/access.hpp>

#include "silo/common/pango_lineage.h"
#include "silo/common/types.h"

namespace boost::serialization {
class access;
} // namespace boost::serialization

namespace silo::common {

template <typename V>
Expand All @@ -19,7 +24,7 @@ class BidirectionalMap {

private:
template <class Archive>
[[maybe_unused]] void serialize(Archive& archive, const unsigned int /* version */) {
[[maybe_unused]] void serialize(Archive& archive, const uint32_t /* version */) {
// clang-format off
archive& value_to_id;
archive& id_to_value;
Expand All @@ -35,7 +40,7 @@ class BidirectionalMap {

[[nodiscard]] V getValue(Idx idx) const;

[[nodiscard]] std::optional<Idx> getId(V value) const;
[[maybe_unused]] [[nodiscard]] std::optional<Idx> getId(V value) const;

[[nodiscard]] Idx getOrCreateId(V value);
};
Expand Down
1 change: 1 addition & 0 deletions include/silo/common/date.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef SILO_DATE_H
#define SILO_DATE_H

#include <cstdint>
#include <optional>
#include <string>

Expand Down
8 changes: 5 additions & 3 deletions include/silo/common/fasta_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <filesystem>
#include <iostream>
#include <optional>
#include <string>

#include "silo/common/input_stream_wrapper.h"

Expand All @@ -11,14 +13,14 @@ class FastaReader {
private:
silo::InputStreamWrapper in_file;

bool populateKey(std::string& key);
std::optional<std::string> nextKey();

public:
explicit FastaReader(const std::filesystem::path& in_file_name);

bool nextKey(std::string& key);
std::optional<std::string> nextSkipGenome();

bool next(std::string& key, std::string& genome);
std::optional<std::string> next(std::string& genome_buffer);

void reset();
};
Expand Down
1 change: 1 addition & 0 deletions include/silo/common/format_number.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef SILO_FORMAT_NUMBER_H
#define SILO_FORMAT_NUMBER_H

#include <cstdint>
#include <string>

namespace silo {
Expand Down
Loading

0 comments on commit e0e2219

Please sign in to comment.