Skip to content

degree calculation/rank sorting is incorrect #18

@vincerubinetti

Description

@vincerubinetti

https://github.com/aaronkw/d3-network/blob/master/d3.network.js#L105-L106

These lines do not properly take into account that query_degreen and degreen can and will be 0, particularly for the query genes, and will cause query_degree and degree to become NaN. This in turn causes the sorting/ranking to not work properly under certain circumstances:

[33, 22, 11, NaN, NaN, 66, 55, 44].sort((a,b)=>b-a) // outputs [33, 22, 11, NaN, NaN, 66, 55, 44]

because both 1-NaN and NaN-1, for example, both yield NaN.

In more complex situations, the order can even different between different browsers, most likely due to the under-the-hood differences in the sorting implementations.

These lines:

https://github.com/aaronkw/d3-network/blob/master/d3.network.js#L105-L106

should have something like this underneath:

if (isNaN(genes[i].query_degree)) {
  genes[i].query_degree = Infinity;
}
if (isNaN(genes[i].degree)) {
  genes[i].degree = Infinity;
}

You'll also have to add some checks to this line to keep the same error from happening:
https://github.com/aaronkw/d3-network/blob/master/d3.network.js#L123

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions