Spaces:
Sleeping
Sleeping
File size: 1,972 Bytes
93e1b64 a6bd112 9333b89 93e1b64 9333b89 93e1b64 9333b89 93e1b64 9333b89 |
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
% Read the CSV file
data = readtable('../MGREL.RRF', Delimiter='|', FileType='text', NumHeaderLines=0, VariableNamingRule='preserve');
data = renamevars(data, '#CUI1', 'CUI1');
ids_1 = data.CUI1;
for k = 1 : length(ids_1)
cellContents = ids_1{k};
% Truncate and stick back into the cell
ids_1{k} = cellContents(2:end);
end
ids_1 = str2double(ids_1);
ids_2 = data.CUI2;
for k = 1 : length(ids_2)
cellContents = ids_2{k};
% Truncate and stick back into the cell
ids_2{k} = cellContents(2:end);
end
ids_2 = str2double(ids_2);
edges = [ids_1, ids_2];
edges = edges(~any(isnan(edges), 2), :);
ids_1 = edges(:, 1);
ids_2 = edges(:, 2);
G = digraph(ids_1, ids_2);
% Compute PageRank centrality
pg_ranks = centrality(G, 'pagerank');
% Assign PageRank to each node
G.Nodes.PageRank = pg_ranks;
for i = 1:numnodes(G)
if pg_ranks(i) > 1.6487e-07
disp(['Node ', num2str(i), ' PageRank: ', num2str(pg_ranks(i))]);
end
end
%idx = G.Nodes.PageRank > 1.6487e-07;
%disp(G.Nodes(idx, :));
% Get the number of unique nodes
%nodes = unique([ids_1; ids_2]);
%num_nodes = length(nodes);
% Initialize sparse adjacency matrix
%A = sparse(ids_1, ids_2, 1, max(ids_2), max(ids_2));
% Display adjacency matrix
%disp(A);
connections = {
'A1', 'B2';
'A1', 'A2'
};
% Extract unique nodes
nodes = unique(connections(:));
% Create a directed graph
num_nodes = length(nodes);
node_indices = containers.Map(nodes, 1:num_nodes);
A = zeros(num_nodes);
for i = 1:size(connections, 1)
from_node = connections{i, 1};
to_node = connections{i, 2};
from_index = node_indices(from_node);
to_index = node_indices(to_node);
A(from_index, to_index) = 1;
end
% Display adjacency matrix
disp(A);
% Create directed graph
G = digraph(A, nodes);
% Compute PageRank centrality
pg_ranks = centrality(G, 'pagerank');
% Display PageRank for each node
for i = 1:num_nodes
disp(['PageRank for ', nodes{i}, ': ', num2str(pg_ranks(i))]);
end
|