Skills

Bio Batch Processing

Process multiple sequence files in batch using Biopython.

Install

npx skills add FreedomIntelligence/OpenClaw-Medical-Skills --skill bio-batch-processing -g -a claude-code -y
Category
Engineering
Updated
4mo ago
License
See repository
Context cost
Mediumabout 2,141 tokens
Runs scripts
Yes, review before use

What it does

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

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

from pathlib import Path
from Bio import SeqIO

Process Multiple Files

Iterate Over Files in Directory

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

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

for gb_file in Path('data/').rglob('*.gb'):
    print(f'Found: {gb_file}')

Merge Files

Merge All FASTA Files

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.

Read the whole SKILL.md on GitHub

More in Engineering