Skip to content

Commit

Permalink
Reformat with clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
clang-format authored and marcelm committed Apr 26, 2023
1 parent 0786f38 commit 5b55d0a
Show file tree
Hide file tree
Showing 38 changed files with 2,037 additions and 1,835 deletions.
30 changes: 17 additions & 13 deletions src/aligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
* This is for anything that returns an aln_info object, currently
* Aligner::align and hamming_align.
*/
#include <sstream>
#include <tuple>
#include "aligner.hpp"
#include <algorithm>
#include <cassert>
#include "aligner.hpp"
#include <sstream>
#include <tuple>

aln_info Aligner::align(const std::string &query, const std::string &ref) const {
aln_info Aligner::align(const std::string& query, const std::string& ref) const {
m_align_calls++;
aln_info aln;
int32_t maskLen = query.length() / 2;
maskLen = std::max(maskLen, 15);
if (ref.length() > 2000){
// std::cerr << "ALIGNMENT TO REF LONGER THAN 2000bp - REPORT TO DEVELOPER. Happened for read: " << query << " ref len:" << ref.length() << std::endl;
if (ref.length() > 2000) {
// std::cerr << "ALIGNMENT TO REF LONGER THAN 2000bp - REPORT TO DEVELOPER. Happened for read: " << query << " ref len:" << ref.length() << std::endl;
aln.edit_distance = 100000;
aln.ref_start = 0;
aln.sw_score = -1000000;
Expand Down Expand Up @@ -110,12 +110,16 @@ aln_info Aligner::align(const std::string &query, const std::string &ref) const
* of the query, once for each end.
*/
std::tuple<size_t, size_t, int> highest_scoring_segment(
const std::string& query, const std::string& ref, int match, int mismatch, int end_bonus
const std::string& query,
const std::string& ref,
int match,
int mismatch,
int end_bonus
) {
size_t n = query.length();

size_t start = 0; // start of the current segment
int score = end_bonus; // accumulated score so far in the current segment
size_t start = 0; // start of the current segment
int score = end_bonus; // accumulated score so far in the current segment

size_t best_start = 0;
size_t best_end = 0;
Expand Down Expand Up @@ -144,15 +148,15 @@ std::tuple<size_t, size_t, int> highest_scoring_segment(
return std::make_tuple(best_start, best_end, best_score);
}

aln_info hamming_align(
const std::string &query, const std::string &ref, int match, int mismatch, int end_bonus
) {
aln_info
hamming_align(const std::string& query, const std::string& ref, int match, int mismatch, int end_bonus) {
aln_info aln;
if (query.length() != ref.length()) {
return aln;
}

auto [segment_start, segment_end, score] = highest_scoring_segment(query, ref, match, mismatch, end_bonus);
auto [segment_start, segment_end, score] =
highest_scoring_segment(query, ref, match, mismatch, end_bonus);

Cigar cigar;
if (segment_start > 0) {
Expand Down
36 changes: 20 additions & 16 deletions src/aligner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

#include <string>
#include <tuple>
#include "ssw/ssw_cpp.h"
#include "cigar.hpp"

#include "ssw/ssw_cpp.h"

struct alignment_params {
// match is a score, the others are penalties (all are nonnegative)
Expand All @@ -29,28 +28,30 @@ struct aln_info {
};

struct Aligner {
public:
public:
Aligner(alignment_params parameters)
: parameters(parameters)
, ssw_aligner(StripedSmithWaterman::Aligner(parameters.match, parameters.mismatch, parameters.gap_open, parameters.gap_extend))
{ }
, ssw_aligner(StripedSmithWaterman::Aligner(
parameters.match,
parameters.mismatch,
parameters.gap_open,
parameters.gap_extend
)) { }

aln_info align(const std::string &query, const std::string &ref) const;
aln_info align(const std::string& query, const std::string& ref) const;

alignment_params parameters;

unsigned calls_count() {
return m_align_calls;
}
unsigned calls_count() { return m_align_calls; }

private:
private:
const StripedSmithWaterman::Aligner ssw_aligner;
const StripedSmithWaterman::Filter filter;
mutable unsigned m_align_calls{0}; // no. of calls to the align() method
};

inline int hamming_distance(const std::string &s, const std::string &t) {
if (s.length() != t.length()){
inline int hamming_distance(const std::string& s, const std::string& t) {
if (s.length() != t.length()) {
return -1;
}

Expand All @@ -65,11 +66,14 @@ inline int hamming_distance(const std::string &s, const std::string &t) {
}

std::tuple<size_t, size_t, int> highest_scoring_segment(
const std::string& query, const std::string& ref, int match, int mismatch, int end_bonus
const std::string& query,
const std::string& ref,
int match,
int mismatch,
int end_bonus
);

aln_info hamming_align(
const std::string &query, const std::string &ref, int match, int mismatch, int end_bonus
);
aln_info
hamming_align(const std::string& query, const std::string& ref, int match, int mismatch, int end_bonus);

#endif
Loading

0 comments on commit 5b55d0a

Please sign in to comment.