Circular RNAs (circRNAs)

Step-by-Step Guide to Understanding Soft-Clipped and Hard-Clipped Reads in SAM/BAM Files

December 28, 2024 Off By admin
Shares

1. Introduction:

In bioinformatics, when performing read alignment (typically with tools like BWA, Bowtie, or HISAT2), we encounter two common types of clipping in the CIGAR string of SAM (Sequence Alignment/Map) files: soft-clipping and hard-clipping. These terms describe how parts of the read sequence are treated when they do not align with the reference genome. Understanding the difference between these two types of clipping is crucial for accurate data interpretation, especially when analyzing read alignments, variant calling, and genome assembly.

2. What Are Soft-Clipped and Hard-Clipped Reads?

  • Soft-Clipped Reads:
    • Soft-clipping occurs when a part of the read sequence does not align to the reference genome, but the bases are still retained in the sequence.
    • These bases are marked as clipped (i.e., they are excluded from the alignment) but remain part of the read.
    • The soft-clipped bases can be used in downstream processes, such as detecting variants or aligning to a different sequence.
    • In SAM files, soft-clipped bases are denoted by the CIGAR string using S (soft-clipped). For example, 5S20M means 5 bases are soft-clipped, and 20 bases align to the reference.
  • Hard-Clipped Reads:
    • Hard-clipping occurs when bases at the ends of the read are not only excluded from the alignment but are also removed from the sequence entirely.
    • These clipped bases do not appear in the sequence field of the SAM file. The read length is adjusted to reflect this removal.
    • Hard-clipped reads are less flexible since the clipped bases are discarded and cannot be used in further analysis.
    • In SAM files, hard-clipped bases are denoted by H in the CIGAR string. For example, 5H20M means 5 bases are hard-clipped, and 20 bases align to the reference.

3. Why Are Soft-Clipped and Hard-Clipped Reads Important?

Understanding the use of clipped reads is crucial in various bioinformatics applications, such as:

  • Read Alignment and Variant Calling: Soft-clipping can help align difficult or repetitive regions by allowing mismatches at the ends of the read, whereas hard-clipping can help clean up low-quality bases.
  • Genome Assembly: In some cases, clipped bases may represent novel sequences that could be useful for de novo assembly or uncovering structural variants.
  • Error Detection: Clipping can help identify sequencing errors at the ends of reads that could interfere with the accuracy of the alignment.
  • Transcriptome Analysis: In RNA-Seq data, soft-clipping can indicate exon-exon junctions or alternatively spliced regions, providing insights into the transcript structure.

4. Detailed Explanation of Clipping in SAM Files:

The CIGAR string in a SAM file provides information about how the read aligns to the reference. The different operations in the CIGAR string (like M, I, D, S, H) represent different aspects of the alignment, including clipped bases.

For example:

  • M (match) represents bases that align to the reference genome.
  • I (insertion) represents bases that are inserted in the read but not in the reference.
  • D (deletion) represents bases that are deleted from the read but exist in the reference.
  • S (soft-clipping) represents bases that are excluded from the alignment but are retained in the read sequence.
  • H (hard-clipping) represents bases that are excluded from the alignment and removed from the sequence.

Example:

Consider the following CIGAR strings:

  • 5S20M: 5 bases are soft-clipped, and 20 bases align to the reference.
  • 5H20M: 5 bases are hard-clipped, and 20 bases align to the reference.

5. How to Extract and Analyze Soft-Clipped and Hard-Clipped Reads in SAM/BAM Files:

You can use tools like samtools to manipulate and analyze SAM/BAM files. Below are some examples of common tasks related to soft-clipped and hard-clipped reads:

  • Extract Reads with Soft-Clipping (S): You can use samtools to extract soft-clipped reads by filtering based on the CIGAR string.
    bash
    samtools view input.bam | awk '{if($6 ~ /S/) print $0}' > soft_clipped_reads.sam
  • Extract Reads with Hard-Clipping (H): Similarly, you can extract hard-clipped reads.
    bash
    samtools view input.bam | awk '{if($6 ~ /H/) print $0}' > hard_clipped_reads.sam
  • Count the Number of Soft- or Hard-Clipped Reads: To count the number of soft-clipped reads in a BAM file:
    bash
    samtools view input.bam | awk '{if($6 ~ /S/) count++} END {print count}'

    For hard-clipped reads:

    bash
    samtools view input.bam | awk '{if($6 ~ /H/) count++} END {print count}'

6. Use Case Scenarios:

  • Soft Clipping in RNA-Seq: Soft-clipping is particularly useful in RNA-Seq applications where reads often map to exon-exon junctions, and soft-clipping allows the detection of these junctions without discarding the remaining part of the read.
  • Hard Clipping for Quality Control: Hard-clipping can be applied when there is low-quality data at the ends of the read (such as adapter contamination or poor sequencing quality). By removing these bases, the integrity of the alignment is preserved.

7. Conclusion: Understanding the difference between soft-clipped and hard-clipped reads is essential for proper interpretation of sequencing data. Soft-clipping provides flexibility by retaining the clipped bases for further analysis, while hard-clipping removes them entirely, making it a cleaner but less flexible option. Both types of clipping serve specific purposes in different bioinformatics workflows, such as aligning reads to genomes, detecting variants, and improving sequencing quality.

8. Summary:

  • Soft-Clipped: Bases are excluded from alignment but remain in the sequence and can be used for further analysis.
  • Hard-Clipped: Bases are excluded and removed from the sequence; they cannot be used in further analysis.
  • Use tools like samtools to extract, count, and analyze these reads.

By understanding and utilizing soft and hard clipping effectively, bioinformaticians can make more informed decisions in their data analysis processes.

Shares