Reading frame translation orf

From XuShuwenn/RedAct · View interactive version

Reading frame translation orf is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Determine sequence type, compute GC%, translate a specified reading frame without truncating at stops, and find the longest valid ORF across frames.

How to use this skill

Skill file

Reading Frame Translation and ORF Analysis

Skill for nucleotide sequence tasks that require: sequence type determination (DNA/RNA/Protein), GC content calculation, translating a specified reading frame with stop codons represented as '*', and identifying the longest open reading frame (ORF) across all three frames.

When to Use

Core Workflow

1) Ingest and normalize the sequence

2) Determine sequence type

3) Compute GC content

4) Translate a specific reading frame

5) Find the longest ORF across all three frames

Implementation Snippets

Sequence type detection

def detect_seq_type(seq: str) -> str:
    s = seq.strip().upper()
    dna_set = set("ACGTN")
    rna_set = set("ACGUN")
    if "U" in s and "T" not in s and set(s) <= rna_set:
        return "RNA"
    if "T" in s and "U" not in s and set(s) <= dna_set:
        return "DNA"
    aa_set = set("ACDEFGHIKLMNPQRSTVWY")
    if set(s) <= aa_set:
        return "Protein"
    # Fallback: prefer DNA if T present, RNA if U present, else Protein
    if "T" in s:
        return "DNA"
    if "U" in s:
        return "RNA"
    return "Protein"

GC content (ignore ambiguous N)

def gc_percent(seq: str) -> float:
    s = seq.strip().upper()
    a = s.count('A')
    c = s.count('C')
    g = s.count('G')
    t = s.count('T')
    denom = a + c + g + t
    if denom == 0:
        return 0.0
    pct = (c + g) / denom * 100.0
    return round(pct, 1)

Frame translation (do not truncate at stop)

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: str, frame: int) -> str:
    """Translate DNA in 1-indexed frame (1, 2, or 3), mapping stops to '*'."""
    s = seq.strip().upper().replace('U', 'T')
    offset = {1:0, 2:1, 3:2}.get(frame, 0)
    prot = []
    for i in range(offset, len(s) - 2, 3):
        codon = s[i:i+3]
        aa = CODON_TABLE.get(codon, '?')
        prot.append(aa)
    return ''.join(prot)

Longest ORF across frames (inclusive of stop codon by default)

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

def longest_orf_bp(seq: str, include_stop: bool = True) -> int:
    s = seq.strip().upper().replace('U', 'T')
    best = 0
    n = len(s)
    for offset in (0, 1, 2):
        i = offset
        while i <= n - 3:
            codon = s[i:i+3]
            if codon == 'ATG':
                j = i + 3
                while j <= n - 3:
                    c = s[j:j+3]
                    if c in STOPS:
                        length = (j - i + 3) if include_stop else (j - i)
                        if length > best:
                            best = length
                        break
                    j += 3
                # continue scanning for additional start sites after this i
            i += 3
    return best

Verification

Common Pitfalls and How to Avoid Them

Output Format Guidance

If the task requires specific lines, match them exactly, for example:

Optional Script Usage

The included helper script implements these algorithms and can be used for quick validation or as a reference implementation.

Examples:

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.