Matlab Build Biopipeline
ASecurityBuild, run, debug, and manage multi-step data processing pipelines and workflows using the Biopipeline Designer app or bioinfo.pipeline.Pipeline (requires Bioinformatics Toolbox). Use when the user wants to chain processing steps into a reusable pipeline or workflow, run many samples or files through the same steps, cache results and re-run only what changed, or build and edit a visual workflow, in any domain: bioinformatics (FASTQ QC, alignment, RNA-Seq), signal, image, sensor, or tabular da...
- 1,414 stars
- 0 votes
- 0 copies
- 0 views
- Added December 5, 2026
Security analysis
100/100Pro scans all 4 files and shows the line behind each finding
npx -y skills add matlab/matlab-agentic-toolkit --skill matlab-build-biopipeline --agent claude-codeAre you the author of Matlab Build Biopipeline?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/matlab-matlab-build-biopipeline)---
name: matlab-build-biopipeline
description: >
Build, run, debug, and manage multi-step data processing pipelines and
workflows using the Biopipeline Designer app or bioinfo.pipeline.Pipeline
(requires Bioinformatics Toolbox). Use when the user wants to chain processing
steps into a reusable pipeline or workflow, run many samples or files through
the same steps, cache results and re-run only what changed, or build and edit
a visual workflow, in any domain: bioinformatics (FASTQ QC, alignment,
RNA-Seq), signal, image, sensor, or tabular data. Covers pre-made and
UserFunction blocks, connecting, compiling, running, inspecting results,
diagnosing failures, and modifying existing pipelines. Load alongside the
relevant domain skill for the steps inside each block.
license: https://www.mathworks.com/content/dam/mathworks/license/pmrl/license.md
metadata:
author: MathWorks
version: "1.0"
---
# Build Bioinformatics Toolbox Pipelines
Build and manage `bioinfo.pipeline.Pipeline` workflows. The pipeline framework provides a block-based dataflow engine with automatic result caching, partial re-execution, parallel dispatch, and visual editing via the Biopipeline Designer app. Applies to any domain — bioinformatics, signal processing, data science, IoT, imaging.
## When to Use
- Building multi-step data processing workflows with `bioinfo.pipeline.Pipeline`
- Connecting blocks (pre-made or UserFunction) in a pipeline
- Running, re-running, or partially executing pipelines
- Diagnosing pipeline compilation or runtime failures
- Inspecting pipeline results or block outputs
- Modifying existing pipelines (insert, remove, reconnect blocks)
- Working with the Biopipeline Designer app or `.plprj` files
- Processing multiple samples/files through the same pipeline
- Wrapping custom MATLAB functions as pipeline blocks
- Building non-bioinformatics workflows (sensor data, signal processing, data science, ML feature pipelines) using UserFunction blocks
## When NOT to Use
- Calling bioinformatics functions directly without a pipeline (use `matlab-analyze-bioinformatics-data`)
- Choosing which functions go inside blocks: load the domain skill alongside this one (e.g. `matlab-analyze-bioinformatics-data`, `matlab-process-images`, `matlab-prepare-signal-data`, `matlab-analyze-data`)
- Installing external tools (Bowtie2, BWA, Cufflinks — those are support packages)
- One-off scripts or loops where the user hasn't asked for a pipeline or workflow and doesn't need caching or re-runs
## Workflow
Every pipeline follows this lifecycle:
1. **Create** — `P = bioinfo.pipeline.Pipeline`
2. **Add blocks** — `addBlock(P, blockObject, "BlockName")`
3. **Connect** — `connect(P, "Source", "Target", ["OutPort", "InPort"])`
4. **Compile** — `compile(P)` or `compile(P, inputStruct)`
5. **Run** — `run(P)` or `run(P, inputStruct)`
6. **Results** — `P.results("BlockName")` and `processTable(P)`
Run the pipeline code with `evaluate_matlab_code`, or save it as a script and use `run_matlab_file`.
## Key Functions
### Pipeline Methods
| Method | Purpose |
|--------|---------|
| `addBlock(P, block, name)` | Add a block with a name (name is 3rd positional arg) |
| `connect(P, src, tgt, portMap)` | Connect blocks via `["OutPort", "InPort"]` port map |
| `disconnect(P, src, tgt)` | Remove all connections between two blocks |
| `compile(P)` or `compile(P, inputStruct)` | Validate structure; provide inputs for unconnected ports |
| `run(P)` or `run(P, inputStruct)` | Execute pipeline |
| `wait(P)` | Block until pipeline finishes |
| `P.results("BlockName")` | Get outputs as a struct (access fields by port name — no 3-arg form). Use dot-notation to avoid variable shadowing. |
| `processTable(P)` | Table of block status, timestamps, errors |
| `findBlock(P, "Name")` | Get block handle by name |
| `portMap(P, "Src", "Tgt")` | Show connections between two blocks |
| `removeBlock(P, "Name")` | Remove a block (also removes its connections) |
| `renameBlock(P, "Old", "New")` | Rename a block |
| `inputNames(P)` | List unconnected pipeline-level input port names |
| `deleteResults(P, "Name")` | Clear cached results for a block |
### Pipeline.run Options
| Option | Purpose |
|--------|---------|
| `From="BlockName"` | Run from this block to the end |
| `To="BlockName"` | Run from start to this block |
| `Only=["A","B"]` | Run exactly these blocks |
| `RunMode="Minimal"` | (Default) Skip blocks with cached results |
| `RunMode="Full"` | Force re-run (combine with `From`/`To`/`Only` to limit scope) |
| `UseParallel=true` | Distribute across parallel pool workers |
| `ResultsDirectory="path"` | Where to write output files |
| `DisplayLevel="Info"` | Logging: "Off", "Error", "Warn", "Info", "Debug" |
`From`/`To`/`Only` restrict which blocks *may* run; up-to-date blocks are still skipped in Minimal mode. To force a re-run, add `RunMode="Full"` or call `deleteResults(P, "Block")` first. Editing a UserFunction's `.m` file is not detected either: after changing helper code, re-run with `RunMode="Full"` or the cached result is silently reused. Pass the same `ResultsDirectory` on every run: a re-run without it switches to the default `PipelineResults` folder, so earlier results are gone and a `From`/`Only` run finds nothing upstream ("No processes completed").
### Block Constructors
Pre-made blocks are in `bioinfo.pipeline.block.*`:
| Block | Purpose |
|-------|---------|
| `FileChooser` | Pipeline input: provides file paths (**absolute paths only** — use `fullfile(pwd, ...)`) |
| `SeqTrim` | Trim FASTQ reads by quality (`Method="MeanQuality", Threshold=N`) |
| `SeqFilter` | Filter FASTQ reads by length (`Method="MinLength", Threshold=N`) |
| `SeqSplit` | Demultiplex by barcodes |
| `Bowtie2` / `BwaMEM` | Align reads |
| `Bowtie2Build` / `BwaIndex` | Build alignment index |
| `FeatureCount` | Count reads per genomic feature |
| `BLASTN/P/X`, `TBLASTN/X` | BLAST searches |
| `MakeBlastDatabase` | Build BLAST database |
| `BamSort` / `SamSort` | Sort alignment files |
| `Concatenate` | Merge inputs (2 by default; N via `InputNames`) |
| `Save` | Save results to MAT file (no `Options`: set `OutputFilename`, `Variables` as properties) |
| `Load` | Load from MAT file |
| `UserFunction` | Wrap any custom function |
See `references/block-port-reference.md` for all port names — consult when connecting blocks.
## Patterns
### Connecting Blocks
The `connect` function requires **4 arguments**: pipeline, source block name, target block name, and a port map as an N×2 string array.
```matlab
% Single-port connection
connect(P, "Trimmer", "Filter", ["TrimmedFASTQFiles", "FASTQFiles"]);
% Multi-port connection (N×2 array)
connect(P, "Reader", "Processor", ["audioData", "audioData"; ...
"sampleRate", "sampleRate"]);
% Fan-out: one output to multiple downstream blocks
connect(P, "Reader", "Filter", ["sampleRate", "sampleRate"]);
connect(P, "Reader", "Writer", ["sampleRate", "sampleRate"]);
```
### Discovering Port Names
Inspect a block's `.Inputs` and `.Outputs` properties to find valid port names:
```matlab
b = bioinfo.pipeline.block.SeqTrim;
fieldnames(b.Inputs) % "FASTQFiles"
fieldnames(b.Outputs) % "TrimmedFASTQFiles", "NumTrimmed", "NumUntrimmed"
```
For UserFunction blocks, port names match `RequiredArguments` (inputs) and `OutputArguments` (outputs). `NameValueArguments` become optional input ports (set `b.Inputs.<name>.Value`; UserFunction has no `Options`).
**Port properties (every block):** inputs have `Required`, `Value`, `SplitDimension`; outputs have `Required`, `UniformOutput` (default `true`). `SplitDimension` controls per-file execution: per-sample blocks (SeqTrim, SeqFilter, SeqSplit, SamSort, BamSort, BwaIndex, aligner read ports, BLAST queries, SRA) default to `"all"` and run once per file. **UserFunction** inputs and aggregating blocks (FeatureCount, Save, Load, Concatenate, Cuff*, index/database ports) default to `[]` and receive all files in one call. To run a UserFunction per file: `b.Inputs.<port>.SplitDimension = "all"`. If each run returns something that can't be concatenated (a table, struct, or different-size array), also set `b.Outputs.<port>.UniformOutput = false`; results are then a cell with one entry per run (`res.data{1}`), and a per-run block downstream receives each one as a 1x1 cell, so unwrap it: `UserFunction(@(T) scoreAdjust(T{1}), ...)`. Otherwise the run reports "results ... could not be concatenated" and returns an `Incomplete` result.
### Providing Pipeline Inputs
Unconnected input ports become pipeline-level inputs. Satisfy them in one of two ways:
```matlab
% Option A: Pass inputStruct to compile and run
inputStruct.FASTQFiles = "reads.fastq";
compile(P, inputStruct);
run(P, inputStruct);
% Option B: Set .Value directly on the port
b = findBlock(P, "Trimmer");
b.Inputs.FASTQFiles.Value = "reads.fastq";
compile(P);
run(P);
% Option C: FileChooser accepts files in constructor (MUST be absolute paths)
fcBlock = bioinfo.pipeline.block.FileChooser(fullfile(pwd, "file1.fastq"));
```
The inputStruct field names must match the port names returned by `inputNames(P)`. Use `string` values (not char arrays — char gets split into individual characters).
### Building with Pre-Made Blocks
```matlab
P = bioinfo.pipeline.Pipeline;
% Blocks can accept options in their constructors
addBlock(P, bioinfo.pipeline.block.FileChooser(files), "Input");
addBlock(P, bioinfo.pipeline.block.SeqTrim(Method="MeanQuality", Threshold=20), "Trim");
addBlock(P, bioinfo.pipeline.block.SeqFilter(Method="MinLength", Threshold=50), "Filter");
addBlock(P, bioinfo.pipeline.block.Save, "Output");
connect(P, "Input", "Trim", ["Files", "FASTQFiles"]);
connect(P, "Trim", "Filter", ["TrimmedFASTQFiles", "FASTQFiles"]);
connect(P, "Filter", "Output", ["FilteredFASTQFiles", "Var1"]);
compile(P);
run(P);
```
### Building with UserFunction Blocks
```matlab
% Wrap any function — use RequiredArguments and OutputArguments
readBlock = bioinfo.pipeline.block.UserFunction(@readtable, ...
RequiredArguments="filename", OutputArguments="data");
cleanBlock = bioinfo.pipeline.block.UserFunction(@rmmissing, ...
RequiredArguments="data", OutputArguments="cleanData");
% For complex functions, write a helper .m file and reference by name or handle
filterBlock = bioinfo.pipeline.block.UserFunction(@myFilterFunction, ...
RequiredArguments=["data", "threshold"], ...
OutputArguments=["filtered", "removed"], ...
NameValueArguments="Verbose");
```
Helper functions must be on the MATLAB path. Use `addpath` before running the pipeline. See `references/userfunction-guide.md` for advanced patterns.
### Modifying an Existing Pipeline
```matlab
% Insert a block between two connected blocks
disconnect(P, "Trimmer", "Save");
addBlock(P, bioinfo.pipeline.block.SeqFilter(Method="MinLength", Threshold=50), "Filter");
connect(P, "Trimmer", "Filter", ["TrimmedFASTQFiles", "FASTQFiles"]);
connect(P, "Filter", "Save", ["FilteredFASTQFiles", "Var1"]);
compile(P);
run(P); % Reuses cached Trimmer results automatically
```
### Inspecting Results
```matlab
% Block status overview
T = processTable(P); % Columns: Block, Status, RunStart, RunEnd, RunErrors
% Get specific block outputs — use dot-notation to avoid variable shadowing
res = P.results("Filter"); % Returns struct with one field per output port
res.FilteredFASTQFiles % bioinfo.pipeline.datatype.File object
res.NumFilteredIn % numeric (array if multi-sample)
res.NumFilteredOut % numeric (array if multi-sample)
% Extract file path from File objects
filePath = unwrap(res.FilteredFASTQFiles); % Returns actual string path
```
### Diagnosing Failures
The pipeline does **not** throw a MATLAB error when a block fails. It stores the error and continues. Always check `processTable` after a run:
```matlab
run(P);
T = processTable(P);
disp(T); % Shows Block, Status, RunStart, RunEnd, RunErrors columns (no row names: use T.RunEnd{T.Block == "Name"})
% Find failed blocks (Status column is a cell array)
for i = 1:height(T)
statuses = T.Status{i}; % May be an array for multi-sample runs
errCell = T.RunErrors{i}; % Successful runs hold empty MExceptions
for k = reshape(find(statuses == bioinfo.pipeline.RunStatus.Error), 1, [])
msg = "(no message recorded)";
if k <= numel(errCell)
e = errCell{k};
if ~isempty(e), msg = e(1).message; end
end
fprintf("Block %s (run %d) failed: %s\n", T.Block(i), k, msg);
end
end
% Fix and re-run from the failed block
run(P, From="FailedBlockName");
```
### Partial Re-execution
```matlab
% Force re-run from a specific block onward (skips earlier blocks)
run(P, From="Align", RunMode="Full");
% Run only out-of-date blocks among these
run(P, Only=["Align", "Count"]);
% Force full re-run (ignore cache)
run(P, RunMode="Full");
% Invalidate one block's cache, then let Minimal mode handle the rest
deleteResults(P, "Align");
run(P); % Re-runs Align and everything downstream
```
### Multi-Sample Execution
Pass all files as a flat array to one pipeline run. Per-sample blocks process each file independently; UserFunction blocks receive the whole array unless you set `SplitDimension` (see Port properties above):
```matlab
% Gather all sample files
allFiles = strings(1, 0);
for s = ["sampleA", "sampleB", "sampleC"]
allFiles = [allFiles, fullfile(samplesDir, s + "_R1.fastq")]; %#ok<AGROW>
end
fcBlock = bioinfo.pipeline.block.FileChooser(allFiles);
% ... add blocks, connect ...
compile(P);
run(P, UseParallel=true, ResultsDirectory="myResults");
% Multi-sample results are arrays (one value per sample):
res = P.results("Filter");
res.NumFilteredIn % e.g. [17 15 18] — one per sample
res.NumFilteredOut % e.g. [3 5 2]
% Paired-end mates must go to one run together: keep both files in a single call
filt = bioinfo.pipeline.block.SeqFilter(Method="MeanQuality", Threshold=20);
filt.Options.PairedFiles = true;
filt.Inputs.FASTQFiles.SplitDimension = []; % default "all" sends each mate to its own run, and every run fails
% If some per-sample runs failed, results is an Incomplete object: index only the completed runs.
% Blocks downstream of the failed block do not run at all, even for the inputs that succeeded:
% their results are empty (completed() is []). Put the step that can fail and everything after it
% in the last block (one UserFunction), so its completed runs hold the final values.
if isa(res, "bioinfo.pipeline.datatype.Incomplete")
ok = find(completed(res));
keptCounts = res.NumFilteredIn(ok); % index in the same expression: res.NumFilteredIn alone errors
end
```
### Biopipeline Designer App
```matlab
% Open a pipeline in the visual editor
biopipelineDesigner(P)
% Open a saved project file
biopipelineDesigner("myProject.plprj")
% Load .plprj back into code (.plprj is a MAT file)
data = load("myProject.plprj", "-mat");
P = data.plprjData.Pipeline;
```
**Live updates:** The designer reflects programmatic changes to the pipeline handle in real time. After opening the app, continue modifying `P` via `addBlock`, `connect`, `renameBlock`, `removeBlock`, etc. — the canvas updates automatically. Do NOT call `biopipelineDesigner(P)` again after modifications (this opens a duplicate window).
**Stale results (yellow warning triangle):** When you modify a block's Options, rename it, or change its connections, the designer marks affected blocks with a yellow ⚠ icon meaning "results are out of date." This is NOT a compilation error — `compile(P)` will not resolve it. The only fix is to re-run the affected block(s):
```matlab
% Re-run just the stale block
run(P, Only="StaleBlockName");
% Or re-run from that block onward (also refreshes downstream)
run(P, From="ModifiedBlock");
```
**Layout:** Canvas layout (block positions, zoom, sizing) and app-level settings can't be set from code. After adding or modifying blocks programmatically, tell the user: "You may want to rearrange blocks on the canvas — drag them manually or use the Auto-Arrange button in the toolstrip."
**Modifying a live pipeline:** When the user asks to rename, remove, or rewire blocks in a pipeline that is already open in the designer, use the Pipeline handle methods directly — do not edit the source script and re-run it:
```matlab
% Rename a block (updates live in designer)
renameBlock(P, "OldName", "NewName");
% Remove and re-add with different config
removeBlock(P, "Filter");
addBlock(P, bioinfo.pipeline.block.SeqFilter(Method="MinLength", Threshold=75), "Filter");
connect(P, "Trim", "Filter", ["TrimmedFASTQFiles", "FASTQFiles"]);
```
Note: Only the app's File → Save menu creates valid `.plprj` files. There is no programmatic save-to-plprj function.
## Common Mistakes
| Mistake | Why It Fails | Correct Approach |
|---------|-------------|-----------------|
| `connect(P, "Block/OutPort", "Block/InPort")` | Slash notation doesn't exist | `connect(P, "Src", "Tgt", ["OutPort", "InPort"])` |
| `connect(P, "Src", "Tgt", "PortName")` | Port map must be N×2 array | `["OutPort", "InPort"]` as 4th argument |
| `addBlock(P, block, Name="MyBlock")` | Name is positional, not name-value | `addBlock(P, block, "MyBlock")` |
| `block.Name = "MyBlock"` | Blocks have no `.Name` property | Name only via `addBlock` third argument |
| `SeqFilter(MinLength=50)` or `SeqTrim(MeanQuality=20)` | Method names are not NV-pairs | `SeqFilter(Method="MinLength", Threshold=50)` |
| `UserFunction(@f, InputArguments="x")` | Wrong parameter name | `RequiredArguments="x"` |
| `compile(P)` with unconnected inputs | Compile fails on unsatisfied ports | `compile(P, inputStruct)` or set `.Value` on ports |
| `results(P)` without block name | Method requires a block name | `P.results("BlockName")` returns a struct |
| `results(P, "Block", "Port")` | No 3-arg form exists | `res = P.results("Block"); res.PortName` |
| Using `char` for file paths in inputStruct | Char arrays get split into characters | Use `string` ("file.fastq") not char ('file.fastq') |
| `P.Connections` or `P.Blocks.Name` | `P.Connections` doesn't exist; `P.Blocks` is a block array and blocks have no `.Name` | `portMap(P, "A", "B")`, `P.BlockNames`, `findBlock(P, "Name")` |
| Assuming pipeline throws on block error | Errors are logged to the command window and stored in processTable, but not thrown | Always check `processTable(P)` after `run`; `P.results` on a never-run or fully failed block errors; after a partial failure it returns an `Incomplete` object: index completed runs with `r.Port(find(completed(r)))`. Blocks downstream of a failed run do not run for any input, so read results from the block that partly failed |
| `save(P, "file.plprj")` | No save method on Pipeline | Use app's File → Save, or `save("file.mat", "P")` |
| Relative paths in FileChooser | FileChooser requires absolute paths | Use `fullfile(pwd, ...)` or absolute string |
| `results(P, "Block")` fails with "Unable to use as index" | A workspace variable named `results` shadows the method | Use `P.results("Block")` (dot-notation) — always safe |
| Calling `biopipelineDesigner(P)` after modifying `P` | Opens a duplicate app window | Modify `P` via handle methods — the open designer updates live |
| Editing a script and re-running to rename a block | Rebuilds the entire pipeline, loses cached results | Use `renameBlock(P, "Old", "New")` on the live handle (keeps upstream results; the renamed block and downstream re-run) |
| Running `compile(P)` to clear the yellow ⚠ icon | Staleness means results are out of date, not a compilation error | `run(P, Only="BlockName")` or `run(P, From="BlockName")` |
## Conventions
- **Pipeline is a handle class.** All methods modify it in-place. Do not reassign: `addBlock(P, b, "X")` not `P = addBlock(P, b, "X")`.
- **Absolute paths for file inputs.** FileChooser requires absolute paths; use them in inputStruct too.
- **Always check `processTable` after `run`.** The pipeline does not throw on block failure.
- **Use `unwrap()` on File outputs.** Pipeline file results are `bioinfo.pipeline.datatype.File` objects, not strings. Inside a UserFunction, file inputs arrive as plain paths, so don't call `unwrap` there. A path a UserFunction returns stays a plain string in the results; `unwrap` on a string calls the phase-unwrap function and errors.
- **Pre-made blocks over UserFunction.** If a pre-made block exists for the task, use it — it handles I/O types, splitting, and error recovery automatically.
- **Helper .m files for UserFunction (recommended).** Anonymous and local-function handles work in serial runs; named functions on the MATLAB path are most robust and needed for parallel workers.
- **`RunMode="Minimal"` is the default.** Pipelines automatically skip blocks with valid cached results.
- **`removeBlock` also removes connections.** After removing and re-adding a block, you must re-connect it.
----
Copyright 2026 The MathWorks, Inc.
----
Files in this skill
- SKILL.md
- manifest.yaml
- references/block-port-reference.md
- references/userfunction-guide.md
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.