Main Content

srafasterqdump

Download FASTQ or FASTA files from SRA

Since R2024a

Description

outputFileNames = srafasterqdump(accessionNumbers) downloads the corresponding files from SRA (Sequence Read Archive) [1] for the specified accession numbers and returns the names of the downloaded files.

srafasterqdump requires the SRA Toolkit for Bioinformatics Toolbox™. If this support package is not installed, then the function provides a download link. For details, see Bioinformatics Toolbox Software Support Packages.

example

outputFileNames = srafasterqdump(accessionNumbers,SRAFasterqDumpOptions) uses additional options specified by SRAFasterqDumpOptions.

example

outputFileNames = srafasterqdump(accessionNumbers,Name=Value) specifies additional options using one or more name-value arguments. For example, you can specify to retrieve the FASTA-formatted file using the FastaOutput name-value argument.

example

Examples

collapse all

Download some paired-end sequencing data in a FASTQ format using an accession run number SRR11846824 that has two reads per spot and has no unaligned reads. Downloading the data may take a few minutes.

tbl = srafasterqdump("SRR11846824")
tbl=1×2 table
                          Reads_1                  Reads_2       
                   _____________________    _____________________

    SRR11846824    "SRR11846824_1.fastq"    "SRR11846824_2.fastq"

By default, the function uses the SplitType="SplitThree" option and downloads only biological reads. Specifically, the function splits spots into reads. For spots having two reads, the function produces *_1.fastq and *_2.fastq, represented by the Reads_1 and Reads_2 columns. If there are any unaligned reads, the function saves unaligned reads in a *.fastq file, which would be represented by the Reads column. Because there are no unaligned reads within this accession, the function did not produce a *.fastq file, and the output table has no Reads column. For details, see SplitType.

You can also specify other download options using SRAFasterqDumpOptions. For instance, use FastaOutput=true to get the FASTA-formatted file.

sraopt = SRAFasterqDumpOptions;
sraopt.FastaOutput = true;
tbl2 = srafasterqdump("SRR11846824",sraopt);

Alternatively, you can specify the options as name-value arguments instead of using the options object.

tbl2 = srafasterqdump("SRR11846824",FastaOutput=true);

You can also download the data in a SAM format using srasamdump.

samFile = srasamdump("SRR11846824")
samFile = 
"SRR11846824.sam"

Specify the download options using an SRASAMDumpOptions object. For instance, specify the output file name and compress the output file using bzip2.

samdumpopt = SRASAMDumpOptions;
samdumpopt.OutputFileName = "SRR11846824.sam.bz2";
samdumpopt.BZip2 = true
samdumpopt = 
  SRASAMDumpOptions with properties:

   Default properties:
       ExtraCommand: ""
        FastaOutput: 0
        FastqOutput: 0
               GZip: 0
      HideIdentical: 0
         IncludeAll: 0
      MinMapQuality: 0
      OutputPrimary: 0
    OutputUnaligned: 0
            Version: "3.0.6"

   Modified properties:
     OutputFileName: "SRR11846824.sam.bz2"
              BZip2: 1

bzFile = srasamdump("SRR11846824",samdumpopt)
bzFile = 
"SRR11846824.sam.bz2"

After downloading the SAM file, you can use it for downstream analyses. For instance, you can use bowtie2 to map the reads to the reference sequence.

First, download the C. elegans reference sequence.

celegans_refseq = fastaread("https://s3.amazonaws.com/igv.broadinstitute.org/genomes/seq/ce11/ce11.fa");

Save Chromosome 3 reference data in a FASTA file.

celegans_chr3   = celegans_refseq(3).Sequence;
warnState = warning;
warning('off','Bioinfo:fastawrite:AppendToFile'); 
fastawrite("celegans_chr3.fa",celegans_chr3);
warning(warnState);

Build a set of index files using bowtie2build. The status value of 0 means that the build was successful.

status = bowtie2build("celegans_chr3.fa","celegans_chr3_index");

Align read data to the reference. This may take a few minutes.

bowtie2("celegans_chr3_index","SRR11846824_1.fastq","SRR11846824_2.fastq","SRR11846824_mapped.sam");

Create a quality control plot for the SAM file. Note that, for this particular experiment, most of the reads happen to have the same quality score of 30.

seqqcplot("SRR11846824_mapped.sam");

Figure SRR11846824_mapped.sam contains 5 axes objects and another object of type annotationpane. Axes object 1 with title Quality Boxplot, xlabel Base Position, ylabel Quality Score contains 505 objects of type line. Axes object 2 with title Base Composition, xlabel Base Position, ylabel Reads (%) contains 5 objects of type bar. These objects represent A, C, G, T, Other. Axes object 3 with title Quality Distribution, xlabel Average Quality, ylabel Reads (%) contains an object of type bar. Axes object 4 with title GC Distribution, xlabel % GC-Content, ylabel Reads (%) contains an object of type bar. Axes object 5 with title Length Distribution, xlabel Length, ylabel Reads (%) contains an object of type bar.

Convert the SAM file to a BAM file. Suppress two informational warnings that are issued while creating a BioMap object.

w = warning;
warning("off","bioinfo:BioMap:BioMap:UnsortedReadsInSAMFile");
warning("off","bioinfo:saminfo:InvalidTagField");
bmObj = BioMap("SRR11846824_mapped.sam");
write(bmObj,"SRR11846824_mapped.bam",Format="BAM");
warning(w);

Visualize the alignment data in the Genomics Viewer app. The corresponding cytoband file is provided with the toolbox.

gv = genomicsViewer(ReferenceFile="celegans_chr3.fa",CytoBand="celegans_cytoBandIdeo.txt.gz");
addTracks(gv,"SRR11846824_mapped.bam");

Use the zoom slider to zoom in and see the features. Or you can enter the following in the search text box: Generated:3,711,861-3,711,940.

You may delete the downloaded files, such as the reference sequence file.

delete celegans_chr3.fa

Close the app.

close(gv);

Input Arguments

collapse all

Accession run numbers, specified as a character vector, string scalar, string vector, or cell array of character vectors.

An accession run number could be in one of these formats: SRR____, ERR____ , or DRR____, which contains actual sequencing data for a particular sequencing experiment. An experiment can contain several runs depending on the number of sequencing instrument runs required. For details about the formats of SRA accession numbers, see Understanding SRA Search Results.

For more information on searching for an SRA accession number, see Search in SRA Entrez.

Example: "SRR1553607"

Data Types: char | string | cell

srafasterqdump options, specified as an SRAFasterqDumpOptions object, character vector, or string scalar. The character vector or string scalar must be in the original fasterq-dump option syntax (prefixed by one or two dashes).

Name-Value Arguments

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: tbl = srafasterqdump("SRR000077",FastaOutput=true) specifies to download the FASTA-formatted file.

Flag to append new data to the output file instead of overwriting it, specified as a numeric or logical 1 ( true) or 0 (false). By default, the output file is overwritten with new data.

Data Types: double | logical

Flag to concatenate sequence information pertaining to each spot, specified as a numeric or logical 1 (true) or 0 (false). By default, the software does not concatenate the information pertaining to each spot. That is, the software writes four lines of FASTQ or two lines of FASTA into one output file for each spot. For details, see FASTQ/FASTA concatenated.

Data Types: double | logical

Additional commands, specified as a character vector or string scalar.

The commands must be in the native syntax (prefixed by one or two dashes). Use this option to apply undocumented flags and flags without corresponding MATLAB® properties.

Example: ExtraCommand="--fasta-ref-tbl --internal-ref"

Data Types: char | string

Flag to save the output in the FASTA format, specified as a numeric or logical 1 (true) or 0 (false). The default output format is the FASTQ format.

Data Types: double | logical

Flag to split sequence information pertaining to each spot without preserving the spot order, specified as a numeric or logical 1 (true) or 0 (false).

If the value is true, the software splits the sequence information in each spot is into reads. For each read, two lines of FASTA are written into the single output file. Setting FastaOutputUnsorted=true is the same as setting SplitType=SplitSpot, with the following exceptions:

  • With FastaOutputUnsorted=true, the original order of the spots and reads is not preserved, and FastaOutputUnsorted name-value argument is exclusively for the FASTA output.

  • This setting is faster than the SplitSpot option and does not use temporary files.

Data Types: double | logical

String of bases used to filter the output, specified as a string scalar. The output is filtered by comparing it to the specified string of bases and keeping reads that include the specified string of bases.

Data Types: string

Flag to include all object properties with corresponding default values when converting properties to the original option syntax, specified as a numeric or logical 1 (true) or 0 (false). You can convert properties to the original syntax prefixed by one or two dashes (such as '-e 8 --split-file') by using the getCommand function.

When IncludeAll=false and you call getCommand(optionsObject), the software converts only the specified properties. If the value is true, getCommand converts all available properties, using default values for unspecified properties, to the original syntax.

Note

If you set IncludeAll to true, the software converts all available properties, using default values for unspecified properties. The only exception is when the default value of a property is NaN, Inf, [], '', or "". In this case, the software does not translate the corresponding property.

Data Types: logical | double

Flag to include technical reads in the downloaded files, specified as a numeric or logical 1 (true) or 0 (false).

Data Types: double | logical

Minimum length required for a read to be included in the output, specified as a nonnegative integer. By default, no read is filtered out.

Data Types: double

Number of parallel threads to use, specified as a positive integer. The software runs threads on separate processors or cores. Increasing the number of threads generally improves the runtime significantly, but also increases the memory footprint.

Data Types: double

Folder where the output files are saved, specified as a character vector or string scalar. By default, the software saves the files in the current directory.

Data Types: char | string

Base name of the output files, specified as a character vector or string scalar. The default base name is the accession run number.

Data Types: char | string

Method used to split sequence information pertaining to each spot, specified as one of the following:

  • "SplitThree" — The software splits spots into reads. For each read, the software writes four lines of FASTQ or two lines of FASTA. For spots with two reads, the software produces *_1.fastq and *_2.fastq files. The software places unmated reads in *.fastq. If the accession does not have any spot with one single read, the software does not create a *.fastq file. For details, see FASTQ/FASTA split 3.

  • "SplitSpot" — The software splits spots into reads. For each read, the software writes four lines of FASTQ or two lines of FASTA. All the reads are saved to a single output file. For details, see FASTQ/FASTA split spot.

  • "SplitFiles" — The software splits spots into reads. For each read, the software writes four lines of FASTQ or two lines of FASTA. The software assigns each read a number n, where 1 ≤ n ≤ 5, and then saves each nth read to the nth file (*_n.fastq). For details, see FASTQ/FASTA split file.

By default, the reads refer to biological reads only. However, if you set IncludeTechnical to true, then the software also includes the technical reads in the output files.

Data Types: char | string

Output Arguments

collapse all

Names of downloaded files, returned as a table. The total number of output files varies depending on the SplitType option and the accession run number. The table can contain one to five columns. The possible column names are: Reads, Reads_1, Reads_2, Reads_3, Reads_4, and Reads_5. Only five of the six column names can appear for a given SplitType option and accession number.

For example, the Reads column could correspond to the single output file produced when you specify SplitType="SplitSpot". The Reads_n columns, where 1 ≤ n ≤ 5, correspond to the output files produced when you specify SplitType="SplitThree" or SplitType="SplitFiles".

More About

collapse all

Biological and Technical Reads

Biological reads are actual sequence data that comes from a biological sample.

Technical reads correspond to technical information, such as adapters, primers, barcodes, and so on. Technical reads are not part of the actual biological sample sequence.

Spot

A spot refers to a location on the flow cell for Illumina® sequencers. All of the bases for a single location constitute a spot, which includes technical reads. For details, see https://www.biostars.org/p/12047/.

Version History

Introduced in R2024a