Chapter 5 Samtools

Samtools Website

Samtools is a suite of programs used for interacting with high-throughput sequencing data, particularly in the context of microbiome research. It provides essential tools for manipulating and analyzing BAM, SAM, and CRAM files, which are formats for storing large nucleotide sequence alignments. In microbiome studies, Samtools is used to sort, index, and filter alignment data, enabling researchers to efficiently process and analyze metagenomic and metatranscriptomic sequences, assess microbial diversity, and identify microbial taxa and functional genes within complex microbial communities.

5.1 Use Samtools

Samtools already installed in group directory, you can just update your path to use samtools by running the following:

export PATH=/mnt/vstor/SOM_PQHS_LXZ716/software/Samtools/bin:$PATH

To check if Samtools has been successfully installed, you can perform the following steps:

samtools --version

5.2 Install Samtools

If you want to download and install your own Samtools, follow these steps:

  1. Download the Source Code:

Download the source code for Samtools from the official website:

https://www.htslib.org/download/

  1. Upload to HPC: Upload the downloaded file to your HPC environment.

  2. Unzip the File: Once uploaded, unzip the file using the following command:

tar -xvjf samtools-1.20.tar.bz2
  1. Change Directory: Navigate to the Samtools directory:
cd samtools-1.20
  1. Configure the Installation: Configure the installation by running (replace /where/to/install with your desired installation directory):
./configure --prefix=/where/to/install
  1. Compile the Source Code: Compile the source code using:
make
  1. Install Samtools: Install Samtools by running:
make install
  1. Update Your PATH: The executable programs will be installed in a bin subdirectory under your specified prefix. Add this directory to your $PATH to access the programs easily (replace /where/to/install with your specified installation directory):
export PATH=/where/to/install/bin:$PATH

5.3 Convert BAM to FASTQ

samtools bam2fq "$bam_file" > "$fastq_file"

This line runs Samtools to convert the BAM file to a FASTQ file.