Skip to content

Commit

Permalink
use average rather than flanking coverage in disconnector
Browse files Browse the repository at this point in the history
  • Loading branch information
snurk authored and Dmitry-Antipov committed May 16, 2019
1 parent 1cf72e4 commit 39101de
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,59 @@ class Component {
}
};

//FIXME unify with the flanking cov helper
template<class Graph>
class RelativeAvgCovHelper {
typedef typename Graph::EdgeId EdgeId;
typedef typename Graph::VertexId VertexId;

const Graph& g_;
double min_coverage_gap_;

public:
RelativeAvgCovHelper(const Graph& g,
double min_coverage_gap)
: g_(g),
min_coverage_gap_(min_coverage_gap) {
VERIFY(math::gr(min_coverage_gap, 1.));
}

template<class EdgeContainer>
double MaxCoverage(const EdgeContainer& edges) const {
double answer = 0.0;
for (EdgeId e : edges) {
answer = std::max(answer, g_.coverage(e));
}
return answer;
}

template<class EdgeContainer>
bool CheckAnyHighlyCovered(const EdgeContainer& edges,
double base_coverage) const {
return math::gr(MaxCoverage(edges),
base_coverage * min_coverage_gap_);
}

bool AnyHighlyCoveredOnBothSides(VertexId v, double base_coverage) const {
return CheckAnyHighlyCovered(g_.IncomingEdges(v), base_coverage) &&
CheckAnyHighlyCovered(g_.OutgoingEdges(v), base_coverage);
}

bool AnyHighlyCoveredOnFourSides(EdgeId e) const {
return AnyHighlyCoveredOnBothSides(g_.EdgeStart(e), LocalCoverage(e, g_.EdgeStart(e))) &&
AnyHighlyCoveredOnBothSides(g_.EdgeEnd(e), LocalCoverage(e, g_.EdgeEnd(e)));
}

double RelativeCoverageToReport(VertexId v, double base_coverage) const {
return std::min(MaxCoverage(g_.OutgoingEdges(v)),
MaxCoverage(g_.IncomingEdges(v)))
/ base_coverage;
}

private:
DECL_LOGGER("RelativeAvgCovHelper");
};

template<class Graph>
class RelativeCoverageHelper {
typedef typename Graph::EdgeId EdgeId;
Expand Down Expand Up @@ -229,30 +282,28 @@ class RelativeCovDisconnectionCondition : public EdgeCondition<Graph> {
typedef EdgeCondition<Graph> base;
typedef typename Graph::EdgeId EdgeId;
typedef typename Graph::VertexId VertexId;
const RelativeCoverageHelper<Graph> rel_helper_;
const RelativeAvgCovHelper<Graph> rel_helper_;
const double diff_mult_;

//Total length of highly-covered neighbourhood
// We believe that if high-covered component is small it is likely to be repeat or loop
const size_t min_neighbourhood_size_;
public:
RelativeCovDisconnectionCondition(const Graph& g,
const FlankingCoverage<Graph>& flanking_cov,
double diff_mult,
size_t min_neighbourhood_size) :
base(g),
rel_helper_(g, flanking_cov, diff_mult),
rel_helper_(g, diff_mult),
diff_mult_(diff_mult),
min_neighbourhood_size_(min_neighbourhood_size) {
}

bool Check(EdgeId e) const override {
VertexId v = this->g().EdgeStart(e);
double coverage_edge_around_v = rel_helper_.LocalCoverage(e, v);
DEBUG("Local flanking coverage - " << coverage_edge_around_v);
DEBUG("Max local coverage incoming - " << rel_helper_.MaxLocalCoverage(this->g().IncomingEdges(v), v));
DEBUG("Max local coverage outgoing - " << rel_helper_.MaxLocalCoverage(this->g().OutgoingEdges(v), v));
return rel_helper_.AnyHighlyCoveredOnBothSides(v, coverage_edge_around_v) &&
DEBUG("Coverage - " << this->g().coverage(e));
DEBUG("Max local coverage incoming - " << rel_helper_.MaxCoverage(this->g().IncomingEdges(v)));
DEBUG("Max local coverage outgoing - " << rel_helper_.MaxCoverage(this->g().OutgoingEdges(v)));
return rel_helper_.AnyHighlyCoveredOnBothSides(v, this->g().coverage(e)) &&
HighCoverageComponentFinder<Graph>(this->g(), this->g().coverage(e) * diff_mult_, min_neighbourhood_size_)
.EdgeSummaryLength(v) >= min_neighbourhood_size_;
}
Expand Down
2 changes: 1 addition & 1 deletion assembler/src/common/stages/simplification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class GraphSimplifier {
"Relative coverage component remover");

algo.AddAlgo(
RelativelyLowCoverageDisconnectorInstance(gp_.g, gp_.flanking_cov,
RelativelyLowCoverageDisconnectorInstance(gp_.g,
simplif_cfg_.red, info_container_),
"Disconnecting edges with relatively low coverage");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ AlgoPtr<Graph> RelativeCoverageComponentRemoverInstance (

template<class Graph>
AlgoPtr<Graph> RelativelyLowCoverageDisconnectorInstance(Graph &g,
const FlankingCoverage<Graph> &flanking_cov,
const config::debruijn_config::simplification::relative_coverage_edge_disconnector &rced_config,
const SimplifInfoContainer &info) {
if (!rced_config.enabled) {
Expand All @@ -452,10 +451,10 @@ AlgoPtr<Graph> RelativelyLowCoverageDisconnectorInstance(Graph &g,
}
using Condition=omnigraph::simplification::relative_coverage::RelativeCovDisconnectionCondition<Graph>;

func::TypedPredicate<EdgeId> condition = Condition(g, flanking_cov, rced_config.diff_mult, rced_config.edge_sum);
func::TypedPredicate<EdgeId> condition = Condition(g, rced_config.diff_mult, rced_config.edge_sum);

if (math::gr(rced_config.unconditional_diff_mult, 0.)) {
condition = func::Or(Condition(g, flanking_cov, rced_config.unconditional_diff_mult, 0), condition);
condition = func::Or(Condition(g, rced_config.unconditional_diff_mult, 0), condition);
}

return std::make_shared<omnigraph::DisconnectionAlgorithm<Graph>>(g,
Expand Down

0 comments on commit 39101de

Please sign in to comment.