File: basic_graph_stats.hpp

package info (click to toggle)
spades 3.13.1+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 22,172 kB
  • sloc: cpp: 136,213; ansic: 48,218; python: 16,809; perl: 4,252; sh: 2,115; java: 890; makefile: 507; pascal: 348; xml: 303
file content (53 lines) | stat: -rw-r--r-- 1,450 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once

#include "utils/standard_base.hpp"
namespace omnigraph {

template<class Graph>
class AvgCovereageCounter {
private:
    const Graph &graph_;
    const size_t min_length_;
public:
    AvgCovereageCounter(const Graph &graph, size_t min_length = 0) :
            graph_(graph), min_length_(min_length) {
    }

    double Count() const {
        double cov = 0;
        size_t length = 0;
        for (auto it = graph_.ConstEdgeBegin(); !it.IsEnd(); ++it) {
            if (graph_.length(*it) >= min_length_) {
                cov += graph_.coverage(*it) * (double) graph_.length(*it);
                length += graph_.length(*it);
            }
        }
        if (length == 0)
            return 0.;
        return cov / (double) length;
    }
};

template<class Graph>
size_t CumulativeLength(const Graph& g,
                        const std::vector<typename Graph::EdgeId>& path) {
    size_t s = 0;
    for (auto it = path.begin(); it != path.end(); ++it)
        s += g.length(*it);

    return s;
}

template<class Graph>
double AvgCoverage(const Graph& g,
                   const std::vector<typename Graph::EdgeId>& path) {
    double unnormalized_coverage = 0;
    size_t path_length = 0;
    for (auto edge : path) {
        size_t length = g.length(edge);
        path_length += length;
        unnormalized_coverage += g.coverage(edge) * (double) length;
    }
    return unnormalized_coverage / (double) path_length;
}
}