This document provides guidance for developing and maintaining the openMINDS_KG_Sync toolbox.
openminds-kg-sync/
├── src/omkg/ # Main toolbox source code
│ ├── +omkg/ # MATLAB package namespace
│ ├── Contents.m # Toolbox contents listing
│ └── gettingStarted.m # Getting started guide
├── tests/ # Unit tests and test utilities
│ ├── +omkg/ # Namespace for unit tests and test utilites
├── tools/ # Development and build tools
│ ├── +omkgsynctools/ # Toolbox utilities
│ └── MLToolboxInfo.json # Toolbox metadata
└── docs/ # Documentation
├── buildDocs.m # Documentation builder
├── README.md # Documentation guide
└── STYLE_GUIDE.md # Coding style guide
% Add the toolbox to your MATLAB path
addpath(genpath('src/omkg'));
% Verify installation
omkg.toolboxversion()Location: Place your main functions in src/omkg/+omkg/
Naming Convention: Use camelCase for function names and PascalCase for class names
Function Template:
function output = myFunction(input, options)
% MYFUNCTION Brief description of what the function does
%
% Syntax:
% output = omkg.myFunction(input)
% output = omkg.myFunction(input, options)
%
% Description:
% Detailed description of the function's purpose and behavior.
%
% Input Arguments:
% input - Description of input parameter
% Type: double | logical | char
% Size: [m,n] | scalar | vector
%
% options - Optional parameters (optional)
% Type: struct
% Fields:
% - field1: Description (default: value)
% - field2: Description (default: value)
%
% Output Arguments:
% output - Description of output
% Type: double | logical | char
% Size: [m,n] | scalar | vector
%
% Examples:
% % Basic usage
% result = omkg.myFunction(data);
%
% % With options
% opts.field1 = value;
% result = omkg.myFunction(data, opts);
%
% See also: RELATEDFUNCTION1, RELATEDFUNCTION2
%
% openMINDS_KG_Sync
% Copyright (c) Eivind Hennestad, University of Oslo / Neural Systems
arguments
input {mustBeNumeric}
options.field1 (1,1) double = 1
options.field2 (1,1) logical = false
end
% Function implementation here
output = processInput(input, options);
endLocation: Place tests in tests/ directory
Test Template:
function tests = testMyFunction
% TESTMYFUNCTION Unit tests for myFunction
%
% Run tests:
% runtests('testMyFunction')
% results = runtests('testMyFunction')
tests = functiontests(localfunctions);
end
function setupOnce(testCase)
% Setup for the entire test suite
addpath(fullfile(fileparts(mfilename('fullpath')), '..', 'src', 'omkg'));
end
function setup(testCase)
% Setup for each test
testCase.TestData.sampleData = rand(10, 5);
end
function testBasicFunctionality(testCase)
% Test basic functionality
input = testCase.TestData.sampleData;
result = omkg.myFunction(input);
verifySize(testCase, result, size(input));
end
function testWithOptions(testCase)
% Test with optional parameters
input = testCase.TestData.sampleData;
options.field1 = 2;
result = omkg.myFunction(input, options);
verifyClass(testCase, result, 'double');
end
function testErrorHandling(testCase)
% Test error conditions
verifyError(testCase, @() omkg.myFunction('invalid'), ...
'MATLAB:validators:mustBeNumeric');
end% Run all tests
runtests('tests')
% Run specific test file
runtests('tests/testMyFunction')
% Run with coverage
import matlab.unittest.TestRunner
import matlab.unittest.plugins.CodeCoveragePlugin
import matlab.unittest.plugins.codecoverage.CoverageReport
suite = testsuite('tests');
runner = TestRunner.withTextOutput;
runner.addPlugin(CodeCoveragePlugin.forFolder('src'));
results = runner.run(suite);Todo
Requirements: MATLAB R2023a or later for toolbox packaging
% Package the toolbox
omkgsynctools.packageToolbox()
% Install locally for testing
omkgsynctools.installMatBox()- Function Headers: Use the template above with complete argument descriptions
- Comments: Explain complex algorithms and non-obvious code
- Examples: Provide practical usage examples in function headers
- See Also: Reference related functions
- Indentation: 4 spaces (no tabs)
- Line Length: Maximum 80 characters
- Variable Names: Use descriptive camelCase names
- Constants: Use UPPER_CASE for constants
- Function Names: Use camelCase, start with lowercase letter
% Use arguments blocks for input validation
arguments
input {mustBeNumeric, mustBeFinite}
options.tolerance (1,1) double {mustBePositive} = 1e-6
end
% Provide meaningful error messages
if size(input, 2) ~= 3
error('OMKG:invalidInput', ...
'Input must have exactly 3 columns, got %d', size(input, 2));
end% Check code quality
checkcode('src/omkg/')
% Profile performance
profile on
omkg.myFunction(data);
profile viewer
% Dependency analysis
[fList, pList] = matlab.codetools.requiredFilesAndProducts('src/omkg');# Create feature branch
git checkout -b feature/new-functionality
# Make changes and commit
git add .
git commit -m "Add new functionality for X"
# Push and create pull request
git push origin feature/new-functionality-
MATLAB Version Compatibility: Toolbox packaging using MatBox requires R2023a+.
-
Path Management: Always use relative paths and the
omkgsynctools.projectdir()function -
Testing: Run tests before committing changes
-
Documentation: Update documentation when adding new features
-
Versioning: Follow semantic versioning (MAJOR.MINOR.PATCH)
- Path Problems: Ensure the toolbox is properly added to MATLAB path
- Test Failures: Check that all dependencies are available
- Packaging Errors: Verify MATLAB version and toolbox metadata
- Performance Issues: Use MATLAB Profiler to identify bottlenecks
- Check existing issues in the repository
- Review the documentation in
docs/ - Consult the MATLAB documentation
- Contact the maintainers: eivihe@uio.no