From 8070dc963753142bb86c4ed698d91fd623ed28e7 Mon Sep 17 00:00:00 2001 From: ziejd2 Date: Thu, 28 Sep 2017 15:04:40 -0500 Subject: BNW using Octave instead of Matlab. This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning. I am calling this BNW_1.02. It can be accessed at: compbio.uthsc.edu/BNW_1.02 --- sourcecodes/bnt-master/KPMtools/loadcell.m | 153 +++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 sourcecodes/bnt-master/KPMtools/loadcell.m (limited to 'sourcecodes/bnt-master/KPMtools/loadcell.m') diff --git a/sourcecodes/bnt-master/KPMtools/loadcell.m b/sourcecodes/bnt-master/KPMtools/loadcell.m new file mode 100644 index 00000000..85691854 --- /dev/null +++ b/sourcecodes/bnt-master/KPMtools/loadcell.m @@ -0,0 +1,153 @@ +function [lc,dflag,dattype]=loadcell(fname,delim,exclusions,options); +%function [lc,dflag,numdata]=loadcell(fname,delim,exclusions); +% +% loadcell loads a cell array with character delimited +% data, which can have variable length lines and content. +% Numeric values are converted from string to double +% unless options is a string containing 'string'. +% +% loadcell is for use with small datasets. It is not optimised +% for large datasets. +% +% fname is the filename to be loaded +% +% delim is/are the relevant delimiter(s). If char(10) is included +% newlines are simply treated as delimiters and a 1-d array is created. +% +% exclusions are the set of characters to be treated as paired +% braces: line ends or delimiters within braces are ignored. +% braces are single characters and any brace can pair with +% any other brace: no type pair checking is done. +% +% options can be omitted or can contain 'string' if no numeric +% conversion is required, 'single' if multiple adjacent seperators +% should not be treated as one, 'free' if all linefeeds should be stripped +% first and 'empty2num' if empty fields are to be treated as numeric +% zeros rather than an empty character set. Combine options using +% concatenation. +% +% lc is a cell array containing the loaded data. +% +% dflag is a set of flags denoting the (i,j) values where data was entered +% dflag(i,j)=1 implies lc(i,j) was loaded from the data, and not just set +% to empty, say, by default. +% +% numdata is an array numdata(i,j)=NaN implies +% lc(i,j) is a string, otherwise it stores the number at i,j. +% This will occur regardless of whether the 'string' option is set. +% +% lc will return -1 if the file is not found or could not be +% opened. +% +% Hint: numdata+(1/dflag-1) provides a concise descriptor for the numeric data +% Inf=not loaded +% NaN=was string or empty set. +% otherwise numeric +% +% EXAMPLE +% +%[a,b]=loadcell('resultsfile',[',' char(9)],'"','single-string'); +% will load file 'resultsfile' into variable a, treating any of tab or +% comma as delimiters. Delimiters or carriage returns lying +% between two double inverted commas will be ignored. Two adjacent delimiters +% will count twice, and all data will be kept as a string. +% +% Note: in space-separated data 'single' would generally be omitted, +% wheras in comma-seperated data it would be included. +% +% Note the exclusion characters will remain in the final data, and any data +% contained within or containing exclusion characters will not be +% converted to numerics. +% +% (c) Amos Storkey 2002 +% v b160702 + +% MATLAB is incapable of loading variable length lines or variable type values +% with a whole file command under the standard library sets. This mfile +% fills that gap. +if (nargin<4) + options=' '; +end; +dflag = []; +%Open file +fid=fopen(fname,'rt'); +%Cannot open: return -1 +if (fid<0) + lc=-1; +else + fullfile=fread(fid,'uchar=>char')'; + %Strip LF if free is set + if ~isempty(findstr(options,'free')) + fullfile=strrep(fullfile,char(10),''); + end; + %Find all delimiters + delimpos=[]; + for s=1:length(delim) + delimpos=[delimpos find(fullfile==delim(s))]; + end + %Find all eol + endpos=find(fullfile==char(10)); + endpos=setdiff(endpos,delimpos); + %find all exclusions + xclpos=[]; + for s=1:length(exclusions); + xclpos=[xclpos find(fullfile==exclusions(s))]; + end + sort(xclpos); + xclpos=[xclpos(1:2:end-1);xclpos(2:2:end)]; + %Combine eol and delimiters + jointpos=union(delimpos,endpos); + t=1; + %Remove delim/eol within exclusion pairs + removedelim=[]; + for s=1:length(jointpos) + if any((jointpos(s)>xclpos(1,:)) & (jointpos(s)