-
Notifications
You must be signed in to change notification settings - Fork 8
/
readsif2sbe.m
executable file
·72 lines (62 loc) · 1.91 KB
/
readsif2sbe.m
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
function [sbeG,sbeNode,fName]=readsif2sbe(filename)
%% readsif2sbe - read in SIF format file
%
% This function reads in network information in SIF format and returns
% edge and node information in sbeG and sbeNode
%
% See also: readtab2sbe, readpajek2sbe
%
% Systems Biology and Evolution Toolbox (SBEToolbox).
% Authors: James Cai, Kranti Konganti.
% (C) Texas A&M University.
%
% $LastChangedDate: 2013-01-28 16:56:39 -0600 (Mon, 28 Jan 2013) $
% $LastChangedRevision: 378 $
% $LastChangedBy: konganti $
%
%% UI for Browse file window
sbeG=[]; sbeNode=[]; fName='';
if ispref('SBEToolbox', 'filedir')
prevPath = getpref('SBEToolbox', 'filedir');
else
prevPath = '';
addpref('SBEToolbox', 'filedir', pwd);
end
if ~ispref('SBEToolbox', 'filename')
addpref('SBEToolbox', 'filename', '');
end
if nargin < 1
[filename, pathname] = uigetfile( ...
{'*.sif', 'SIF Files (*.sif)';'*.*', 'All Files (*.*)'}, ...
'Pick an SIF file', prevPath);
if isequal(filename, 0)
return
end
fName = filename;
filename=[pathname,filename];
if pathname ~= 0
setpref('SBEToolbox', 'filedir', pathname);
setpref('SBEToolbox', 'filename', fName);
end
end
%% Read file using fopen and textscan
sif_file_id = fopen(filename);
dataCell = textscan(sif_file_id, '%s%s%s');
fclose(sif_file_id);
c = [dataCell{1};dataCell{3}];
%% Store edge and node information into sbeG and sbeNode
[sbeNode,~,x]=unique(c);
n=numel(sbeNode);
y=reshape(x,[numel(x)/2 2]);
%z=[x(1:numel(x)/2),x(numel(x)/2+1:end)];
%all(y==z);
sbeG=false(n);
for k=1:numel(x)/2
sbeG(y(k,1),y(k,2))=true;
sbeG(y(k,2),y(k,1))=true;
end
%% Assign empty node as 'N/A'
isemptyNodeNameIdx = find(logical(cellfun(@isempty, sbeNode)));
if ~isempty(isemptyNodeNameIdx) && isempty(sbeNode{isemptyNodeNameIdx})
sbeNode{isemptyNodeNameIdx} = 'N/A';
end