• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

graphia-app / graphia / 42724698251

09 Nov 2026 10:47PM UTC coverage: 71.88% (+0.5%) from 71.427%
42724698251

push

github

timangus
Add Leiden clustering

11927 of 18208 branches covered (65.5%)

Branch coverage included in aggregate %.

486 of 497 new or added lines in 3 files covered. (97.79%)

699 existing lines in 55 files now uncovered.

30522 of 40847 relevant lines covered (74.72%)

740302.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.21
/source/plugins/correlation/quantilenormaliser.cpp
1
/* Copyright © 2013-2025 Tim Angus
2
 * Copyright © 2013-2025 Tom Freeman
3
 *
4
 * This file is part of Graphia.
5
 *
6
 * Graphia is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * Graphia is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with Graphia.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19

20
#include "quantilenormaliser.h"
21

22
#include "shared/loading/iparser.h"
23

24
#include <QtGlobal>
25

26
#include <algorithm>
27
#include <cstddef>
28
#include <iterator>
29
#include <numeric>
30
#include <vector>
31

32
bool QuantileNormaliser::process(ContinuousDataVectors& dataRows, IParser* parser) const
33
{
14 ✔
34
    if(dataRows.empty())
14 ✔
35
        return true;
4 ✔
36

37
    auto numColumns = dataRows.at(0).size();
10 ✔
38

39
    std::vector<std::vector<double>> sortedColumnValues(numColumns);
10 ✔
40

41
    for(size_t column = 0; column < numColumns; column++)
46 ✔
42
    {
36 ✔
43
        if(parser != nullptr && parser->cancelled())
36 !
44
            return false;
×
45

46
        auto& sortedValues = sortedColumnValues[column];
36 ✔
47
        sortedValues.reserve(dataRows.size());
36 ✔
48

49
        // Get column values
50
        std::ranges::transform(dataRows, std::back_inserter(sortedValues),
36 ✔
51
        [column](const auto& dataRow)
36 ✔
52
        {
156 ✔
53
            return dataRow.valueAt(column);
156 ✔
54
        });
156 ✔
55

56
        std::ranges::sort(sortedValues);
36 ✔
57

58
        if(parser != nullptr)
36 ✔
59
            parser->setProgress(static_cast<int>((column * 100) / numColumns));
12 ✔
60
    }
36 ✔
61

62
    if(parser != nullptr)
10 ✔
63
        parser->setProgress(-1);
2 ✔
64

65
    std::vector<double> rowMeans(dataRows.size());
10 ✔
66

67
    // Populate row means
68
    for(size_t row = 0; row < rowMeans.size(); row++)
52 ✔
69
    {
42 ✔
70
        const double rowSum = std::accumulate(sortedColumnValues.begin(), sortedColumnValues.end(), 0.0,
42 ✔
71
            [row](double sum, const auto& columnValues) { return sum + columnValues[row]; });
156 ✔
72

73
        rowMeans[row] = rowSum / static_cast<double>(numColumns);
42 ✔
74
    }
42 ✔
75

76
    // So that the mean of a range of row means can be found quickly
77
    std::vector<double> cumulativeRowMeans(rowMeans.size() + 1, 0.0);
10 ✔
78
    std::partial_sum(rowMeans.begin(), rowMeans.end(), cumulativeRowMeans.begin() + 1);
10 ✔
79

80
    for(auto& dataRow : dataRows)
10 ✔
81
    {
42 ✔
82
        if(parser != nullptr && parser->cancelled())
42 !
UNCOV
83
            return false;
×
84

85
        for(size_t column = 0; column < numColumns; column++)
198 ✔
86
        {
156 ✔
87
            const auto& sortedValues = sortedColumnValues[column];
156 ✔
88
            auto [first, last] = std::ranges::equal_range(sortedValues, dataRow.valueAt(column));
156 ✔
89
            auto lo = static_cast<size_t>(std::distance(sortedValues.begin(), first));
156 ✔
90
            auto hi = static_cast<size_t>(std::distance(sortedValues.begin(), last));
156 ✔
91
            Q_ASSERT(lo < hi && hi <= rowMeans.size());
156 !
92

93
            // Tied values are given the mean of the row means for the ranks they span
94
            auto value = (hi - lo) == 1 ? rowMeans[lo] :
156 ✔
95
                (cumulativeRowMeans[hi] - cumulativeRowMeans[lo]) / static_cast<double>(hi - lo);
156 ✔
96

97
            dataRow.setValueAt(column, value);
156 ✔
98
        }
156 ✔
99
    }
42 ✔
100

101
    return true;
10 ✔
102
}
10 ✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc