/bio-duplicate-handling
<!--
$ npx -y skills add FreedomIntelligence/OpenClaw-Medical-Skills --skill bio-duplicate-handling --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/bio-duplicate-handling
Context preview
The summary Claude sees to decide when to auto-load this skill.
<!--
SKILL.md
bio-duplicate-handling.SKILL.md<!--
COPYRIGHT NOTICE
This file is part of the "Universal Biomedical Skills" project.
Copyright (c) 2026 MD BABU MIA, PhD <md.babu.mia@mssm.edu>
All Rights Reserved.
#
This code is proprietary and confidential.
Unauthorized copying of this file, via any medium is strictly prohibited.
#
Provenance: Authenticated by MD BABU MIA
-->
--- name: bio-duplicate-handling description: Mark and remove PCR/optical duplicates using samtools fixmate and markdup. Use when preparing alignments for variant calling or when duplicate reads would bias analysis. tool_type: cli primary_tool: samtools measurable_outcome: Execute skill workflow successfully with valid output within 15 minutes. allowed-tools:
- read_file
- run_shell_command
---
Duplicate Handling
Mark and remove PCR/optical duplicates using samtools.
Why Remove Duplicates?
PCR duplicates are identical copies of the same original molecule, created during library preparation. They:
- Inflate coverage artificially
- Bias allele frequencies
- Can create false positive variant calls
Optical duplicates are clusters read multiple times due to their proximity on the flowcell.
Duplicate Marking Workflow
The standard samtools workflow requires multiple steps:
# 1. Sort by name (required for fixmate)
samtools sort -n -o namesort.bam input.bam
# 2. Add mate information with fixmate
samtools fixmate -m namesort.bam fixmate.bam
# 3. Sort by coordinate (required for markdup)
samtools sort -o coordsort.bam fixmate.bam
# 4. Mark duplicates
samtools markdup coordsort.bam marked.bam
# 5. Index result
samtools index marked.bam
Pipeline Version
samtools sort -n input.bam | \
samtools fixmate -m - - | \
samtools sort - | \
samtools markdup - marked.bam
samtools index marked.bamsamtools fixmate
Adds mate information required by markdup. Must be run on name-sorted BAM.
Basic Usage
samtools fixmate namesorted.bam fixmate.bam
Add Mate Score Tag (-m)
# Required for markdup to work correctly
samtools fixmate -m namesorted.bam fixmate.bam
Multi-threaded
samtools fixmate -m -@ 4 namesorted.bam fixmate.bam
Remove Secondary/Unmapped
samtools fixmate -r -m namesorted.bam fixmate.bam
samtools markdup
Marks or removes duplicate alignments. Requires coordinate-sorted BAM with mate tags from fixmate.
Mark Duplicates (Keep in File)
samtools markdup input.bam marked.bam
Remove Duplicates
samtools markdup -r input.bam deduped.bam
Output Statistics
samtools markdup -s input.bam marked.bam 2> markdup_stats.txt
Optical Duplicate Distance
# Set pixel distance for optical duplicate detection (default: 100)
samtools markdup -d 2500 input.bam marked.bam
Multi-threaded
samtools markdup -@ 4 input.bam marked.bam
Write Stats to File
samtools markdup -f stats.txt input.bam marked.bam
Duplicate Statistics
Check Duplicate Rate
samtools flagstat marked.bam
# Look for "duplicates" line
Count Duplicates
# Count reads with duplicate flag
samtools view -c -f 1024 marked.bam
Percentage Duplicates
total=$(samtools view -c marked.bam)
dups=$(samtools view -c -f 1024 marked.bam)
echo "scale=2; $dups * 100 / $total" | bc
pysam Python Alternative
Full Pipeline
import pysam
# Sort by name
pysam.sort('-n', '-o', 'namesort.bam', 'input.bam')
# Fixmate
pysam.fixmate('-m', 'namesort.bam', 'fixmate.bam')
# Sort by coordinate
pysam.sort('-o', 'coordsort.bam', 'fixmate.bam')
# Mark duplicates
pysam.markdup('coordsort.bam', 'marked.bam')
# Index
pysam.index('marked.bam')Check Duplicate Flag
import pysam
with pysam.AlignmentFile('marked.bam', 'rb') as bam:
total = 0
duplicates = 0
for read in bam:
total += 1
if read.is_duplicate:
duplicates += 1
print(f'Total: {total}')
print(f'Duplicates: {duplicates}')
print(f'Rate: {duplicates/total*100:.2f}%')Filter Out Duplicates
import pysam
with pysam.AlignmentFile('marked.bam', 'rb') as infile:
with pysam.AlignmentFile('nodup.bam', 'wb', header=infile.header) as outfile:
for read in infile:
if not read.is_duplicate:
outfile.write(read)Mark Duplicates Manually (Simple Case)
import pysam
from collections import defaultdict
def simple_markdup(input_bam, output_bam):
seen = defaultdict(set)
with pysam.AlignmentFile(input_bam, 'rb') as infile:
with pysam.AlignmentFile(output_bam, 'wb', header=infile.header) as outfile:
for read in infile:
if read.is_unmapped:
outfile.write(read)
continue
key = (read.reference_id, read.reference_start, read.is_reverse,
read.next_reference_id, read.next_reference_start)
if key in seen:
read.is_duplicate = True
else:
seen[key].add(read.query_name)
outfile.write(read)
simple_markdup('sorted.bam', 'marked.bam')Alternative: From Aligner
Some aligners can mark duplicates directly:
BWA-MEM2 with samblaster
bwa-mem2 mem ref.fa R1.fq R2.fq | \
samblaster | \
samtools sort -o marked.bamUsing Picard (Alternative Tool)
java -jar picard.jar MarkDuplicates \
I=input.bam \
O=marked.bam \
M=metrics.txtQuick Reference
| Task | Command | |------|---------| | Full workflow | `sort -n \| fixmate -m \| sort \| markdup` | | Mark duplicates | `samtools markdup in.bam out.bam` | | Remove duplicates | `samtools markdup -r in.bam out.bam` | | Count duplicates | `samtools view -c -f 1024 marked.bam` | | View non-duplicates | `samtools view -F 1024 marked.bam` | | Get stats | `samtools markdup -s in.bam out
Read more
<!--
COPYRIGHT NOTICE
This file is part of the "Universal Biomedical Skills" project.
Copyright (c) 2026 MD BABU MIA, PhD <md.babu.mia@mssm.edu>
All Rights Reserved.
#
This code is proprietary and confidential.
Unauthorized copying of this file, via any medium is strictly prohibited.
#
Provenance: Authenticated by MD BABU MIA
-->
--- name: bio-duplicate-handling description: Mark and remove PCR/optical duplicates using samtools fixmate and markdup. Use when preparing alignments for variant calling or when duplicate reads would bias analysis. tool_type: cli primary_tool: samtools measurable_outcome: Execute skill workflow successfully with valid output within 15 minutes. allowed-tools:
- read_file
- run_shell_command
---
Duplicate Handling
Mark and remove PCR/optical duplicates using samtools.
Why Remove Duplicates?
PCR duplicates are identical copies of the same original molecule, created during library preparation. They:
- Inflate coverage artificially
- Bias allele frequencies
- Can create false positive variant calls
Optical duplicates are clusters read multiple times due to their proximity on the flowcell.
Duplicate Marking Workflow
The standard samtools workflow requires multiple steps:
# 1. Sort by name (required for fixmate) samtools sort -n -o namesort.bam input.bam # 2. Add mate information with fixmate samtools fixmate -m namesort.bam fixmate.bam # 3. Sort by coordinate (required for markdup) samtools sort -o coordsort.bam fixmate.bam # 4. Mark duplicates samtools markdup coordsort.bam marked.bam # 5. Index result samtools index marked.bam
Pipeline Version
samtools sort -n input.bam | \
samtools fixmate -m - - | \
samtools sort - | \
samtools markdup - marked.bam
samtools index marked.bamsamtools fixmate
Adds mate information required by markdup. Must be run on name-sorted BAM.
Basic Usage
samtools fixmate namesorted.bam fixmate.bam
Add Mate Score Tag (-m)
# Required for markdup to work correctly samtools fixmate -m namesorted.bam fixmate.bam
Multi-threaded
samtools fixmate -m -@ 4 namesorted.bam fixmate.bam
Remove Secondary/Unmapped
samtools fixmate -r -m namesorted.bam fixmate.bam
samtools markdup
Marks or removes duplicate alignments. Requires coordinate-sorted BAM with mate tags from fixmate.
Mark Duplicates (Keep in File)
samtools markdup input.bam marked.bam
Remove Duplicates
samtools markdup -r input.bam deduped.bam
Output Statistics
samtools markdup -s input.bam marked.bam 2> markdup_stats.txt
Optical Duplicate Distance
# Set pixel distance for optical duplicate detection (default: 100) samtools markdup -d 2500 input.bam marked.bam
Multi-threaded
samtools markdup -@ 4 input.bam marked.bam
Write Stats to File
samtools markdup -f stats.txt input.bam marked.bam
Duplicate Statistics
Check Duplicate Rate
samtools flagstat marked.bam # Look for "duplicates" line
Count Duplicates
# Count reads with duplicate flag samtools view -c -f 1024 marked.bam
Percentage Duplicates
total=$(samtools view -c marked.bam) dups=$(samtools view -c -f 1024 marked.bam) echo "scale=2; $dups * 100 / $total" | bc
pysam Python Alternative
Full Pipeline
import pysam
# Sort by name
pysam.sort('-n', '-o', 'namesort.bam', 'input.bam')
# Fixmate
pysam.fixmate('-m', 'namesort.bam', 'fixmate.bam')
# Sort by coordinate
pysam.sort('-o', 'coordsort.bam', 'fixmate.bam')
# Mark duplicates
pysam.markdup('coordsort.bam', 'marked.bam')
# Index
pysam.index('marked.bam')Check Duplicate Flag
import pysam
with pysam.AlignmentFile('marked.bam', 'rb') as bam:
total = 0
duplicates = 0
for read in bam:
total += 1
if read.is_duplicate:
duplicates += 1
print(f'Total: {total}')
print(f'Duplicates: {duplicates}')
print(f'Rate: {duplicates/total*100:.2f}%')Filter Out Duplicates
import pysam
with pysam.AlignmentFile('marked.bam', 'rb') as infile:
with pysam.AlignmentFile('nodup.bam', 'wb', header=infile.header) as outfile:
for read in infile:
if not read.is_duplicate:
outfile.write(read)Mark Duplicates Manually (Simple Case)
import pysam
from collections import defaultdict
def simple_markdup(input_bam, output_bam):
seen = defaultdict(set)
with pysam.AlignmentFile(input_bam, 'rb') as infile:
with pysam.AlignmentFile(output_bam, 'wb', header=infile.header) as outfile:
for read in infile:
if read.is_unmapped:
outfile.write(read)
continue
key = (read.reference_id, read.reference_start, read.is_reverse,
read.next_reference_id, read.next_reference_start)
if key in seen:
read.is_duplicate = True
else:
seen[key].add(read.query_name)
outfile.write(read)
simple_markdup('sorted.bam', 'marked.bam')Alternative: From Aligner
Some aligners can mark duplicates directly:
BWA-MEM2 with samblaster
bwa-mem2 mem ref.fa R1.fq R2.fq | \
samblaster | \
samtools sort -o marked.bamUsing Picard (Alternative Tool)
java -jar picard.jar MarkDuplicates \
I=input.bam \
O=marked.bam \
M=metrics.txtQuick Reference
| Task | Command | |------|---------| | Full workflow | `sort -n \| fixmate -m \| sort \| markdup` | | Mark duplicates | `samtools markdup in.bam out.bam` | | Remove duplicates | `samtools markdup -r in.bam out.bam` | | Count duplicates | `samtools view -c -f 1024 marked.bam` | | View non-duplicates | `samtools view -F 1024 marked.bam` | | Get stats | `samtools markdup -s in.bam out
The largest open-source medical AI skill library for OpenClaw.
Other skills on openclaw-medical-skills.
- /aav-vector-design-agent
<!--
Open skill - /adaptyv
Cloud laboratory platform for automated protein testing and validation. Use when designing proteins and needing experimental validation including binding assays, expression testing, thermostability measurements, enzyme activity assays, or protein sequence optimization. Also use
Open skill - /adhd-daily-planner
Time-blind friendly planning, executive function support, and daily structure for ADHD brains. Specializes in realistic time estimation, dopamine-aware task design, and building systems that
Open skill - /aeon
This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations
Open skill - /agent-browser
Browse the web for any task — research topics, read articles, interact with web apps, fill forms, take screenshots, extract data, and test web pages. Use whenever a browser would be useful, not just when the user explicitly asks.
Open skill - /agentd-drug-discovery
<!--
Open skill

