samtools-view(1) | Bioinformatics tools | samtools-view(1) |
samtools-view - views and converts SAM/BAM/CRAM files
samtools view [options] in.sam|in.bam|in.cram [region...]
With no options or regions specified, prints all alignments in the specified input alignment file (in SAM, BAM, or CRAM format) to standard output in SAM format (with no header).
You may specify one or more space-separated region specifications after the input filename to restrict output to only those alignments which overlap the specified region(s). Use of region specifications requires a coordinate-sorted and indexed input file (in BAM or CRAM format).
The -b, -C, -1, -u, -h, -H, and -c options change the output format from the default of headerless SAM, and the -o and -U options set the output file name(s).
The -t and -T options provide additional reference data. One of these two options is required when SAM input does not contain @SQ headers, and the -T option is required whenever writing CRAM output.
The -L, -M, -N, -r, -R, -d, -D, -s, -q, -l, -m, -f, -F, -G, and --rf options filter the alignments that will be included in the output to only those alignments that match certain criteria.
The -p, option sets the UNMAP flag on filtered alignments then writes them to the output file.
The -x, -B, --add-flags, and --remove-flags options modify the data which is contained in each alignment.
The -X option can be used to allow user to specify customized index file location(s) if the data folder does not contain any index file. See EXAMPLES section for sample of usage.
Finally, the -@ option can be used to allocate additional threads to be used for compression, and the -? option requests a long help message.
Important note: when multiple regions are given, some alignments may be output multiple times if they overlap more than one of the specified regions.
Examples of region specifications:
This option saves time spent on compression/decompression and is thus preferred when the output is piped to another samtools command.
If the reference file is not local, but is accessed instead via an https://, s3:// or other URL, the index file will need to be supplied by the server alongside the reference. It is possible to have the reference and index files in different locations by supplying both to this option separated by the string "##idx##", for example:
-T ftp://x.com/ref.fa##idx##ftp://y.com/index.fa.fai
However, note that only the location of the reference will be stored in the output file header. If this method is used to make CRAM files, the cram reader may not be able to find the index, and may not be able to decode the file unless it can get the references it needs using a different method.
For a list of flag names see samtools-flags(1).
If the list starts with a `^' then it is negated and treated as a request to remove all tags except those in STR. The list may be empty, so -x ^ will remove all tags.
Note that tags will only be removed from reads that pass filtering.
Note that tags will only be removed from reads that pass filtering.
This option first scans the requested region, using the RNEXT and PNEXT fields of the records that have the PAIRED flag set and pass other filtering options to find where paired reads are located. These locations are used to build an expanded region list, and a set of QNAMEs to allow from the new regions. It will then make a second pass, collecting all reads from the originally-specified region list together with reads from additional locations that match the allowed set of QNAMEs. Any other filtering options used will be applied to all reads found during this second pass.
As this option links reads using RNEXT and PNEXT, it is important that these fields are set accurately. Use 'samtools fixmate' to correct them if necessary.
Note that this option does not work with the -c, --count; -U, --output-unselected; or -p, --unmap options.
samtools view -bo aln.bam aln.sam
If @SQ lines are absent:
samtools faidx ref.fa samtools view -bt ref.fa.fai -o aln.bam aln.sam
where ref.fa.fai is generated automatically by the faidx command.
samtools view -C -T ref.fa -o aln.cram aln.bam
samtools view -C --output-fmt-option store_md=1 --output-fmt-option store_nm=1 -o aln.cram aln.bam samtools view --input-fmt-option decode_md=0 -o aln.new.bam aln.cram
samtools view -O cram,store_md=1,store_nm=1 -o aln.cram aln.bam samtools view --input-fmt cram,decode_md=0 -o aln.new.bam aln.cram
samtools view [options] -X /data_folder/data.bam /index_folder/data.bai chrM:1-10
samtools view -r grp2 -o /data_folder/data.rg2.bam /data_folder/data.bam
samtools view -D BC:barcodes.txt -o /data_folder/data.barcodes.bam /data_folder/data.bam
samtools view -d RG:grp2 -o /data_folder/data.rg2_only.bam /data_folder/data.bam
samtools view -h --remove-flags DUP -x dt -o /data_folder/dat.no_dup_markings.bam /data_folder/data.bam
Written by Heng Li from the Sanger Institute.
samtools(1), samtools-tview(1), sam(5)
Samtools website: <http://www.htslib.org/>
2 September 2022 | samtools-1.16.1 |