Skip to content

Commit

Permalink
Merge pull request #152 from veg/2024-refactoring-RF2
Browse files Browse the repository at this point in the history
Resolving CoI sequence vs person level stuff
  • Loading branch information
stevenweaver authored Nov 19, 2024
2 parents 17204e1 + 9e54e97 commit 4701615
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
33 changes: 22 additions & 11 deletions src/clusternetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,13 @@ var hivtrace_cluster_network_graph = function (
if (priority_group) {
cluster_nodes = self.priority_groups_find_by_name(priority_group);
if (cluster_nodes) {
cluster_nodes = cluster_nodes.node_objects;
if (self.has_multiple_sequences) {
cluster_nodes = self.aggregate_indvidual_level_records(
cluster_nodes.node_objects
);
} else {
cluster_nodes = cluster_nodes.node_objects;
}
} else {
return;
}
Expand Down Expand Up @@ -2044,17 +2050,22 @@ var hivtrace_cluster_network_graph = function (
var rows_for_export = [
["Overlapping Cluster of Interest", "Node", "Other clusterOI"],
];
_.each(ps.nodes, (n) => {
const overlap = self.priority_node_overlap[n.name];
let other_sets = "None";
if (overlap.size > 1) {
other_sets = _.sortBy(
_.filter([...overlap], (d) => d !== priority_list)
).join("; ");

_.each(
self.aggregate_indvidual_level_records(ps.node_objects),
(n) => {
const eid = self.entity_id(n);
const overlap = self.priority_node_overlap[eid];
let other_sets = "None";
if (overlap.size > 1) {
other_sets = _.sortBy(
_.filter([...overlap], (d) => d !== priority_list)
).join("; ");
}
rows.push([{ value: eid }, { value: other_sets }]);
rows_for_export.push([ps.name, eid, other_sets]);
}
rows.push([{ value: n.name }, { value: other_sets }]);
rows_for_export.push([ps.name, n.name, other_sets]);
});
);

d3.select(
self.get_ui_element_selector_by_role(
Expand Down
4 changes: 2 additions & 2 deletions src/clustersOfInterest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1418,9 +1418,9 @@ function draw_priority_set_table(self, container, priority_groups) {
return (
String(v[0]) +
(v[1]
? ' <span title="Number of nodes in the overlap" class="label label-default pull-right">' +
? ' <span title="Number of persons in the overlap" class="label label-default pull-right">' +
v[1] +
" nodes</span>"
" persons</span>"
: "") +
(v[2].length
? ' <span title="clusterOIs which are exact duplicates of this clusterOI: ' +
Expand Down
31 changes: 19 additions & 12 deletions src/hiv_tx_network.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,14 +711,20 @@ class HIVTxNetwork {

priority_groups_compute_overlap = function (groups) {
this.priority_node_overlap = {};
const size_by_pg = {};

var entities_by_pg = {};
var size_by_pg = {};
_.each(groups, (pg) => {
size_by_pg[pg.name] = pg.nodes.length;
_.each(pg.nodes, (n) => {
if (!(n.name in this.priority_node_overlap)) {
this.priority_node_overlap[n.name] = new Set();
entities_by_pg[pg.name] = this.aggregate_indvidual_level_records(
pg.node_objects
);
size_by_pg[pg.name] = entities_by_pg[pg.name].length;
_.each(entities_by_pg[pg.name], (n) => {
const entity_id = this.entity_id(n);
if (!(entity_id in this.priority_node_overlap)) {
this.priority_node_overlap[entity_id] = new Set();
}
this.priority_node_overlap[n.name].add(pg.name);
this.priority_node_overlap[entity_id].add(pg.name);
});
});

Expand All @@ -731,24 +737,25 @@ class HIVTxNetwork {
};

const by_set_count = {};
_.each(pg.nodes, (n) => {
if (this.priority_node_overlap[n.name].size > 1) {
_.each(entities_by_pg[pg.name], (n) => {
const entity_id = this.entity_id(n);
if (this.priority_node_overlap[entity_id].size > 1) {
overlap.nodes++;
this.priority_node_overlap[n.name].forEach((pgn) => {
this.priority_node_overlap[entity_id].forEach((pgn) => {
if (pgn !== pg.name) {
if (!(pgn in by_set_count)) {
by_set_count[pgn] = [];
}
by_set_count[pgn].push(n.name);
by_set_count[pgn].push(entity_id);
}
overlap.sets.add(pgn);
});
}
});

_.each(by_set_count, (nodes, name) => {
if (nodes.length === pg.nodes.length) {
if (size_by_pg[name] === pg.nodes.length) {
if (nodes.length == size_by_pg[pg.name]) {
if (size_by_pg[name] == size_by_pg[pg.name]) {
overlap.duplicates.push(name);
} else {
overlap.supersets.push(name);
Expand Down

0 comments on commit 4701615

Please sign in to comment.