# Bio Batch Processing

Process multiple sequence files in batch using Biopython.

- Repository: https://github.com/FreedomIntelligence/OpenClaw-Medical-Skills (3090 stars)
- Category: Engineering
- License: see repository
- Last updated: 2026-07-21
- Runs scripts: yes, review before use

## Install

Claude Code: `npx skills add FreedomIntelligence/OpenClaw-Medical-Skills --skill bio-batch-processing -g -a claude-code -y`
Codex: `npx skills add FreedomIntelligence/OpenClaw-Medical-Skills --skill bio-batch-processing -g -a codex -y`
Cursor: `npx skills add FreedomIntelligence/OpenClaw-Medical-Skills --skill bio-batch-processing -g -a cursor -y`
Gemini CLI: `npx skills add FreedomIntelligence/OpenClaw-Medical-Skills --skill bio-batch-processing -g -a gemini-cli -y`

## Description

Process multiple sequence files in batch using Biopython. Use when working with many files, merging/splitting sequences, or automating file operations across directories.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

## Version Compatibility

Reference examples tested with: BioPython 1.83+

Before using code patterns, verify installed versions match. If versions differ:
- Python: `pip show <package>` then `help(module.function)` to check signatures

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

# Batch Processing

**"Process all my sequence files in a directory"** → Iterate, merge, split, convert, and generate summary statistics across multiple sequence files.
- Python: `SeqIO.parse()`, `Path.glob()` (BioPython, pathlib)

Process multiple sequence files efficiently using Biopython.

## Required Imports

```python
from pathlib import Path
from Bio import SeqIO
```

## Process Multiple Files

### Iterate Over Files in Directory
```python
from pathlib import Path

for fasta_file in Path('data/').glob('*.fasta'):
    records = list(SeqIO.parse(fasta_file, 'fasta'))
    print(f'{fasta_file.name}: {len(records)} sequences')
```

### Process All FASTQ Files
```python
for fq_file in Path('.').glob('*.fastq'):
    count = sum(1 for _ in SeqIO.parse(fq_file, 'fastq'))
    print(f'{fq_file.name}: {count} reads')
```

### Recursive File Search
```python
for gb_file in Path('data/').rglob('*.gb'):
    print(f'Found: {gb_file}')
```

## Merge Files

### Merge All FASTA Files
```python
from pathlib import Path

def all_records(directory, pattern, format):
    for filepath in Path(directory).glob(pattern):
        yield from SeqIO.parse(filepath, format)

records = all_records('data/', '*.fasta', 'fasta')
count = SeqIO.write(records, 'merged.fasta', 'fasta')
print(f'Merged {count} records')
```

### Merge with Source Tracking

**Goal:** Combine sequences from multiple files into one, tagging each record with its source filename.

**Approach:** Stream records from each file through a generator that appends source metadata to the description.

The rest: https://github.com/FreedomIntelligence/OpenClaw-Medical-Skills/blob/HEAD/skills/bio-batch-processing/SKILL.md
