anvi-get-short-reads-from-bam

Get short reads back from a BAM file with options for compression, splitting of forward and reverse reads, etc.

🔙 To the main page of anvi’o programs and artifacts.

Authors

Requires

bam-file

Can use

profile-db contigs-db bin

Provides

short-reads-fasta

Usage

Get short reads from a bam-file in the form of short-reads-fasta).

The purpose of this program is not to replace more efficient tools to recover short reads from BAM files such as samtool. Since it was designed to address much more subtle needs, this program may have a huge memory fingerprint for very large and numerous BAM files.

Using this program you can,

  • Get all reads from one or more BAM files
  • Get reads matching to contig names found in any bin in a collection
  • Get reads matching to contig names found in one or more specific bins in a collection
  • Get all reads matching to a specific contig name
  • Get reads matching to a specific region of a specific contig name

In addition, you can use the previously-defined fetch filters via the --fetch-filter parmeter to get only short reads satisfy a particular set of criteria (i.e., those that are in forward-forward or reverse-reverse orientation, those that have a template length longer than 1,000 nucleotides, and so on). For a complete set of fetch filters you can use, please see the help menu of the program.

The program can report all reads in a single file, or you can ask reads to be split into R1 and R2 files for mapping results of paired-end sequences using the flag --split-R1-and-R2. In this case, reads that are not paired will be reported in a file with the prefix _UNPAIRED.fa.

Reads reported as a FASTA will contain necessary information in their deflines to recover which BAM file, contig, sample they are from with explicit start/stop positions on the contig to which they matched.

Getting all reads

A basic run of this program is as follows:

anvi-get-short-reads-from-bam BAM_FILE_1.bam BAM_FILE_2.bam (…) \ --output-file OUTPUT.fa

This will report all short reads found in BAM files BAM_FILE_1.bam and BAM_FILE_2.bam and store them into a single file. You can use as many BAM files as you wish.

Narrowing the input with anvi’o files:

You can choose to only return the short reads that are contained within a collection:

anvi-get-short-reads-from-bam BAM_FILE_1.bam BAM_FILE_2.bam \ -c contigs-db \ -p profile-db \ -C collection \ --output-file OUTPUT.fa

Or in a bin that is described in a collection:

anvi-get-short-reads-from-bam BAM_FILE_1.bam BAM_FILE_2.bam \ -c contigs-db \ -p profile-db \ -C collection \ -b bin \ --output-file OUTPUT.fa

Focusing on individual contigs

You can get all reads mapped to a contig:

anvi-get-short-reads-from-bam BAM_FILE_1.bam BAM_FILE_2.bam \ --target-contig CONTIG_NAME \ --output-file OUTPUT.fa

Or define explicit start/stop positions on it:

anvi-get-short-reads-from-bam BAM_FILE_1.bam BAM_FILE_2.bam \ --target-contig CONTIG_NAME \ --target-region-start 100 \ --target-region-end 1000 \ --output-file OUTPUT.fa

In this mode, the program will fetch any read that includes a nucleotide that matches to anywhere in the region defined by the user. Which means, if the user sets --target-region-start to 100 and --target-region-end to 101, all reads that have a nuclotide mapping to the 100th position will be returned.

Changing the output format

You can split the output based on the directionality of paired-end reads. Adding the tag --split-R1-and-R2 causes the program to create three separate output files: one for R1 (sequences in the forward direction), one for R2 (sequences in the reverse direction; i.e. reverse complement of R1 sequences), and one for unparied reads. When doing this, you can name these three files with a prefix by using the flag -O.

anvi-get-short-reads-from-bam -o path/to/output \ --split-R1-and-R2 \ -O BAM_1_and_BAM_2 \ BAM_FILE_1.bam BAM_FILE_2.bam

You can also compress the output by adding the flag --gzip-output.

Edit this file to update this information.

Command line interface

The following is the list of parameters and their descriptions in the latest version of anvi-get-short-reads-from-bam.

The code that generates this web page ensures that this information is the latest available in 9-dev (eunice). Which means, in some cases the information in this section (generated automatically) might be more comprehensive or up-to-date compared to the descriptions above (written by humans).


Command line usage

anvi-get-short-reads-from-bam [-h] [-p PROFILE_DB] [-c CONTIGS_DB] [-C COLLECTION_NAME] [-b BIN_NAME] [-B FILE_PATH] [--target-contig CONTIG_NAME] [--target-region-start NUCLEOTIDE_POSITION] [--target-region-end NUCLEOTIDE_POSITION] [--fetch-filter FILTER] [-o FILE_PATH] [-O FILENAME_PREFIX] [-X] [-Q] BAM FILE[S] [BAM FILE[S] ...]

Parameters and their descriptions

positional arguments
BAM FILE[S] required
BAM file(s) to access to recover short reads
INPUT OPTION #1 Work with good'ol anvi'o databases, collections, and bins, and get all the reads from one or more BAM files that match to the contigs matching to your selections.
-p, --profile-db PROFILE_DB
Anvi'o profile database
-c, --contigs-db CONTIGS_DB
Anvi'o contigs database generated by 'anvi-gen-contigs-database'
-C, --collection-name COLLECTION_NAME
Collection name.
-b, --bin-id BIN_NAME
Bin name you are interested in.
-B, --bin-ids-file FILE_PATH
Text file for bins (each line should be a unique bin id).
INPUT OPTION #2 Target a specific contig and/or specific start/stop positions to get all the matching reads from your BAM file(s).
--target-contig CONTIG_NAME
Contig name of interest.
--target-region-start NUCLEOTIDE_POSITION
The start position of the region of interest.
--target-region-end NUCLEOTIDE_POSITION
The end position of the region of interest.
FILTERS Choose which reads to work (or not to work) with like a pro.
--fetch-filter FILTER
By default, anvi'o fetches all reads from a BAM file. Once a read is 'fetched', some reads may be excluded if you have used parameters such as `--min-percent-identity`. But the `--fetch-filter` is different as it determines WHICH reads from a BAM file will be used for profiling at all. You can do a lot of fun things with this parameter. For details, please read the online documentation for `anvi-profile` using the URL you should see at the end of the `--help` output on your terminal. The known filters are the following: proper-pairs, double-forwards, double-reverses, inversions, distant-inversions, single-mapped-reads, distant-pairs-1K.
OUTPUT Output options
-o, --output-file FILE_PATH
File path to store results.
-O, --output-file-prefix FILENAME_PREFIX
A prefix to be used while naming the output files. No file type extensions please; just a prefix -- all ouptut file names and extensions will be appended to this prefix.
-X, --gzip-output
When declared, output file(s) will be gzip compressed and the extension `.gz` will be added.
-Q, --split-R1-and-R2
When declared, this program outputs 3 FASTA files for paired-end reads: one for R1, one for R2, and one for unpaired reads.

Additional Resources

Are you aware of resources that may help users better understand the utility of this program? Please feel free to edit this file on GitHub. If you are not sure how to do that, find the __resources__ tag in this file to see an example.