本文へ移動
cccskills
無料GitHub で公開

bio-format-conversion

Convert between sequence file formats (FASTA, FASTQ, GenBank, EMBL) using Biopython Bio.SeqIO. Use when changing file formats or preparing data for different tools.

インストール方法を見る

含まれるファイル(3)

  • SKILL.md5.8 KB
  • examples/convert_format.py1.6 KB
  • usage-guide.md1.1 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Version Compatibility

Reference examples tested with: BioPython 1.83+, 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

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

Format Conversion

"Convert this file to a different format" → Read records in one format, optionally add missing annotations, and write in the target format.

  • Python: SeqIO.convert() for direct conversion, or SeqIO.parse() + SeqIO.write() when modifications are needed (BioPython)
  • CLI: seqkit seq (SeqKit) for FASTA/FASTQ; samtools view for SAM/BAM/CRAM

Convert sequence files between formats using Biopython's Bio.SeqIO module.

Required Import

from Bio import SeqIO

Core Function

SeqIO.convert() - Direct Conversion

Convert between formats in a single call. Most efficient method.

count = SeqIO.convert('input.gb', 'genbank', 'output.fasta', 'fasta')
print(f'Converted {count} records')

Parameters:

  • in_file - Input filename or handle
  • in_format - Input format string
  • out_file - Output filename or handle
  • out_format - Output format string

Returns: Number of records converted

Common Conversions

FromToNotes
GenBankFASTALoses annotations, keeps sequence
FASTAGenBankNeed to add molecule_type
FASTQFASTALoses quality scores
FASTAFASTQNeed to add quality scores
GenBankEMBLUsually works directly
StockholmFASTAAlignment to sequences

Code Patterns

Simple Conversion

SeqIO.convert('input.gb', 'genbank', 'output.fasta', 'fasta')

GenBank to FASTA

SeqIO.convert('sequence.gb', 'genbank', 'sequence.fasta', 'fasta')

FASTQ to FASTA (drop quality)

SeqIO.convert('reads.fastq', 'fastq', 'reads.fasta', 'fasta')

FASTA to GenBank (requires molecule_type)

Goal: Convert FASTA to GenBank format, which requires molecule_type annotation.

Approach: Stream records through a generator that injects the missing annotation, then write.

Reference (BioPython 1.83+):

records = SeqIO.parse('input.fasta', 'fasta')
def add_molecule_type(records):
    for record in records:
        record.annotations['molecule_type'] = 'DNA'
        yield record

SeqIO.write(add_molecule_type(records), 'output.gb', 'genbank')

FASTA to FASTQ (add dummy quality)

Goal: Convert FASTA to FASTQ by assigning uniform placeholder quality scores.

Approach: Stream records through a generator that adds phred_quality to each, then write as FASTQ.

Reference (BioPython 1.83+):

def add_quality(records, quality=30):
    for record in records:
        record.letter_annotations['phred_quality'] = [quality] * len(record.seq)
        yield record

records = SeqIO.parse('input.fasta', 'fasta')
SeqIO.write(add_quality(records), 'output.fastq', 'fastq')

Batch Convert Multiple Files

Goal: Convert all files of one format in a directory to another format.

Approach: Glob for input files, apply SeqIO.convert() to each, and report per-file counts.

Reference (BioPython 1.83+):

from pathlib import Path

for gb_file in Path('.').glob('*.gb'):
    fasta_file = gb_file.with_suffix('.fasta')
    count = SeqIO.convert(str(gb_file), 'genbank', str(fasta_file), 'fasta')
    print(f'{gb_file.name}: {count} records')

Convert with Modifications

from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord

def uppercase_record(rec):
    return SeqRecord(rec.seq.upper(), id=rec.id, description=rec.description)

records = SeqIO.parse('input.fasta', 'fasta')
modified = (uppercase_record(rec) for rec in records)
SeqIO.write(modified, 'output.fasta', 'fasta')

Alignment Format Conversion

from Bio import AlignIO

AlignIO.convert('alignment.sto', 'stockholm', 'alignment.phy', 'phylip')

Format Compatibility Matrix

Can convert directly (no modifications needed):

  • GenBank <-> EMBL
  • FASTA -> any format (may need annotations added)
  • Any format -> FASTA (always works, may lose data)
  • FASTQ -> FASTA

Requires adding data:

  • FASTA -> FASTQ (need quality scores)
  • FASTA -> GenBank (need molecule_type)

May lose data:

  • GenBank -> FASTA (loses features, annotations)
  • FASTQ -> FASTA (loses quality scores)
  • Any rich format -> FASTA

Common Errors

ErrorCauseSolution
ValueError: missing molecule_typeFASTA to GenBankAdd molecule_type annotation
ValueError: missing quality scoresFASTA to FASTQAdd phred_quality to letter_annotations
KeyError: 'phred_quality'Wrong FASTQ variantTry 'fastq-sanger', 'fastq-illumina'

Decision Tree

Converting formats?
├── Simple conversion (no data changes)?
│   └── Use SeqIO.convert() directly
├── Need to add annotations?
│   └── Parse, modify records, then write
├── Need to transform sequences?
│   └── Parse, apply transformation, then write
└── Multiple files?
    └── Loop with SeqIO.convert() or batch generator

Related Skills

  • read-sequences - Parse sequences for custom conversion logic
  • write-sequences - Write converted sequences with modifications
  • batch-processing - Convert multiple files at once
  • compressed-files - Handle compressed input/output during conversion
  • alignment-files - For SAM/BAM/CRAM conversion, use samtools view

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

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 for submitting experiments via API, tracking experiment status, downloading results, optimizing protein sequences for better expression using computational tools (NetSolP, SoluProt, SolubleMPNN, ESM), or managing protein design workflows with wet-lab validation.

日本語の概要は準備中です。原文の説明を表示しています。

FreedomIntelligence/OpenClaw-Medical-Skills3,0622026年7月21日 更新

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 actually work for neurodivergent minds.

日本語の概要は準備中です。原文の説明を表示しています。

FreedomIntelligence/OpenClaw-Medical-Skills3,0622026年7月21日 更新

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 requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.

日本語の概要は準備中です。原文の説明を表示しています。

FreedomIntelligence/OpenClaw-Medical-Skills3,0622026年7月21日 更新

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.

日本語の概要は準備中です。原文の説明を表示しています。

FreedomIntelligence/OpenClaw-Medical-Skills3,0622026年7月21日 更新

AI驱动的综合健康分析系统,整合多维度健康数据、识别异常模式、预测健康风险、提供个性化建议。支持智能问答和AI健康报告生成。

日本語の概要は準備中です。原文の説明を表示しています。

FreedomIntelligence/OpenClaw-Medical-Skills3,0622026年7月21日 更新

alphafold

無料

Validate protein designs using AlphaFold2 structure prediction. Use this skill when: (1) Validating designed sequences fold correctly, (2) Predicting binder-target complex structures, (3) Calculating confidence metrics (pLDDT, pTM, ipTM), (4) Self-consistency validation of designs, (5) Multi-chain complex prediction with AlphaFold-Multimer. For faster single-chain prediction, use esm. For QC thresholds, use protein-qc.

日本語の概要は準備中です。原文の説明を表示しています。

FreedomIntelligence/OpenClaw-Medical-Skills3,0622026年7月21日 更新

FreedomIntelligence のスキルをすべて見る

このスキルの問題を報告する