Agent skill

Bio Alignment Sorting

by GPTomics in GPTomics/bioSkills

Sort alignment files by coordinate or read name using samtools and pysam.

MITAuto-check passedResearch & Science

Install Bio Alignment Sorting

skills CLI
$ npx skills add GPTomics/bioSkills --skill bio-alignment-sorting -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install GPTomics/bioSkills bio-alignment-sorting --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/GPTomics/bioSkills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/alignment-files/alignment-sorting .claude/skills/bio-alignment-sorting && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
bio-alignment-sorting
GitHub stars
1.2k
Used in
2 other repos
Token cost
~2.6k tokens
SKILL.md length
747 words
Files
3
Skills in repo
553
Repo updated
First seen
Licence
MIT

At a glance

Sort alignment files by coordinate or read name using samtools and pysam.

  • Preparing BAM files for indexing
  • SKILL.md covers Version Compatibility, Sort Orders, samtools sort and samtools collate vs sort -n, plus 3 more sections
  • Runs Shell scripts from its folder; calls pip
  • Variant calling

What it does

Bio Alignment Sorting is an agent skill from GPTomics/bioSkills. Sort alignment files by coordinate or read name using samtools and pysam. Use when preparing BAM files for indexing, variant calling, or paired-end analysis.

Its SKILL.md is about 2.6k tokens, which your agent loads only when the skill is triggered. The skill folder holds 3 other files (for example `examples/sort_pipeline.sh` and `usage-guide.md`).

It sits in Research & Science, covering Bioinformatics. It works with pysam and Python. The repository describes itself as: a set of SKILLS.md for doing bioinformatics with agents like claude code. The licence is MIT.

When your agent uses it

  • Preparing BAM files for indexing
  • Variant calling
  • Paired-end analysis

Example prompts

  • “/bio-alignment-sorting”

Requirements

  • Python 3
  • A Bash shell

What it can do on your machine

Read from SKILL.md and the folder at commit d91ed3d. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships script files (Shell), which the agent can run.

    Shell commands in SKILL.md call:

    • pip

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use pip, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Bio Alignment Sorting loads about 2.6k tokens when it runs. Until then it costs about 45 tokens; SKILL.md has 747 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~45
When it runs · the whole SKILL.md, loaded when a task matches
~2.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from GPTomics/bioSkills at commit d91ed3d, republished under its MIT licence (© GPTomics). 747 words, ~2,585 tokens.

Download SKILL.mdSave it as .claude/skills/bio-alignment-sorting/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
bio-alignment-sorting
description
Sort alignment files by coordinate or read name using samtools and pysam. Use when preparing BAM files for indexing, variant calling, or paired-end analysis.
tool_type
cli
primary_tool
samtools

Version Compatibility

Reference examples tested with: pysam 0.22+, samtools 1.19+

Before using code patterns, verify installed versions match. If versions differ:

  • Python: pip show <package> then help(module.function) to check signatures
  • CLI: <tool> --version then <tool> --help to confirm flags

If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.

Alignment Sorting

Sort alignment files by coordinate or read name using samtools and pysam.

"Sort a BAM file" -> Reorder reads by genomic coordinate (for indexing/variant calling) or by name (for paired-end processing).

  • CLI: samtools sort -o sorted.bam input.bam
  • Python: pysam.sort('-o', 'sorted.bam', 'input.bam')

Sort Orders

OrderFlagUse Case
CoordinatedefaultIndexing, visualization, variant calling
Name-nPaired-end processing, fixmate, markdup
Tag-t TAGSort by specific tag value

samtools sort

Sort by Coordinate (Default)
bash
samtools sort -o sorted.bam input.bam
Sort by Read Name
bash
samtools sort -n -o namesorted.bam input.bam
Multi-threaded Sorting
bash
samtools sort -@ 8 -o sorted.bam input.bam
Control Memory Usage
bash
samtools sort -m 4G -@ 4 -o sorted.bam input.bam
Set Temporary Directory
bash
samtools sort -T /tmp/sort_tmp -o sorted.bam input.bam
Specify Output Format
bash
# Output as BAM (default)
samtools sort -O bam -o sorted.bam input.bam

# Output as CRAM
samtools sort -O cram --reference ref.fa -o sorted.cram input.bam
Sort by Tag
bash
# Sort by cell barcode (10x Genomics)
samtools sort -t CB -o sorted_by_barcode.bam input.bam
Pipe from Aligner
bash
bwa mem ref.fa reads.fq | samtools sort -o aligned.bam

samtools collate vs sort -n

ToolAlgorithmSpeedMemoryOutput guarantee
sort -nFull lexicographic sort by QNAMESlowestSpills to -TStrict total order by name
collateHash-bucket grouping~3-10x fasterBoundedMates adjacent; between-mate order undefined

Use collate when extracting paired FASTQ, re-aligning, or streaming through markdup. Use sort -n only when a tool requires true lexicographic name order (e.g. RSEM, Salmon alignment-mode).

bash
# Fast paired FASTQ extraction
samtools collate -O -u in.bam tmp_prefix | \
    samtools fastq -1 R1.fq.gz -2 R2.fq.gz -0 /dev/null -s /dev/null -n -

# Markdup pre-processing (collate beats sort -n here)
samtools collate -O -u in.bam tmp_prefix | \
    samtools fixmate -m -u - - | \
    samtools sort -u - | \
    samtools markdup - out.bam
Sort Order Required by Downstream Tool
OperationRequired sort
samtools indexcoordinate (hard requirement)
samtools fixmate -mname (or collate; needs mates adjacent)
samtools markdupcoordinate (after fixmate)
GATK MarkDuplicatesSparkcoordinate or queryname
samtools mpileup / bcftools mpileupcoordinate
GATK HaplotypeCaller, Mutect2coordinate
featureCounts / HTSeqcoordinate or name (-p for paired)
umi_tools dedupcoordinate (with index)
fgbio GroupReadsByUmiany order accepted (template-coordinate recommended to avoid an internal re-sort)
fgbio CallMolecularConsensusReadsgrouped by MI tag (consumes GroupReadsByUmi output)
Sniffles, cuteSV, Manta, Dellycoordinate (need SA tags)
Salmon alignment-modename
RSEM (with STAR --quantMode TranscriptomeSAM)name (hard requirement)

Check Sort Order

From Header
bash
samtools view -H input.bam | grep "^@HD"
# SO:coordinate = coordinate sorted
# SO:queryname = name sorted
# SO:unsorted = not sorted
Verify Sorted
bash
# Check if coordinate sorted (returns 0 if sorted). Reset the position tracker
# on each new contig, else the POS reset at every chromosome boundary of a
# correctly sorted multi-contig BAM would falsely report "unsorted".
samtools view input.bam | awk '$3!=c {c=$3; prev=0} $4<prev {exit 1} {prev=$4}'
# Simpler and authoritative: trust the @HD SO: header shown above.

pysam Python Alternative

Sort with pysam
python
import pysam

pysam.sort('-o', 'sorted.bam', 'input.bam')
Sort by Name
python
pysam.sort('-n', '-o', 'namesorted.bam', 'input.bam')
Sort with Options
python
pysam.sort('-@', '4', '-m', '2G', '-o', 'sorted.bam', 'input.bam')
Avoid In-Python Sorting

Do not load BAM records into a list and call sorted(). pysam.sort() calls samtools' external-merge sort which spills to disk; loading reads into memory blows up around ~30M reads (~10 GB human BAM). Always delegate to pysam.sort():

python
import pysam

pysam.sort('-@', '4', '-m', '2G', '-T', '/tmp/sortpfx',
           '-o', 'sorted.bam', 'input.bam')
Check Sort Order in pysam
python
import pysam

with pysam.AlignmentFile('input.bam', 'rb') as bam:
    hd = bam.header.get('HD', {})
    sort_order = hd.get('SO', 'unknown')
    print(f'Sort order: {sort_order}')
Stream Sort from Aligner

For streaming from aligners, use shell pipes (simpler and more reliable):

python
import subprocess

subprocess.run(
    'bwa mem ref.fa reads.fq | samtools sort -o aligned.bam',
    shell=True, check=True
)

samtools merge

Combine multiple BAM files into one. samtools merge does NOT validate sort-order consistency across inputs; mismatched inputs silently produce a malformed output.

Verify Sort Order Consistency First
bash
for f in *.bam; do samtools view -H "$f" | head -1; done | sort -u
# Should print exactly ONE line, e.g. "@HD VN:1.6 SO:coordinate"
Show full SKILL.md (322 more words)Show less
Safe Merge (dedup @RG and @PG)
bash
# -c deduplicates @RG records; -p deduplicates @PG records (samtools-merge(1))
samtools merge -c -p -@ 8 merged.bam sample1.bam sample2.bam sample3.bam

When merging BAMs from different lanes / machines / aligners, RG IDs may collide. -c and -p deduplicate header records, but RG IDs that genuinely refer to different lane-level read groups must be made unique upstream (samtools addreplacerg) before merge -- otherwise GATK BQSR (which keys models by RGID/PU) silently produces wrong recalibration.

Merge with Threads / from File List
bash
samtools merge -@ 4 merged.bam sample1.bam sample2.bam sample3.bam
samtools merge -b files.txt merged.bam   # one BAM path per line
Force Overwrite
bash
samtools merge -f merged.bam sample1.bam sample2.bam
Merge Specific Region
bash
samtools merge -R chr1:1000000-2000000 merged_region.bam sample1.bam sample2.bam
pysam Merge
python
import pysam

pysam.merge('-c', '-p', '-f', 'merged.bam', 'sample1.bam', 'sample2.bam', 'sample3.bam')

Common Workflows

Goal: Combine sorting with other alignment processing steps into efficient pipelines.

Approach: Pipe aligner output directly into samtools sort to avoid writing unsorted intermediates, then index for downstream access.

Align and Sort
bash
bwa mem -t 8 ref.fa R1.fq R2.fq | samtools sort -@ 4 -o aligned.bam
samtools index aligned.bam
Re-sort by Name for Duplicate Marking
bash
# Full workflow: sort by name, fixmate, sort by coord, markdup
samtools sort -n -o namesorted.bam input.bam
samtools fixmate -m namesorted.bam fixmate.bam
samtools sort -o sorted.bam fixmate.bam
samtools markdup sorted.bam marked.bam
Convert Name-sorted to Coordinate-sorted
bash
samtools sort -o coord_sorted.bam name_sorted.bam
samtools index coord_sorted.bam
Extract FASTQ from Sorted BAM
bash
# Collate first to group pairs
samtools collate -u -O input.bam /tmp/collate | \
    samtools fastq -1 R1.fq -2 R2.fq -0 /dev/null -s /dev/null -

Performance Tips

ParameterEffect
-@ NUse N additional threads
-m SIZEMemory per thread (e.g., 4G)
-T PREFIXTemp file location (use fast SSD scratch)
-l LEVELCompression level (1-9, default 6)
Compression Level Decision
LevelUseWall-time vs defaultSize vs default
-l 0 / -uPipe between samtools tools0% (skips BGZF)+200-400%
-l 1Final output if disk is cheap~+10%~+30%
-l 6Defaultbaselinebaseline
-l 9Archival, write-once~+50-100%~-2-5%
bash
# WRONG -- pipe re-compresses then decompresses every step
samtools fixmate -m in.bam - | samtools sort -o out.bam

# RIGHT -- uncompressed (-u) between piped samtools commands
samtools fixmate -m -u in.bam - | samtools sort -o out.bam
Optimal Settings for Large Files
bash
# 8 threads, 2GB per thread, low compression for output written to fast disk
samtools sort -@ 8 -m 2G -l 1 -T /scratch/sortpfx -o sorted.bam input.bam

Quick Reference

TaskCommand
Sort by coordinatesamtools sort -o out.bam in.bam
Sort by namesamtools sort -n -o out.bam in.bam
Sort with threadssamtools sort -@ 8 -o out.bam in.bam
Collate pairssamtools collate -o out.bam in.bam
Merge BAMssamtools merge out.bam in1.bam in2.bam
Check sort ordersamtools view -H in.bam | grep "^@HD"
Sort + indexsamtools sort -o out.bam in.bam && samtools index out.bam

Common Errors

ErrorCauseSolution
out of memoryInsufficient RAMUse -m to limit per-thread memory
disk fullTemp files filling diskUse -T to specify different location
truncated fileInterrupted sortRe-run sort from original
  • sam-bam-basics - View and convert alignment files
  • alignment-indexing - Index after coordinate sorting
  • duplicate-handling - Requires name-sorted input for fixmate
  • alignment-filtering - Filter before or after sorting

© GPTomics, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 2 other files in alignment-files/alignment-sorting of GPTomics/bioSkills.

  • SKILL.md
  • examples/sort_pipeline.sh
  • usage-guide.md

Open the folder on GitHubat commit d91ed3d

Used in 2 other repositories

We found 2 copies of this SKILL.md (exact, near-identical or edited) in other folders, from 2 other GitHub owners. This page covers the copy in GPTomics/bioSkills, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Bio Alignment Sorting next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Bio Alignment Sorting compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Bio Alignment Sorting this skillGPTomics/bioSkills1.2k2 repos~2.6kAutomated safety check: PassMIT
PysamK-Dense-AI/scientific-agent-skills48k1 repos~3.4kAutomated safety check: NotesMIT
Tooluniverse Epigenomicswu-yc/LabClaw1.1k2 repos~14kAutomated safety check: PassNone
Samtools Bam Processingjaechang-hits/SciAgent-Skills3701 repos~4.1kAutomated safety check: PassMIT
Pysam Genomic Filesjaechang-hits/SciAgent-Skills3701 repos~5.2kAutomated safety check: PassMIT
Bio Splicing QcFreedomIntelligence/OpenClaw-Medical-Skills3.1k—~1.6kAutomated safety check: PassNone

Similar skills

  • Pysam

    K-Dense-AI/scientific-agent-skills

    Provides Python/HTSlib workflows for genomic files. An agent skill from K-Dense-AI/scientific-agent-skills.

    48k GitHub starsUsed in 1 repo~3.4k tokens
    Research & ScienceAuto-check: notes
  • Production-ready genomics and epigenomics data processing for BixBench questions.

    1.1k GitHub starsUsed in 2 repos~14k tokens
    Research & ScienceAuto-check passed
  • Samtools Bam Processing

    jaechang-hits/SciAgent-Skills

    CLI toolkit for SAM/BAM/CRAM: sort, index, convert, filter, QC alignments.

    370 GitHub starsUsed in 1 repo~4.1k tokens
    Research & ScienceAuto-check passed
  • Pysam Genomic Files

    jaechang-hits/SciAgent-Skills

    Read/write SAM/BAM/CRAM, VCF/BCF, FASTA/FASTQ. An agent skill from jaechang-hits/SciAgent-Skills.

    370 GitHub starsUsed in 1 repo~5.2k tokens
    Research & ScienceAuto-check passed
  • Bio Splicing Qc

    FreedomIntelligence/OpenClaw-Medical-Skills

    Assesses RNA-seq data quality for splicing analysis including junction saturation curves, splice site strength scoring, and junction coverage metrics using RSeQC.

    3.1k GitHub stars~1.6k tokensUpdated 2 mo ago
    Data & AnalyticsAuto-check passed
  • Alphagenome Single Variant Analysis

    google-deepmind/science-skills

    Analyzes genetic variant effects on gene expression (RNA-seq), chromatin accessibility (DNASE), histone marks (ChIP), and transcription factors using the AlphaGenome API.

    3.2k GitHub starsUsed in 2 repos~3k tokens
    Research & ScienceAuto-check: notes

More from GPTomics/bioSkills

All 553 skills in this repo
  • Bio Alignment Io

    GPTomics/bioSkills

    Read, write, and convert multiple sequence alignment files using Biopython Bio.AlignIO.

    1.2k GitHub starsUsed in 3 repos~4.9k tokens
    Auto-check passed
  • bioSkills Installer

    GPTomics/bioSkills

    Installs the bioSkills collection of 425 bioinformatics skills in one step, or only chosen categories, so sequencing, RNA-seq, single-cell and variant tasks get specialized help.

    1.2k GitHub starsUsed in 1 repo~789 tokens
    Auto-check passed
  • Bio Write Sequences

    GPTomics/bioSkills

    Write biological sequences to files (FASTA, FASTQ, GenBank, EMBL) using Biopython Bio.SeqIO.

    1.2k GitHub starsUsed in 3 repos~2.1k tokens
    Auto-check passed
  • Amplicon Primer Clipping

    GPTomics/bioSkills

    Soft- or hard-clips PCR primer footprints from aligned amplicon BAMs so primer bases stop masquerading as confirmed reference sequence.

    1.2k GitHub starsUsed in 2 repos~2.2k tokens
    Auto-check passed
  • Bio Alignment Indexing

    GPTomics/bioSkills

    Create and use BAI/CSI indices for BAM/CRAM files using samtools and pysam.

    1.2k GitHub starsUsed in 2 repos~2.4k tokens
    Auto-check passed
  • Bio Alignment Validation

    GPTomics/bioSkills

    Validate alignment quality with insert size distribution, proper pairing rates, GC bias, strand balance, and other post-alignment metrics.

    1.2k GitHub starsUsed in 2 repos~3.7k tokens
    Auto-check passed

Works with

Questions about Bio Alignment Sorting

What does Bio Alignment Sorting do?

Sort alignment files by coordinate or read name using samtools and pysam. Bio Alignment Sorting is an agent skill from GPTomics/bioSkills. Sort alignment files by coordinate or read name using samtools and pysam.

When should I use Bio Alignment Sorting?

Bio Alignment Sorting fits situations like: preparing BAM files for indexing; variant calling; paired-end analysis.

How do I install Bio Alignment Sorting in Claude Code?

Run `npx skills add GPTomics/bioSkills --skill bio-alignment-sorting -a claude-code`. Or copy the skill folder (alignment-files/alignment-sorting in GPTomics/bioSkills) into .claude/skills/bio-alignment-sorting in your project. Claude Code loads it when a task matches its description.

How do I install Bio Alignment Sorting in Codex?

Run `npx skills add GPTomics/bioSkills --skill bio-alignment-sorting -a codex`. Or copy the skill folder (alignment-files/alignment-sorting in GPTomics/bioSkills) into .agents/skills/bio-alignment-sorting in your project. Codex loads it when a task matches its description.

Can I use Bio Alignment Sorting in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add GPTomics/bioSkills --skill bio-alignment-sorting -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/bio-alignment-sorting, .gemini/skills/bio-alignment-sorting, .github/skills/bio-alignment-sorting and .opencode/skills/bio-alignment-sorting in your project.

What does Bio Alignment Sorting need to run?

Going by SKILL.md and its folder, Bio Alignment Sorting needs a shell for the scripts in its folder and the command-line tools its instructions call (pip). Our summary lists: Python 3; A Bash shell.

Does Bio Alignment Sorting access the network?

SKILL.md contains no URLs. Its commands use pip, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Bio Alignment Sorting safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Bio Alignment Sorting use?

Bio Alignment Sorting is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Bio Alignment Sorting use?

About 2.6k tokens (SKILL.md is roughly 10k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Bio Alignment Sorting?

Skills that share tags, products or a category with Bio Alignment Sorting: Pysam (K-Dense-AI/scientific-agent-skills, 48k stars), Tooluniverse Epigenomics (wu-yc/LabClaw, 1.1k stars), Samtools Bam Processing (jaechang-hits/SciAgent-Skills, 370 stars) and Pysam Genomic Files (jaechang-hits/SciAgent-Skills, 370 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Bio Alignment Sorting?

GPTomics (a GitHub organization) maintains it in GPTomics/bioSkills, which has 1,215 GitHub stars. The repository holds 553 skills in this directory. The repository was last updated on August 15, 2026.

Source: GPTomics/bioSkills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.