Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

bio-reverse-complement

БесплатноЗапускает вложенные скриптыНе проверен

Generate reverse complements and complements of DNA/RNA sequences using Biopython, including IUPAC ambiguity codes, gapped alignments, and minus-strand…

lilinjiот lilinji★ 18 звёзд на GitHub

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

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.

Reverse Complement

Generate complementary and reverse complementary sequences using Biopython.

"Get the reverse complement" -> Produce the 5'-to-3' sequence of the opposite strand.

  • Python: seq.reverse_complement() (BioPython Seq)
  • CLI: samtools faidx ref.fa region --reverse-complement (extracts and RCs a region)

The Governing Principle

Never hand-roll the complement table. Biopython's reverse_complement() already encodes the full IUPAC mapping correctly, case-insensitively, and on minus-strand features it is applied for the analyst automatically by SeqFeature.extract(). Every silent corruption in this domain comes from reimplementing what Biopython already does right: swapping ambiguity codes, forgetting that S/W/N are self-complementary, complementing the wrong molecule type, or reverse-complementing a second time after extract() already did it. Reach for the library method; reach for a guard (molecule_type) before it; never reach for a custom dictionary.

Required Import

from Bio.Seq import Seq

Which Method for Which Question

Question Method Output strand/direction
Opposite strand, conventional 5'->3' reverse_complement() 5'->3' of the complementary strand (the usual answer)
Base-paired sequence, same direction complement() 3'->5' of the complementary strand
Opposite strand of RNA, keep U reverse_complement_rna() 5'->3', emits U
Complement of RNA, keep U complement_rna() 3'->5', emits U
Coding strand from template (or vice versa) reverse_complement() the other strand, 5'->3'
mRNA sequence from the coding strand transcribe() (NOT a complement) same strand, T->U

reverse_complement()

Returns the reverse complement (5'->3' of the opposite strand). This is the most commonly used operation.

seq = Seq('ATGCGATCG')
rc = seq.reverse_complement()  # Returns Seq('CGATCGCAT')

complement()

Returns the complement without reversing. Less common - gives the opposite strand still written in 3'->5' order.

seq = Seq('ATGCGATCG')
comp = seq.complement()  # Returns Seq('TACGCTAGC')

reverse_complement_rna() and complement_rna()

For RNA, the dedicated methods emit U:

rna = Seq('AUGCGAUCG')
rna.reverse_complement_rna()  # Returns Seq('CGAUCGCAU')
rna.complement_rna()          # Returns Seq('UACGCUAGC')

Base Pairing and Ambiguity Codes

reverse_complement() complements all 15 IUPAC codes plus X correctly. The mapping is non-obvious for ambiguity codes - this is exactly why hand-rolling corrupts silently.

Code Bases Complement Code Bases Complement
A A T M A/C K
T T A B C/G/T V
G G C V A/C/G B
C C G D A/G/T H
R A/G Y H A/C/T D
Y C/T R S G/C S (self)
K G/T M W A/T W (self)
N any N (self)

S, W, N, and X are SELF-complementary. The pairs that get swapped wrong by hand are B<->V and D<->H. The table is built for upper and lower case, so complementation is case-insensitive (Seq('atRY').reverse_complement() works).

DNA vs RNA: the U handling rule

reverse_complement() runs in DNA mode: it treats any U as a T and EMITS T (docstring: "Any U in the sequence is treated as a T"). It does not raise and does not leave U.

Seq('ACGU').reverse_complement()      # Returns Seq('ACGT')  -- U mapped to A, emitted as T
Seq('ACGU').reverse_complement_rna()  # Returns Seq('ACGU')  -- stays RNA

transcribe() does NOT complement. It swaps T->U on the SAME strand. Confusing "complement the template" with "transcribe the coding strand" is silent corruption. True biological transcription from the template strand is template_dna.reverse_complement().transcribe().

Gaps and Non-Table Characters

complement and reverse_complement do NOT validate the alphabet (unlike translate()). A gap - is not a table key, so it passes through unchanged and reversal preserves gap columns - the desired behavior for aligned sequences. Any other non-table character (?, *) also passes through silently.

Seq('ATG-CGA--TY').reverse_complement()  # Returns Seq('RA--TCG-CAT') -- gaps preserved, Y->R

Because there is no alphabet check, garbage in produces garbage out without a warning (see the protein trap below).

Code Patterns

Visualize Double-Stranded DNA

def show_dsdna(seq
Полный SKILL.md на GitHub

Установить bio-reverse-complement в Claude Code и Claude Desktop

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

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

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

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

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

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

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

examples/basic_operations.pyexamples/iupac_and_features.pyexamples/palindrome_check.pyexamples/primer_design.pyusage-guide.md

FAQ

Что делает скилл bio-reverse-complement?

Generate reverse complements and complements of DNA/RNA sequences using Biopython, including IUPAC ambiguity codes, gapped alignments, and minus-strand features. Use when working with the opposite strand, building reverse primers, normalizing strand orientation before alignment, or extracting a coding sequence from a minus-strand feature.

Как установить скилл bio-reverse-complement?

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

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

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

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

Сравнить bio-reverse-complement с