Frame translation and orf

From XuShuwenn/RedAct · View interactive version

Frame translation and orf is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Compute GC content, translate a nucleotide sequence in a specified reading frame, and find the longest ORF across frames with robust verification.

How to use this skill

Skill file

Reading-Frame Translation and Longest ORF Detection

A reusable workflow for nucleotide sequence analysis: sequence type detection, GC content calculation, frame-specific translation with stop codons marked as '*', and finding the longest open reading frame (ORF) across all three frames.

When to Use

Activate this skill when a user asks to:

Core Workflow

  1. Normalize input
  1. Determine sequence type
  1. GC content (nucleic acids only)
  1. Frame-specific translation
  1. Longest ORF across all frames
  1. Output formatting

Algorithms and Reference Snippets

GC content (ignoring ambiguous bases in the denominator):

def gc_content_percent(seq):
    s = seq.upper().replace('U', 'T')
    valid = sum(1 for c in s if c in 'ATCG')
    g = s.count('G')
    c = s.count('C')
    if valid == 0:
        return 0.0
    return round((g + c) / valid * 100, 1)

Frame translation (0-indexed frame; for frame 2 use frame=1):

CODON_TABLE = {
    'TTT':'F','TTC':'F','TTA':'L','TTG':'L',
    'CTT':'L','CTC':'L','CTA':'L','CTG':'L',
    'ATT':'I','ATC':'I','ATA':'I','ATG':'M',
    'GTT':'V','GTC':'V','GTA':'V','GTG':'V',
    'TCT':'S','TCC':'S','TCA':'S','TCG':'S',
    'CCT':'P','CCC':'P','CCA':'P','CCG':'P',
    'ACT':'T','ACC':'T','ACA':'T','ACG':'T',
    'GCT':'A','GCC':'A','GCA':'A','GCG':'A',
    'TAT':'Y','TAC':'Y','TAA':'*','TAG':'*',
    'CAT':'H','CAC':'H','CAA':'Q','CAG':'Q',
    'AAT':'N','AAC':'N','AAA':'K','AAG':'K',
    'GAT':'D','GAC':'D','GAA':'E','GAG':'E',
    'TGT':'C','TGC':'C','TGA':'*','TGG':'W',
    'CGT':'R','CGC':'R','CGA':'R','CGG':'R',
    'AGT':'S','AGC':'S','AGA':'R','AGG':'R',
    'GGT':'G','GGC':'G','GGA':'G','GGG':'G',
}

def translate_frame(seq, frame=0):
    s = seq.upper().replace('U', 'T')
    protein = []
    for i in range(frame, len(s) - 2, 3):
        codon = s[i:i+3]
        if any(ch not in 'ATCG' for ch in codon):
            protein.append('?')
        else:
            protein.append(CODON_TABLE.get(codon, '?'))
    return ''.join(protein)

Longest ORF length in bp (inclusive of stop), across frames:

STOPS = {'TAA','TAG','TGA'}

def longest_orf_bp(seq):
    s = seq.upper().replace('U', 'T')
    best = 0
    for frame in range(3):
        # consider every ATG as a start candidate
        for i in range(frame, len(s) - 2, 3):
            codon = s[i:i+3]
            if codon != 'ATG':
                continue
            # scan to the first in-frame stop after this ATG
            for j in range(i + 3, len(s) - 2, 3):
                stop_codon = s[j:j+3]
                if stop_codon in STOPS:
                    length = (j - i) + 3  # include stop codon
                    if length > best:
                        best = length
                    break
    return best

Verification

Use these checks before finalizing results:

Common Pitfalls

Optional Script Usage

A helper script is provided to standardize computations.

Examples:

Integrate these outputs into the exact line-based format required by the task prompt.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.