samtools samples [options] (<input>|stdin)
samtools samples [options] -X f1.bam f2.bam ... f1.bam.bai f2.bam.bai ...
Print the sample names found in the read-groups and the path to the reference genome from alignment files. The output of this tool can be used to create an input for any popular workflow manager. The input is a list of SAM/BAM/CRAM files, or the path to those files can be provided via stdin. The output is tab-delimited containing the sample name as the first column, the path to the alignment file as the second column, the path to the reference genome as a third optional column and a single character flag (Y/N) indicating whether the alignment file is indexed or not as a fourth optional column. If no reference is found for an alignment, a dot (.) will be used in the reference path column. If no sample is available in any read-group header, a dot (.) will be used as the sample name. If a BAM file contains more than one sample, one line will be printed for each sample.
print help and exit
print a header
test if the file is indexed. Add an extra column to the output with a single character value (Y/N).
provide the sample tag name from the @RG line [SM].
output file [stdout].
load an indexed fasta file in the collection of references. Can be used multiple times. Add an extra column with the path to the reference file.
read a file containing the paths to indexed fasta files. One path per line.
use a custom index file.
$ samtools samples -h S*.bam *.sam #SM PATH S1 S1.bam S2 S2.bam S3 S3.bam S4 S4.bam S5 S5.bam . example.sam
$ samtools samples -i -h S*.bam *.sam #SM PATH INDEX S1 S1.bam Y S2 S2.bam Y S3 S3.bam Y S4 S4.bam Y S5 S5.bam Y . example.sam N
$ samtools samples -i -h -X S1.bam S2.bam S1.bam.bai S2.bam.bai #SM PATH INDEX S1 S1.bam Y S2 S2.bam Y
$ find . -type f \( -name "S*.bam" -o -name "S*.bai" \) | sort | paste - - | samtools samples -i -h -X #SM PATH INDEX S1 ./S1.bam Y S2 ./S2.bam Y S3 ./S3.bam Y S4 ./S4.bam Y S5 ./S5.bam Y
$ samtools samples -h -T LB S*.bam #LB PATH S1 S1.bam S2 S2.bam S3 S3.bam S4 S4.bam S5Lib1 S5.bam S5Lib2 S5.bam
$ find . -type f \( -name "S*.bam" -o -name "*.cram" \) | samtools samples -h #SM PATH S5 ./S5.bam S2 ./S2.bam S4 ./S4.bam S3 ./S3.bam S1 ./example.cram S1 ./S1.bam
$ samtools samples -h -f reference.fa -f example.fa S*.bam *.sam *.cram #SM PATH REFERENCE S1 S1.bam reference.fa S2 S2.bam reference.fa S3 S3.bam reference.fa S4 S4.bam reference.fa S5 S5.bam reference.fa . example.sam example.fa S1 example.cram example.fa
$ cat references.list reference.fa example.fa $ samtools samples -h -F references.list S*.bam *.sam *.cram #SM PATH REFERENCE S1 S1.bam reference.fa S2 S2.bam reference.fa S3 S3.bam reference.fa S4 S4.bam reference.fa S5 S5.bam reference.fa . example.sam example.fa S1 example.cram example.fa
Written by Pierre Lindenbaum from Institut du Thorax U1087, Nantes, France.
Samtools website: <http://www.htslib.org/>
Copyright © 2023 Genome Research Limited (reg no. 2742969) is a charity registered in England with number 1021457. Terms and conditions.