This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Samtools View - What'S The Purpose Of The -T Option?

Here is what the docs say:

-t FILE This file is TAB-delimited. Each line must contain the reference name and the length of the reference, one line for each distinct reference; additional fields are ignored. This file also defines the order of the reference sequences in sorting. If you run ‘samtools faidx <ref.fa>’, the resultant index file <ref.fa>.fai can be used as this <in.ref_list> file.

I guess that tells me how to use it. But I'm wondering what the purpose is? What do people use this option for exactly? And what does it do?

samtools

1 answer

It's used for when you need to create a BAM out of a SAM, but your SAM file doesn't have a header. BAM files need information about the length of each reference, and this info is stored in the header.

For example, typical conversion of BAM -> SAM might be: [HTML] $ samtools view my.bam > my.sam [HTML] But trying to do the reverse results in an error: [HTML] $ samtools view -S -b my.sam > my.bam [samopen] no @SQ lines in the header. [sam_read1] missing header? Abort! [HTML]

One option is simply to include the header when making the SAM file in the first place: [HTML] $ samtools view -h my.bam > my.sam $ samtools view -S -b my.sam > my.bam.recreated [HTML] But sometimes this simple fix isn't possible (for example, maybe you don't have the original BAM), so the -t option lets you provide the data for the header.

Side note: the -T option lets you provide a FASTA for the same purpose, and the -H option lets you print the header alone from a BAM if you need to make a file for the -t arg.

Log in to answer this question.