Salmon

Description

According to the page of Salmon, Salmon is a tool for fast quantification of transcriptomes from RNA-seq data. It requires a set of target transcripts (reference or de novo assembly) and FASTA/FASTQ files with the reads.

Available Versions

  • salmon/0.14.0 (default)

Loading the Module

# Load Salmon
module load salmon/0.14.0

# Verify installation
salmon --version

Transcriptome Indexing

submit_salmon_index.sh
#!/bin/bash
#SBATCH -J salmon_index
#SBATCH -N 1
#SBATCH -c 8
#SBATCH -t 06:00:00
#SBATCH --mem=32G

export INPUT="transcripts.fasta"
export OUTPUT="transcripts_index/"

module load salmon/0.14.0

job-nanny salmon index -t transcripts.fasta -i transcripts_index -k 31

Quantification (mapping-based mode)

submit_salmon_quant.sh
#!/bin/bash
#SBATCH -J salmon_quant
#SBATCH -N 1
#SBATCH -c 8
#SBATCH -t 24:00:00
#SBATCH --mem=16G

export INPUT="reads_1.fastq reads_2.fastq"
export OUTPUT="sample_quant/"

module load salmon/0.14.0

job-nanny salmon quant -i transcripts_index -l A \
                 -1 reads_1.fastq -2 reads_2.fastq \
                 --validateMappings -o sample_quant \
                 -p $SLURM_CPUS_PER_TASK

Single-end Quantification

submit_salmon_single.sh
#!/bin/bash
#SBATCH -J salmon_single
#SBATCH -N 1
#SBATCH -c 8
#SBATCH -t 12:00:00
#SBATCH --mem=8G

export INPUT="reads.fastq"
export OUTPUT="sample_quant/"

module load salmon/0.14.0

job-nanny salmon quant -i transcripts_index -l A \
                 -r reads.fastq \
                 --validateMappings -o sample_quant \
                 -p $SLURM_CPUS_PER_TASK

Batch Processing with Script

submit_salmon_batch.sh
#!/bin/bash
#SBATCH -J salmon_batch
#SBATCH -N 1
#SBATCH -c 8
#SBATCH -t 72:00:00
#SBATCH --mem=16G

export INPUT="samples.txt"
export OUTPUT="all_quant/"

module load salmon/0.14.0

mkdir -p all_quant

# Create execution script
cat > run_salmon.sh << 'EOF'
#!/bin/bash

while IFS= read -r sample; do
    echo "Processing sample: $sample"

    if [ -f "${sample}_1.fastq" ] && [ -f "${sample}_2.fastq" ]; then
        # Paired-end
        salmon quant -i transcripts_index -l A \
            -1 ${sample}_1.fastq -2 ${sample}_2.fastq \
            --validateMappings -o all_quant/${sample} \
            -p $SLURM_CPUS_PER_TASK
    elif [ -f "${sample}.fastq" ]; then
        # Single-end
        salmon quant -i transcripts_index -l A \
            -r ${sample}.fastq \
            --validateMappings -o all_quant/${sample} \
            -p $SLURM_CPUS_PER_TASK
    else
        echo "Files not found for $sample"
    fi
done < samples.txt
EOF

chmod +x run_salmon.sh
job-nanny ./run_salmon.sh
samples.txt
sample1
sample2
sample3
sample4
sample5

Job Array for Multiple Samples

submit_salmon_array.sh
#!/bin/bash
#SBATCH -J salmon_array
#SBATCH --array=1-10
#SBATCH -N 1
#SBATCH -c 8
#SBATCH -t 24:00:00
#SBATCH --mem=16G

SAMPLES=(
    "sample1"
    "sample2"
    "sample3"
    "sample4"
    "sample5"
    "sample6"
    "sample7"
    "sample8"
    "sample9"
    "sample10"
)

SAMPLE=${SAMPLES[$SLURM_ARRAY_TASK_ID-1]}
export INPUT="${SAMPLE}_1.fastq ${SAMPLE}_2.fastq"
export OUTPUT="quant/${SAMPLE}/"

module load salmon/0.14.0

mkdir -p quant/${SAMPLE}

if [ -f "${SAMPLE}_1.fastq" ] && [ -f "${SAMPLE}_2.fastq" ]; then
    job-nanny salmon quant -i transcripts_index -l A \
                     -1 ${SAMPLE}_1.fastq -2 ${SAMPLE}_2.fastq \
                     --validateMappings -o quant/${SAMPLE} \
                     -p $SLURM_CPUS_PER_TASK
else
    job-nanny salmon quant -i transcripts_index -l A \
                     -r ${SAMPLE}.fastq \
                     --validateMappings -o quant/${SAMPLE} \
                     -p $SLURM_CPUS_PER_TASK
fi

Library Type Detection

submit_salmon_infer.sh
#!/bin/bash
#SBATCH -J salmon_infer
#SBATCH -N 1
#SBATCH -c 8
#SBATCH -t 06:00:00
#SBATCH --mem=8G

export INPUT="reads_1.fastq reads_2.fastq"
export OUTPUT="lib_type.txt"

module load salmon/0.14.0

job-nanny salmon quant -i transcripts_index -l A \
                 -1 reads_1.fastq -2 reads_2.fastq \
                 --validateMappings -o lib_test \
                 -p $SLURM_CPUS_PER_TASK

# Extract detected library type
grep "Library type" lib_test/logs/salmon_quant.log > lib_type.txt

Results Analysis

analyze_salmon.sh
#!/bin/bash
#SBATCH -J analyze_salmon
#SBATCH -N 1
#SBATCH -n 1
#SBATCH -t 04:00:00
#SBATCH --mem=8G

module load R/4.0.2

# Create quantification matrix
cat > create_matrix.R << 'EOF'
library(tximport)
library(rhdf5)
library(ggplot2)

# List quantification files
files <- list.files(path="quant", pattern="quant.sf",
                    recursive=TRUE, full.names=TRUE)
names(files) <- basename(dirname(files))

# Import with tximport
txi <- tximport(files, type="salmon", txOut=TRUE)

# Count matrix
counts <- txi$counts
tpm <- txi$abundance

write.table(counts, "counts_matrix.txt", sep="\t", quote=FALSE)
write.table(tpm, "tpm_matrix.txt", sep="\t", quote=FALSE)

# Summary statistics
stats <- data.frame(
    Sample = colnames(counts),
    Total_Counts = colSums(counts),
    Total_TPM = colSums(tpm),
    Detected = colSums(counts > 0)
)

write.table(stats, "summary_stats.txt",
            sep="\t", quote=FALSE, row.names=FALSE)

# PCA
pca <- prcomp(t(log2(tpm + 1)))
pca_df <- data.frame(pca$x[,1:2], Sample=colnames(tpm))

ggplot(pca_df, aes(x=PC1, y=PC2, label=Sample)) +
    geom_point() +
    geom_text(vjust=1, hjust=1) +
    theme_minimal() +
    labs(title="PCA of samples")
ggsave("pca_plot.png", width=8, height=6)
EOF

Rscript create_matrix.R

References

See also