Command Palette

Search for a command to run...

Назад к скиллам
скилл № 42048

bio-format-conversion

Convert between sequence file formats (FASTA, FASTQ, GenBank, EMBL, Stockholm) and re-encode FASTQ quality offsets using Biopython Bio.SeqIO. Use when…

БесплатноЗапускает вложенные скрипты
lilinjiот lilinji★ 18 звёзд на GitHub

Установить bio-format-conversion в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

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.

Format Conversion

"Convert this file to a different format" -> Read records in one format, optionally add or drop annotations, and write in the target format.

  • Python: SeqIO.convert() for a streaming one-shot conversion, or SeqIO.parse() + SeqIO.write() when records need modification (BioPython)
  • CLI: seqkit seq (SeqKit) for FASTA/FASTQ; samtools view for SAM/BAM/CRAM

The Governing Principle

A conversion is lossy whenever the target format cannot represent the source's information. The conversion still succeeds with no error and no warning. FASTA stores only id + description + sequence, so it is the most lossy common target: converting GenBank, EMBL, or FASTQ to FASTA silently discards everything the richer format carried. Before converting, decide whether the destination can hold what the source contains. If it cannot, treat the conversion as a deliberate downgrade, not a neutral reformat.

The Canonical Trap: GenBank/EMBL -> FASTA Silently Drops Everything

SeqIO.convert('in.gb', 'genbank', 'out.fasta', 'fasta') discards all features, annotations, qualifiers, and dbxrefs. The genes, CDS coordinates, /product and /gene qualifiers, organism, taxonomy, references, and molecule_type are all gone. There is no error, no warning, and the record count is unchanged, so the loss is invisible unless the output is inspected. FASTA encodes only record.id, record.description, and record.seq; everything in record.features, record.annotations, and record.dbxrefs has nowhere to go.

If the features matter, do not convert to FASTA. Extract feature sequences first (see sequence-manipulation/sequence-slicing) or keep the GenBank file as the source of record and use the FASTA only as a sequence-only derivative for tools that demand FASTA.

Lossy Conversion Decision Table

From To What is lost (silently)
GenBank / EMBL FASTA All features, qualifiers, annotations, dbxrefs; keeps id + description + seq
GenBank EMBL (or reverse) Usually lossless; both hold features and annotations
FASTQ FASTA Per-base quality scores (phred_quality)
FASTQ Phred+64 FASTQ Phred+33 Nothing if offsets handled correctly; corruption if the wrong parser is used
FASTQ Phred FASTQ Solexa Precision at low quality (round-trip lossy below ~Q10); warns when max Solexa exceeded
Stockholm FASTA Alignment columns (gaps), consensus, per-column annotation; keeps ungapped seqs
Any rich format FASTA Everything except id + description + seq

The general pattern: rich -> flat loses the richness. The conversion succeeds regardless.

Preferred Path: SeqIO.convert() Is a Streaming One-Shot

For a plain conversion with no record modification, use SeqIO.convert(). It streams one record at a time from input to output (memory-efficient, never loads the whole file) and is preferred over parse() + write(), which is only needed when records must be changed en route.

from Bio import SeqIO

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

Parameters: in_file, in_format, out_file, out_format (filenames or handles; format strings are lowercase). Returns the number of records written. Reach for parse() + write() only when injecting annotations, transforming sequences, or filtering during the conversion.

FASTQ Quality Encoding Conversion

FASTQ quality is one ASCII character per base, but the offset and score type differ across instrument generations. Re-encoding between them is a conversion, not a copy: the bytes in the quality line change.

Format string For Offset Score type
fastq (alias of fastq-sanger) Sanger and modern Illumina 1.8+ 33 Phred 0-93
fastq-sanger same as above 33 Phred 0-93
fastq-illumina Illumina 1.3-1.7 64 Phred 0-62
fastq-solexa pre-1.3 Solexa 64 Solexa odds -5..62

Re-encode old Illumina 1.3+ (Phred+64) to modern Sanger (Phred+33) by naming both variants. SeqIO.convert() reads with the input offset and writes with the output offset:

from Bio import SeqIO

SeqIO.convert('illumina13.fastq', 'fastq-illumina', 'sanger.fastq', 'fastq-sanger')

Never re-encode without a verified source encoding. Quality encoding cannot be auto-detected in general: ASCII >= 64 is legal in every variant, so a high-quality Sanger file and a low-quality Illumina-1.3 file can be byte-identical in their quality lines. Two failure

Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • examples/convert_format.py
  • usage-guide.md

FAQ

Что делает скилл bio-format-conversion?

Convert between sequence file formats (FASTA, FASTQ, GenBank, EMBL, Stockholm) and re-encode FASTQ quality offsets using Biopython Bio.SeqIO. Use when changing a file format for a downstream tool, fixing FASTQ quality encoding (Phred+33 vs Phred+64 vs Solexa), or when a conversion risks silently dropping annotations or quality scores.

Как установить скилл bio-format-conversion?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл bio-format-conversion запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить bio-format-conversion с