Skip to content

[WIP] Improve input validation and help descriptions for genome utility functions#617

Closed
Copilot wants to merge 1 commit into
develop3from
copilot/add-input-validation-and-help-blocks
Closed

[WIP] Improve input validation and help descriptions for genome utility functions#617
Copilot wants to merge 1 commit into
develop3from
copilot/add-input-validation-and-help-blocks

Conversation

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown

Coding agent has begun work on Improve MATLAB Help Descriptions and Input Validation for Genome Utility Functions and will update this pull request as work progresses.

Original prompt

improve this function by adding if validators of inputs like this for example nargin<1 || isempty(fileName) [fileName, pathName] = uigetfile({'.xml;.sbml'}, 'Please select the model file'); if fileName == 0 error('You should select a model file') else fileName = fullfile(pathName,fileName); end end fileName=char(fileName); if nargin<2 || isempty(removeExcMets) removeExcMets=true; end if nargin<3 || isempty(removePrefix) removePrefix=true; end if nargin<4 supressWarnings=false; end

The user has attached the following files from their workspace:

  • curation/downloadGenomeData.m

TITLE: Improve MATLAB Help Descriptions and Input Validation for Genome Utility Functions


USER INTENT: Summarize the full conversation, which covers two sequential tasks: (1) rewriting help blocks for three MATLAB functions, and (2) adding nargin-style input validators to those same functions following an established RAVEN pattern.


TASK DESCRIPTION:

  • Rewrite the MATLAB help documentation for downloadGenomeData, getGeneData, and renameModelGenes following the structured style used in importModel and curateModelFromTables (Parameters / Returns / Examples / Notes / See also sections).
  • Add defensive input validators to each function using the nargin < N || isempty(...) pattern already used in RAVEN, including uigetfile prompts where appropriate, char() casts, default values, and descriptive error() messages.

EXISTING:
Completed:

  • downloadGenomeData.m — full structured help block written; input validation block added, including:
    • nargin < 1 || isempty(accession) guard with descriptive error
    • char() cast on accession
    • strncmpi format check for GCF_/GCA_ prefix
    • varargin parsed via a for loop with switch/case for 'outputDir' and 'verbose'
    • logMsg wrapper for conditional fprintf
    • Output variables gffFile and faaFile explicitly assigned at end of function
  • getGeneData.m — full structured help block written (input validation not yet added)
  • renameModelGenes.m — full structured help block written (input validation not yet added)

PENDING:

  • getGeneData.m — add nargin-style input validators for:
    • accession (required, char cast, GCF_/GCA_ prefix check)
    • outputFile (optional, default '')
    • gffFile (optional, default triggers downloadGenomeData)
    • faaFile (optional, default triggers downloadGenomeData)
  • renameModelGenes.m — add nargin-style input validators for:
    • model (required, must be a struct with .genes and .grRules fields)
    • geneTable (required, accept table or char path; if char, load with readtable)
    • fromCol (required, must be a valid column name in geneTable)
    • toCol (required, must be a valid column name in geneTable)

CODE STATE:

downloadGenomeData.m — validation block (completed):

function [gffFile, faaFile] = downloadGenomeData(accession, varargin)
% ... (structured help block) ...

% -------------------------------------------------------------------------
% Input validation
% -------------------------------------------------------------------------
if nargin < 1 || isempty(accession)
    error('downloadGenomeData:missingInput', ...
        ['accession is required. ', ...
         'Provide an NCBI assembly accession, e.g. ''GCF_000002595.2''.']);
end
accession = char(accession);

if ~any(strncmpi(accession, {'GCF_', 'GCA_'}, 4))
    error('downloadGenomeData:invalidAccession', ...
        ['Accession must start with ''GCF_'' (RefSeq) or ''GCA_'' (GenBank). ', ...
         'Received: ''%s''.'], accession);
end

% -------------------------------------------------------------------------
% Parse optional name-value arguments
% -------------------------------------------------------------------------
downloadDir = pwd;   % default: current working directory
verbose     = true;  % default: print progress

for i = 1:2:numel(varargin)
    if ~ischar(varargin{i}) && ~isstring(varargin{i})
        error('downloadGenomeData:invalidParam', ...
            'Parameter names must be character vectors or strings.');
    end
    switch lower(char(varargin{i}))
        case 'outputdir'
            if i+1 > numel(varargin) || isempty(varargin{i+1})
                error('downloadGenomeData:missingValue', ...
                    '''outputDir'' requires a non-empty directory path.');
            end
            downloadDir = char(varargin{i+1});
        case 'verbose'
            if i+1 > numel(varargin)
                error('downloadGenomeData:missingValue', ...
                    '''verbose'' requires a logical value.');
            end
            verbose = logical(varargin{i+1});
        otherwise
            error('downloadGenomeData:unknownParam', ...
                'Unknown parameter: ''%s''.', varargin{i});
    end
end

logMsg = @(varargin) verbose && fprintf(varargin{:});

% ......

</details>

@ae-tafur ae-tafur closed this Jun 10, 2026
Copilot AI requested a review from ae-tafur June 10, 2026 16:06
Copilot stopped work on behalf of ae-tafur due to an error June 10, 2026 16:06
@ae-tafur ae-tafur deleted the copilot/add-input-validation-and-help-blocks branch June 10, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants