klinic / MATLAB /test.m
Tanguyvans's picture
matlab
90c8ced
raw
history blame
1.74 kB
function visualize_connectedNodes()
% Read the data and create the connections map
data = readtable('MGREL.RRF', 'Delimiter', '|', 'FileType', 'text', 'NumHeaderLines', 0, 'VariableNamingRule', 'preserve');
data = renamevars(data, '#CUI1', 'CUI1');
data = data(1:1000,:);
connectionsMap = containers.Map('KeyType', 'char', 'ValueType', 'char');
for i = 1:size(data, 1)
node = data{i, 'CUI1'};
char_node = char(node);
connectedNode = data{i, 'CUI2'};
char_connectedNode = char(connectedNode);
if isKey(connectionsMap, char_node)
connectionsMap(char_node) = [connectionsMap(char_node), '|', char_connectedNode];
else
connectionsMap(char_node) = char_connectedNode;
end
end
% Prompt the user for input
prompt = 'Enter a key:';
dlgtitle = 'Input';
dims = [1 35];
definput = {'C0000727'};
userInput = inputdlg(prompt, dlgtitle, dims, definput);
% Check if user canceled the dialog
if isempty(userInput)
disp('User canceled the operation.');
return;
end
key = userInput{1};
% Check if the key exists in the connectionsMap
if isKey(connectionsMap, key)
% Split the value string by the pipe symbol '|'
split_values = strsplit(connectionsMap(key), '|');
% Display the connected nodes
disp(split_values);
% Visualize the graph
G = graph();
for i = 1:length(split_values)
G = addedge(G, key, split_values{i});
end
figure;
plot(G, 'Layout', 'force');
title('Graph of Connected Nodes');
else
disp('Key does not exist in the connectionsMap.');
end
end