Main Content

bioinfo.pipeline.block.Save

Save pipeline outputs to MAT-file

Since R2024b

  • Save block icon

Description

A Save block enables you to save output variables from your pipeline to a MAT-file.

Creation

Description

b = bioinfo.pipeline.block.Save creates a Save block.

example

b = bioinfo.pipeline.block.Save(Name=Value) specifies additional options using one or more name-value arguments. The name-value arguments set the property names and values of a Save block.

Properties

expand all

Function to handle errors from the run method of the block, specified as a function handle. The handle specifies the function to call if the run method encounters an error within a pipeline. For the pipeline to continue after a block fails, ErrorHandler must return a structure that is compatible with the output ports of the block. The error handling function is called with the following two inputs:

  • Structure with these fields:

    FieldDescription
    identifierIdentifier of the error that occurred
    messageText of the error message
    indexLinear index indicating which block process failed in the parallel run. By default, the index is 1 because there is only one run per block. For details on how block inputs can be split across different dimensions for multiple run calls, see Bioinformatics Pipeline SplitDimension.

  • Input structure passed to the run method when it fails

Data Types: function_handle

This property is read-only.

Input ports of the block, specified as a structure. The field names of the structure are the names of the block input ports, and the field values are bioinfo.pipeline.Input objects. These objects describe the input port behaviors. The input port names are the expected field names of the input structure that you pass to the block run method.

The Save block Inputs structure has the field named Var1, which is a bioinfo.pipeline.datatype.Unset object. This input is required and must be satisfied. If you specify variables in the Variables property, the Inputs structure contains fields named after the variables.

Data Types: struct

This property is read-only.

Output ports of the block, specified as a structure. The field names of the structure are the names of the block output ports, and the field values are bioinfo.pipeline.Output objects. These objects describe the output port behaviors. The field names of the output structure returned by the block run method are the same as the output port names.

The Save block Outputs structure has a field named SaveFile, and the value is a bioinfo.pipeline.Output object.

Data Types: struct

Names of variables to save to the MAT-file, specified as a character vector, string scalar, string vector, or cell array of character vectors. The variable names must be valid and unique.

Setting this property specify the input ports of the block. For instance, if the property value is ["X","Y"], then the block has two input ports named X and Y, and the inputs to these ports are saved as variables named "X" and "Y" in the MAT-file.

Flag to save the input structure fields as variables, specified as numeric or logical true (1) or false (0).

The value of true indicates that the Save block expects a single input port accepting a scalar structure and its fields are saved as separate variables, instead of saving the structure itself. In other words, FromStruct=true has the same as behavior as calling save("filename.mat","-struct","S"). For details, see variables.

Name of the output MAT-file to save, specified as a character vector or string scalar.

Object Functions

compilePerform block-specific additional checks and validations
copyCopy array of handle objects
emptyInputsCreate input structure for use with run method
evalEvaluate block object
runRun block object

Examples

collapse all

Create a Bioinformatics pipeline.

P = bioinfo.pipeline.Pipeline;

Select an input FASTQ file using a FileChooser block.

fastqfile = bioinfo.pipeline.block.FileChooser(which("SRR005164_1_50.fastq"));

Create a SeqFilter block.

sequencefilter = bioinfo.pipeline.block.SeqFilter;

Define the filtering threshold value. Specifically, filter out sequences with a total of more than 10 low-quality bases, where a base is considered a low-quality base if its quality score is less than 20.

sequencefilter.Options.Threshold = [10 20];

Add the blocks to the pipeline.

addBlock(P,[fastqfile,sequencefilter]);

Connect the output port of fastqfile to the input port of sequencefilter.

out_port = string(fieldnames(fastqfile.Outputs));
in_port = string(fieldnames(sequencefilter.Inputs));
connect(P,fastqfile,sequencefilter,[out_port,in_port]);

Create a Save block to save the filtered sequence data to a MAT-file.

sb = bioinfo.pipeline.block.Save;

Set the Variables property of the Save block to the output variables of the sequencefilter block. When you run the pipeline, these variables are saved to the specified MAT-file.

vars2Save = string(fieldnames(sequencefilter.Outputs));
sb.Variables = vars2Save;
sb.OutputFilename = "seqfilter_results.mat";
addBlock(P,sb);
connect(P,sequencefilter,sb,["FilteredFASTQFiles","FilteredFASTQFiles"; ...
                             "NumFilteredIn","NumFilteredIn"; ...
                             "NumFilteredOut","NumFilteredOut"]);
run(P);

To see the location of the saved MAT-file, use unwrap.

r = results(P,sb);
unwrap(r.SaveFile)

Version History

Introduced in R2024b