omics.co.in logo omics.co.in
📜 15 Production Shell Scripts HPC SLURM • Conda • Multi-Core Batch POSIX Bash 5+ Compatible

Essential Shell Scripts for Bioinformatics & HPC Automation

Production-grade Bash scripts, parallel SLURM job array templates, Conda environment automation, and multi-core NGS batch workflows. Formatted with defensive programming practices (set -euo pipefail) for institutional supercomputing clusters and local Linux workstations.

15 scripts
HPC • SLURM slurm_paired_end_job_array.sh • Batch Array Task Execution

Parallelizes processing of 100+ paired-end sequencing samples using a SLURM job array. Reads sample names and FASTQ paths dynamically from a TSV manifest, executes inside high-speed node scratch ($TMPDIR), and automatically syncs outputs back to shared storage upon completion.

$ sbatch slurm_paired_end_job_array.sh samples.tsv SLURM Submission
HPC • GPU slurm_gpu_deepvariant.sh • NVIDIA A100 / V100 GPU Acceleration

Automates GPU-accelerated variant calling with DeepVariant or Dorado basecalling using NVIDIA container bindings. Leverages Apptainer/Singularity with --nv flags to execute convolutional neural network models in minutes.

$ sbatch slurm_gpu_deepvariant.sh sample.bam hg38.fa results/ NVIDIA CUDA GPU
HPC • MONITOR slurm_resource_monitor.sh • Real-Time Memory & CPU Profiler

Spawns a non-blocking background probe that samples target process memory (resident RSS in MB), CPU utilization, and I/O rates every 10 seconds. Prevents out-of-memory (OOM) killer terminations and determines exact cluster partition sizing.

$ ./slurm_resource_monitor.sh $PID resource_log.tsv & Background Daemon
ENVIRONMENT • UBUNTU setup_bioinformatics_workstation.sh • Idempotent OS Provisioner

Idempotent system provisioning script for Ubuntu 22.04 / 24.04 LTS. Installs C/C++ compiler toolchains, header libraries for SAM/BAM compression (zlib, bzip2, lzma), CMake, multi-core compression utilities (pigz, pbzip2), and Git version control.

$ sudo bash setup_bioinformatics_workstation.sh Root / Sudo Execution
ENVIRONMENT • CONDA install_miniforge_bioconda.sh • Fast Mamba & Channel Solver

Installs Miniforge3 non-interactively in user space without requiring root privileges. Configures Bioconda channels in strict priority order (conda-forge, bioconda, defaults) to prevent dependency conflicts and library incompatibilities.

$ bash install_miniforge_bioconda.sh User Space Installation
ENVIRONMENT • REPRODUCIBILITY conda_lock_and_export.sh • Publication Lockfile Generator

Generates dual environment lockfiles for publication compliance: an OS-portable multi-platform YAML (--no-builds) and a byte-for-byte explicit spec file containing direct package URLs and MD5 hashes.

$ ./conda_lock_and_export.sh omics-core ./env_exports/ Environment Snapshot
FASTQ • QC batch_fastq_qc_fastp.sh • Parallel Quality Trimming & MultiQC

Iterates through raw sequencing directories to discover paired-end files (_R1 / _R2). Executes fastp adapter and low-quality tail trimming multi-threaded, then compiles an aggregated MultiQC report.

$ ./batch_fastq_qc_fastp.sh raw_fastq/ clean_fastq/ 8 Multi-threaded Processing
FASTQ • SRA batch_sra_download_parallel.sh • NCBI SRA / ENA Batch Streaming

Batch downloads public sequencing runs from NCBI SRA using fasterq-dump. Streams outputs through multi-threaded pigz compression and verifies file checksums automatically.

$ ./batch_sra_download_parallel.sh srr_accessions.txt fastq_out/ 8 Parallel Downloads
FASTQ • SUBSAMPLE subsample_paired_fastq.sh • Deterministic Random Subsampler

Subsamples an exact number of reads (e.g. 100,000 pairs) from large sequencing libraries using seqtk sample with a fixed random seed. Preserves paired-end ordering and read synchronization perfectly.

$ ./subsample_paired_fastq.sh R1.fq.gz R2.fq.gz 500000 sub_R1.fq.gz sub_R2.fq.gz Preserved Pairing
BAM • ALIGNMENT batch_bam_sort_index_stats.sh • Multi-Threaded Sort & Index

Streamlines post-alignment processing: coordinate sorts raw SAM/BAM alignments multi-threaded, generates index files (.bai), compiles flagstat mapping rate summaries, and records chromosome counts.

$ ./batch_bam_sort_index_stats.sh raw_alignments/ sorted_bams/ 8 High-Throughput Alignment
BAM • COVERAGE bam_depth_target_bed.sh • Target Region Coverage Calculator

Calculates per-base and regional depth of coverage across target intervals in a capture panel or clinical exome. Summarizes mean depth and fraction of target bases covered at ≥ 1x, 10x, 20x, and 30x thresholds.

$ ./bam_depth_target_bed.sh sample.bam targets.bed coverage_report.tsv Clinical Sequencing Depth
BAM • EXTRACTION extract_unmapped_paired_reads.sh • Discordant & Unmapped Read Slicer

Extracts read pairs where both segments failed to align to the host reference (flag 12), collates by read name, and converts them into clean paired FASTQ files for viral pathogen hunting or non-host de novo assembly.

$ ./extract_unmapped_paired_reads.sh sample.bam unmapped_R1.fq.gz unmapped_R2.fq.gz 4 Pathogen Discovery
VCF • NORMALIZATION vcf_normalize_filter_tabix.sh • Left-Align & PASS Filter

Automates variant standardization: left-aligns indels against the reference genome build, splits multiallelic variants into biallelic rows, applies PASS and depth filters, and indexes with tabix.

$ ./vcf_normalize_filter_tabix.sh raw.vcf.gz ref.fa filtered.vcf.gz Variant Callset QC
VCF • STATS vcf_titv_and_stats_report.sh • Variant Callset Benchmark Report

Executes bcftools stats across multi-sample VCF callsets, parses transition/transversion (Ti/Tv) ratios, counts SNVs vs Indels, and evaluates homozygous vs heterozygous call distributions.

$ ./vcf_titv_and_stats_report.sh sample.vcf.gz stats_report.txt Quality Assessment
HPC • STORAGE hpc_scratch_cleanup_guard.sh • Scratch Quota & Temporary File Guard

Scans HPC scratch and cluster workspaces to identify orphan temporary files (.tmp.bam, uncompressed .sam, intermediate sort spills), reports directory disk footprints, and safely purges files older than 30 days.

$ ./hpc_scratch_cleanup_guard.sh /scratch/users/$USER 30 Quota Management