Contenuto principale

generateCode

R2026b

Generate MATLAB code to recreate bioinformatics pipeline

Since R2026b

Description

generateCode(pipeline) generates a MATLAB function that recreates pipeline and opens an untitled function file containing the function definition in the MATLAB editor. By default, the generated function is called createPipeline.

example

generateCode(pipeline,fileName) specifies the function file name fileName.

example

generateCode(___,Name=Value) specifies additional options using one or more name-value arguments.

example

code = generateCode(___) returns the generated MATLAB function as a textual output. If you do not specify an output argument, the function does not return anything at the command line.

example

Examples

collapse all

Generate MATLAB code that recreates a bioinformatics pipeline.

Import the pipeline and block objects needed for the example.

import bioinfo.pipeline.Pipeline
import bioinfo.pipeline.blocks.*

Create a pipeline with two blocks and connect them.

p = Pipeline;
sf = addBlock(p,SeqTrim);
st = addBlock(p,SeqFilter);
connect(p,sf,st,["TrimmedFASTQFiles","FASTQFiles"]);

Generate code for the pipeline. The generated function opens in the MATLAB editor.

generateCode(p)

Save the generated code to a file.

generateCode(p,"createPipeline.m")

Generate code with default values included and without opening the editor. Return the generated code as a string.

myCode = generateCode(p,IncludeDefaultValues=true,OpenEditor=false);

Input Arguments

collapse all

Bioinformatics pipeline, specified as a bioinfo.pipeline.Pipeline object.

Name of the MATLAB function file, specified as a character vector or string scalar. Specify a file name or a full or relative file path with the file name. The function automatically adds the file extension (.m) as needed.

By default, the function creates the file in the current directory if you do not specify the full or relative file path.

Data Types: char | string

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: generateCode(pipeline,"myFcn.m",IncludeDefaultValues=true) generates myFcn.m in the current directory and the file includes code for properties that have the same value as their default.

Flag to include comments in the generated MATLAB code, specified as a numeric or logical 1 (true) or 0 (false).

Data Types: double | logical

Flag to generate code for block properties that have the same value as their default, specified as a numeric or logical 1 (true) or 0 (false).

Data Types: double | logical

Flag to show the generated code in the MATLAB editor, specified as "auto", true (1), or false (0). The default ("auto") option is to show the generated code in the MATLAB editor only when you do not specify the file name as the second input or you do not specify an output argument.

Data Types: double | logical | char | string

Flag to overwrite the existing file, specified as a numeric or logical 1 (true) or 0 (false). If false, generateCode errors if fileName already exists.

Data Types: double | logical

Output Arguments

collapse all

Generated MATLAB function, returned as a string scalar.

Version History

Introduced in R2026b