Skip to content

Commit

Permalink
drop deprecated binary_function
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasrausch committed Sep 16, 2024
1 parent bf3157f commit 414f332
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 141 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bindir ?= $(exec_prefix)/bin

# Flags
CXX ?= g++
CXXFLAGS += -std=c++14 -isystem ${EBROOTHTSLIB} -pedantic -W -Wall -Wno-unknown-pragmas -D__STDC_LIMIT_MACROS -fno-strict-aliasing -fpermissive
CXXFLAGS += -std=c++17 -isystem ${EBROOTHTSLIB} -pedantic -W -Wall -Wno-unknown-pragmas -D__STDC_LIMIT_MACROS -fno-strict-aliasing -fpermissive
LDFLAGS += -L${EBROOTHTSLIB} -lboost_iostreams -lboost_filesystem -lboost_system -lboost_program_options -lboost_date_time

# Flags for parallel computation
Expand Down
10 changes: 4 additions & 6 deletions src/asmode.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ namespace torali {
}

// Sort junctions
for(typename TReadBp::iterator it = readBp.begin(); it != readBp.end(); ++it) {
std::sort(it->second.begin(), it->second.end(), SortJunction<Junction>());
}
for(typename TReadBp::iterator it = readBp.begin(); it != readBp.end(); ++it) std::sort(it->second.begin(), it->second.end());

// Clean-up
bam_hdr_destroy(hdr);
Expand Down Expand Up @@ -170,7 +168,7 @@ namespace torali {
for(uint32_t svt = 0; svt < srBR.size(); ++svt) {
if (srBR[svt].empty()) continue;
// Sort
std::sort(srBR[svt].begin(), srBR[svt].end(), SortSRBamRecord<SRBamRecord>());
std::sort(srBR[svt].begin(), srBR[svt].end());
//outputSRBamRecords(c, srBR, true);

// Cluster
Expand Down Expand Up @@ -364,7 +362,7 @@ namespace torali {
_setAsmConsensus(c, svc, srStore);

// Sort SVs
sort(svc.begin(), svc.end(), SortSVs<StructuralVariantRecord>());
sort(svc.begin(), svc.end());

// Filter SVs
uint32_t idCount = 0;
Expand Down Expand Up @@ -396,7 +394,7 @@ namespace torali {
for(uint32_t file_c = 0; file_c < c.files.size(); ++file_c) {
jctMap[file_c].resize(svs.size(), JunctionCount());
spanMap[file_c].resize(svs.size(), SpanningCount());
rcMap[file_c].resize(svs.size(), ReadCount());
rcMap[file_c].resize(svs.size());
}

// VCF Output
Expand Down
36 changes: 12 additions & 24 deletions src/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,19 @@ namespace torali
uint8_t MapQuality;

BamAlignRecord(bam1_t* rec, uint8_t pairQuality, uint16_t a, uint16_t ma, int32_t median, int32_t mad, int32_t maxISize) : tid(rec->core.tid), pos(rec->core.pos), mtid(rec->core.mtid), mpos(rec->core.mpos), alen(a), malen(ma), Median(median), Mad(mad), maxNormalISize(maxISize), flag(rec->core.flag), MapQuality(pairQuality) {}
};

// Sort reduced bam alignment records
template<typename TRecord>
struct SortBamRecords : public std::binary_function<TRecord, TRecord, bool>
{
inline bool operator()(TRecord const& s1, TRecord const& s2) const {
if (s1.tid==s1.mtid) {
return ((std::min(s1.pos, s1.mpos) < std::min(s2.pos, s2.mpos)) ||
((std::min(s1.pos, s1.mpos) == std::min(s2.pos, s2.mpos)) && (std::max(s1.pos, s1.mpos) < std::max(s2.pos, s2.mpos))) ||
((std::min(s1.pos, s1.mpos) == std::min(s2.pos, s2.mpos)) && (std::max(s1.pos, s1.mpos) == std::max(s2.pos, s2.mpos)) && (s1.maxNormalISize < s2.maxNormalISize)));
bool operator<(const BamAlignRecord& s2) const {
if (tid==mtid) {
return ((std::min(pos, mpos) < std::min(s2.pos, s2.mpos)) ||
((std::min(pos, mpos) == std::min(s2.pos, s2.mpos)) && (std::max(pos, mpos) < std::max(s2.pos, s2.mpos))) ||
((std::min(pos, mpos) == std::min(s2.pos, s2.mpos)) && (std::max(pos, mpos) == std::max(s2.pos, s2.mpos)) && (maxNormalISize < s2.maxNormalISize)));
} else {
return ((s1.pos < s2.pos) ||
((s1.pos == s2.pos) && (s1.mpos < s2.mpos)) ||
((s1.pos == s2.pos) && (s1.mpos == s2.mpos) && (s1.maxNormalISize < s2.maxNormalISize)));
return ((pos < s2.pos) ||
((pos == s2.pos) && (mpos < s2.mpos)) ||
((pos == s2.pos) && (mpos == s2.mpos) && (maxNormalISize < s2.maxNormalISize)));
}
}
};


// Edge struct
template<typename TWeight, typename TVertex>
Expand All @@ -64,14 +58,9 @@ namespace torali
TWeight weight;

EdgeRecord(TVertex s, TVertex t, TWeight w) : source(s), target(t), weight(w) {}
};

// Sort edge records
template<typename TRecord>
struct SortEdgeRecords : public std::binary_function<TRecord, TRecord, bool>
{
inline bool operator()(TRecord const& e1, TRecord const& e2) const {
return ((e1.weight < e2.weight) || ((e1.weight == e2.weight) && (e1.source < e2.source)) || ((e1.weight == e2.weight) && (e1.source == e2.source) && (e1.target < e2.target)));
bool operator<(const EdgeRecord e2) const {
return ((weight < e2.weight) || ((weight == e2.weight) && (source < e2.source)) || ((weight == e2.weight) && (source == e2.source) && (target < e2.target)));
}
};

Expand Down Expand Up @@ -225,7 +214,7 @@ namespace torali
// Iterate all components
for(typename TCompEdgeList::iterator compIt = compEdge.begin(); compIt != compEdge.end(); ++compIt) {
// Sort edges by weight
std::sort(compIt->second.begin(), compIt->second.end(), SortEdgeRecords<TEdgeRecord>());
std::sort(compIt->second.begin(), compIt->second.end());

// Find a large clique
typename TEdgeList::const_iterator itWEdge = compIt->second.begin();
Expand Down Expand Up @@ -454,12 +443,11 @@ namespace torali
inline void
_searchCliques(TConfig const& c, TCompEdgeList& compEdge, TBamRecord const& bamRecord, TSVs& svs, int32_t const svt) {
typedef typename TCompEdgeList::mapped_type TEdgeList;
typedef typename TEdgeList::value_type TEdgeRecord;

// Iterate all components
for(typename TCompEdgeList::iterator compIt = compEdge.begin(); compIt != compEdge.end(); ++compIt) {
// Sort edges by weight
std::sort(compIt->second.begin(), compIt->second.end(), SortEdgeRecords<TEdgeRecord>());
std::sort(compIt->second.begin(), compIt->second.end());

// Find a large clique
typename TEdgeList::const_iterator itWEdge = compIt->second.begin();
Expand Down
13 changes: 4 additions & 9 deletions src/cnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,13 @@ namespace torali

explicit SVBreakpoint(int32_t const p) : pos(p), cilow(0), cihigh(0), qual(0) {}
SVBreakpoint(int32_t const p, int32_t const cil, int32_t const cih, int32_t q) : pos(p), cilow(cil), cihigh(cih), qual(q) {}
};


template<typename TSVBp>
struct SortSVBreakpoint : public std::binary_function<TSVBp, TSVBp, bool>
{
inline bool operator()(TSVBp const& sv1, TSVBp const& sv2) {
return ((sv1.pos<sv2.pos) || ((sv1.pos==sv2.pos) && (sv1.qual<sv2.qual)));
bool operator<(const SVBreakpoint& sv2) const {
return ((pos<sv2.pos) || ((pos==sv2.pos) && (qual<sv2.qual)));
}
};


struct BpCNV {
int32_t start;
int32_t end;
Expand Down Expand Up @@ -139,7 +134,7 @@ namespace torali
midpoint = (int32_t) ((cnvs[n].start + cnvs[n].end) / 2);
if (searchEnd > midpoint) searchEnd = midpoint;
// Current CNV start for this breakpoint
typename TSVs::const_iterator itsv = std::lower_bound(svbp[refIndex].begin(), svbp[refIndex].end(), SVBreakpoint(searchStart), SortSVBreakpoint<SVBreakpoint>());
auto itsv = std::lower_bound(svbp[refIndex].begin(), svbp[refIndex].end(), SVBreakpoint(searchStart));
for(; itsv != svbp[refIndex].end(); ++itsv) {
if (itsv->pos > searchEnd) break;
if ((itbest == svbp[refIndex].end()) || (itsv->qual > itbest->qual)) itbest = itsv;
Expand Down
4 changes: 2 additions & 2 deletions src/coral.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace torali
svbp[svs[i].chr].push_back(SVBreakpoint(svs[i].svStart, svs[i].ciposlow, svs[i].ciposhigh, svs[i].mapq));
svbp[svs[i].chr2].push_back(SVBreakpoint(svs[i].svEnd, svs[i].ciendlow, svs[i].ciendhigh, svs[i].mapq));
}
for (uint32_t i = 0; i < svbp.size(); ++i) sort(svbp[i].begin(), svbp[i].end(), SortSVBreakpoint<SVBreakpoint>());
for (uint32_t i = 0; i < svbp.size(); ++i) sort(svbp[i].begin(), svbp[i].end());
}

// Iterate chromosomes
Expand Down Expand Up @@ -458,7 +458,7 @@ namespace torali
}

// Sort CNVs
sort(cnvs.begin(), cnvs.end(), SortCNVs<CNV>());
sort(cnvs.begin(), cnvs.end());

// Genotype CNVs
cnvVCF(c, cnvs);
Expand Down
26 changes: 13 additions & 13 deletions src/coverage.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ namespace torali {
SpanPoint() : bppos(0), svt(0), id(0), chr2(0), otherBppos(0) {}
explicit SpanPoint(int32_t const bp) : bppos(bp), svt(0), id(0), chr2(0), otherBppos(0) {}
SpanPoint(int32_t const bp, int32_t const s, uint32_t const identifier, int32_t const tid, int32_t const obp) : bppos(bp), svt(s), id(identifier), chr2(tid), otherBppos(obp) {}

bool operator<(const SpanPoint& s2) const {
return (bppos < s2.bppos);
}
};

struct BpRegion {
Expand All @@ -45,15 +49,12 @@ namespace torali {
BpRegion() : regionStart(0), regionEnd(0), bppos(0), homLeft(0), homRight(0), svt(0), id(0), bpPoint(0) {}
explicit BpRegion(int32_t bp) : regionStart(0), regionEnd(0), bppos(bp), homLeft(0), homRight(0), svt(0), id(0), bpPoint(0) {}
BpRegion(int32_t rs, int32_t re, int32_t bpos, int32_t hl, int32_t hr, int32_t s, uint32_t identifier, uint8_t bpp) : regionStart(rs), regionEnd(re), bppos(bpos), homLeft(hl), homRight(hr), svt(s), id(identifier), bpPoint(bpp) {}
};

template<typename TRecord>
struct SortBp : public std::binary_function<TRecord, TRecord, bool> {
inline bool operator()(TRecord const& s1, TRecord const& s2) const {
return (s1.bppos < s2.bppos);
bool operator<(const BpRegion& s2) const {
return (bppos < s2.bppos);
}
};

struct SpanningCount {
std::vector<uint8_t> ref;
std::vector<uint8_t> alt;
Expand Down Expand Up @@ -228,15 +229,14 @@ namespace torali {
fai_destroy(fai);
for(int32_t refIndex=0; refIndex < (int32_t) hdr->n_targets; ++refIndex) {
// Sort breakpoint regions
std::sort(bpRegion[refIndex].begin(), bpRegion[refIndex].end(), SortBp<BpRegion>());
std::sort(bpRegion[refIndex].begin(), bpRegion[refIndex].end());
}
}

template<typename TConfig, typename TSampleLibrary, typename TSVs, typename TCoverageCount, typename TCountMap, typename TSpanMap>
inline void
annotateCoverage(TConfig& c, TSampleLibrary& sampleLib, TSVs& svs, TCoverageCount& covCount, TCountMap& countMap, TSpanMap& spanMap)
{
typedef typename TCoverageCount::value_type::value_type TCovPair;
typedef typename TSpanMap::value_type::value_type TSpanPair;
typedef typename TCountMap::value_type::value_type TCountPair;
typedef std::vector<uint8_t> TQuality;
Expand All @@ -262,7 +262,7 @@ namespace torali {
countMap.resize(c.files.size());
spanMap.resize(c.files.size());
for(uint32_t file_c = 0; file_c < c.files.size(); ++file_c) {
covCount[file_c].resize(svs.size(), TCovPair());
covCount[file_c].resize(svs.size());
countMap[file_c].resize(svs.size(), TCountPair());
spanMap[file_c].resize(svs.size(), TSpanPair());
}
Expand Down Expand Up @@ -372,7 +372,7 @@ namespace torali {
spanPoint.push_back(SpanPoint(itSV->svEnd, itSV->svt, itSV->id, itSV->chr, itSV->svStart));
}
}
std::sort(spanPoint.begin(), spanPoint.end(), SortBp<SpanPoint>());
std::sort(spanPoint.begin(), spanPoint.end());

// Count reads
hts_itr_t* iter = sam_itr_queryi(idx[file_c], refIndex, 0, hdr[file_c]->target_len[refIndex]);
Expand Down Expand Up @@ -426,7 +426,7 @@ namespace torali {
}
if (bpvalid) {
// Fetch all relevant SVs
typename TBpRegion::iterator itBp = std::lower_bound(bpRegion[refIndex].begin(), bpRegion[refIndex].end(), BpRegion(rbegin), SortBp<BpRegion>());
typename TBpRegion::iterator itBp = std::lower_bound(bpRegion[refIndex].begin(), bpRegion[refIndex].end(), BpRegion(rbegin));
for(; ((itBp != bpRegion[refIndex].end()) && (rec->core.pos + rec->core.l_qseq >= itBp->bppos)); ++itBp) {
if ((countMap[file_c][itBp->id].ref.size() + countMap[file_c][itBp->id].alt.size()) >= c.maxGenoReadCount) continue;
// Read spans breakpoint?
Expand Down Expand Up @@ -582,7 +582,7 @@ namespace torali {
}
if (spanvalid) {
// Fetch all relevant SVs
typename TSpanPoint::iterator itSpan = std::lower_bound(spanPoint.begin(), spanPoint.end(), SpanPoint(st), SortBp<SpanPoint>());
typename TSpanPoint::iterator itSpan = std::lower_bound(spanPoint.begin(), spanPoint.end(), SpanPoint(st));
for(; ((itSpan != spanPoint.end()) && (st + spanlen >= itSpan->bppos)); ++itSpan) {
// Account for reference bias
if (++refAlignedSpanCount[file_c][itSpan->id] % 2) {
Expand Down Expand Up @@ -617,7 +617,7 @@ namespace torali {
}
if (spanvalid) {
// Fetch all relevant SVs
typename TSpanPoint::iterator itSpan = std::lower_bound(spanPoint.begin(), spanPoint.end(), SpanPoint(pbegin), SortBp<SpanPoint>());
typename TSpanPoint::iterator itSpan = std::lower_bound(spanPoint.begin(), spanPoint.end(), SpanPoint(pbegin));
for(; ((itSpan != spanPoint.end()) && (pend >= itSpan->bppos)); ++itSpan) {
if (svt == itSpan->svt) {
// Make sure, mate is correct
Expand Down
2 changes: 1 addition & 1 deletion src/delly.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace torali
sam_close(samfile);

// Re-number SVs
sort(svs.begin(), svs.end(), SortSVs<StructuralVariantRecord>());
sort(svs.begin(), svs.end());
uint32_t cliqueCount = 0;
for(typename TVariants::iterator svIt = svs.begin(); svIt != svs.end(); ++svIt, ++cliqueCount) svIt->id = cliqueCount;

Expand Down
8 changes: 2 additions & 6 deletions src/gaf.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ namespace torali

AlignRecord() : qstart(0), hap('*'), seed(0) {}
AlignRecord(int32_t const q, std::size_t const s) : qstart(q), hap('*'), seed(s) {}
};

template<typename TRecord>
struct SortAlignRecord : public std::binary_function<TRecord, TRecord, bool> {
inline bool operator()(TRecord const& s1, TRecord const& s2) const {
return ((s1.seed < s2.seed) || ((s1.seed == s2.seed) && (s1.qstart < s2.qstart)));
bool operator<(const AlignRecord& s2) const {
return ((seed < s2.seed) || ((seed == s2.seed) && (qstart < s2.qstart)));
}
};


inline void
parseGafCigar(std::string const& cigar, AlignRecord& ar) {
Expand Down
15 changes: 6 additions & 9 deletions src/gfa.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ namespace torali

Link() {}
Link(bool const fv, bool const tv, uint32_t const fr, uint32_t tos) : fromfwd(fv), tofwd(tv), from(fr), to(tos) {}

bool operator<(const Link& l2) const {
return ((from < l2.from) || ((from==l2.from) && (to < l2.to)));
}
};

struct LinkCargo {
Expand All @@ -36,19 +40,12 @@ namespace torali
LinkCargo() {}
LinkCargo(Link const lk) : fromfwd(lk.fromfwd), tofwd(lk.tofwd), from(lk.from), to(lk.to), support(0), mapq(0) {}
LinkCargo(bool const fv, bool const tv, uint32_t const fr, uint32_t tos) : fromfwd(fv), tofwd(tv), from(fr), to(tos), support(0) {}
};


template<typename TLink>
struct SortLinks : public std::binary_function<TLink, TLink, bool>
{
inline bool operator()(TLink const& l1, TLink const& l2) {
return ((l1.from < l2.from) || ((l1.from==l2.from) && (l1.to < l2.to)));
bool operator<(const LinkCargo& l2) const {
return ((from < l2.from) || ((from==l2.from) && (to < l2.to)));
}
};



struct Graph {
typedef std::map<std::string, uint32_t> TSegmentIdMap;

Expand Down
6 changes: 2 additions & 4 deletions src/junction.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,7 @@ namespace torali
}

// Sort junctions
for(typename TReadBp::iterator it = readBp.begin(); it != readBp.end(); ++it) {
std::sort(it->second.begin(), it->second.end(), SortJunction<Junction>());
}
for(typename TReadBp::iterator it = readBp.begin(); it != readBp.end(); ++it) std::sort(it->second.begin(), it->second.end());

// Clean-up
bam_hdr_destroy(hdr);
Expand Down Expand Up @@ -570,7 +568,7 @@ namespace torali
if (srBR[svt].empty()) continue;

// Sort
std::sort(srBR[svt].begin(), srBR[svt].end(), SortSRBamRecord<SRBamRecord>());
std::sort(srBR[svt].begin(), srBR[svt].end());

// Cluster
cluster(c, srBR[svt], svc, svt);
Expand Down
17 changes: 6 additions & 11 deletions src/merge.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,10 @@ struct IntervalScore {
int32_t score;

IntervalScore(uint32_t s, uint32_t e, int32_t c) : start(s), end(e), score(c) {}
};

template<typename TRecord>
struct SortIScores : public std::binary_function<TRecord, TRecord, bool>
{
inline bool operator()(TRecord const& s1, TRecord const& s2) const {
return ((s1.start < s2.start) || ((s1.start == s2.start) && (s1.end < s2.end)));
bool operator<(const IntervalScore& s2) const {
return ((start < s2.start) || ((start == s2.start) && (end < s2.end)));
}

};

template<typename TPos>
Expand Down Expand Up @@ -434,7 +429,7 @@ void _outputSelectedIntervals(MergeConfig& c, TGenomeIntervals const& iSelected,
int32_t score = rec[idx]->qual;

// Is this a selected interval
typename TIntervalScores::const_iterator iter = std::lower_bound(iSelected[tid].begin(), iSelected[tid].end(), IntervalScore(svStart, svEnd, score), SortIScores<IntervalScore>());
typename TIntervalScores::const_iterator iter = std::lower_bound(iSelected[tid].begin(), iSelected[tid].end(), IntervalScore(svStart, svEnd, score));
bool foundInterval = false;
for(; (iter != iSelected[tid].end()) && (iter->start == svStart); ++iter) {
if ((iter->start == svStart) && (iter->end == svEnd) && (iter->score == score)) {
Expand Down Expand Up @@ -693,7 +688,7 @@ void _outputSelectedIntervals(MergeConfig& c, TGenomeIntervals const& iSelected,
int32_t score = rec[idx]->qual;

// Is this a selected interval
typename TIntervalScores::const_iterator iter = std::lower_bound(iSelected[tid].begin(), iSelected[tid].end(), IntervalScore(svStart, svEnd, score), SortIScores<IntervalScore>());
typename TIntervalScores::const_iterator iter = std::lower_bound(iSelected[tid].begin(), iSelected[tid].end(), IntervalScore(svStart, svEnd, score));
bool foundInterval = false;
for(; (iter != iSelected[tid].end()) && (iter->start == svStart); ++iter) {
if ((iter->start == svStart) && (iter->end == svEnd) && (iter->score == score)) {
Expand Down Expand Up @@ -884,14 +879,14 @@ mergeRun(MergeConfig& c, int32_t const svt) {
TGenomeIntervals iScore;
iScore.resize(numseq, TIntervalScores());
_fillIntervalMap(c, iScore, contigMap, svt);
for(uint32_t i = 0; i<numseq; ++i) std::sort(iScore[i].begin(), iScore[i].end(), SortIScores<IntervalScore>());
for(uint32_t i = 0; i<numseq; ++i) std::sort(iScore[i].begin(), iScore[i].end());

// Filter intervals
TGenomeIntervals iSelected;
iSelected.resize(numseq, TIntervalScores());
_processIntervalMap(c, iScore, iSelected, svt);
iScore.clear();
for(uint32_t i = 0; i<numseq; ++i) std::sort(iSelected[i].begin(), iSelected[i].end(), SortIScores<IntervalScore>());
for(uint32_t i = 0; i<numseq; ++i) std::sort(iSelected[i].begin(), iSelected[i].end());

// Output best intervals
if (svt == 9) _outputSelectedIntervalsCNVs(c, iSelected, contigMap);
Expand Down
Loading

0 comments on commit 414f332

Please sign in to comment.