Variant analysis

From XuShuwenn/RedAct · View interactive version

Variant analysis is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Annotate VCF variants with their type (SNP, MNP, INS, DEL) based on REF and ALT allele lengths. Use when parsing VCF files and classifying variant types from sequence changes.

How to use this skill

Skill file

Variant Analysis: VCF Variant Type Annotation

Overview

Given a VCF file, annotate each variant with its type (SNP, MNP, INS, DEL) based on the length difference between REF and ALT alleles.

Variant Type Classification Rules

From the REF and ALT alleles:

VCF Parsing

def parse_vcf(filepath):
    """Parse VCF file and return list of variant records."""
    variants = []
    with open(filepath) as f:
        for line in f:
            if line.startswith("#"):
                continue  # Skip header
            fields = line.strip().split("\t")
            chrom = fields[0]
            pos = int(fields[1])
            ref = fields[3]
            alt = fields[4]
            variants.append((chrom, pos, ref, alt))
    return variants

Variant Type Detection

def classify_variant_type(ref, alt):
    """Classify variant as SNP, MNP, INS, or DEL."""
    ref_len = len(ref)
    alt_len = len(alt)
    len_diff = alt_len - ref_len

    if len_diff == 0:
        # Same length - SNP or MNP
        if ref_len == 1:
            return "SNP"
        else:
            return "MNP"
    elif len_diff > 0:
        return "INS"
    else:
        return "DEL"

Complete Script

def parse_vcf(filepath):
    variants = []
    with open(filepath) as f:
        for line in f:
            if line.startswith("#"):
                continue
            fields = line.strip().split("\t")
            chrom = fields[0]
            pos = int(fields[1])
            ref = fields[3]
            alt = fields[4]
            variants.append((chrom, pos, ref, alt))
    return variants

def classify_variant_type(ref, alt):
    ref_len = len(ref)
    alt_len = len(alt)
    len_diff = alt_len - ref_len

    if len_diff == 0:
        return "SNP" if ref_len == 1 else "MNP"
    elif len_diff > 0:
        return "INS"
    else:
        return "DEL"

# Parse VCF and annotate
variants = parse_vcf("/root/input.vcf")

with open("/root/output.txt", "w") as f:
    for chrom, pos, ref, alt in variants:
        vtype = classify_variant_type(ref, alt)
        f.write(f"{chrom}:{pos} {vtype} {ref}>{alt}\n")

Output Format

chr1:100 SNP A>G
chr2:200 INS T>TA
chr3:300 DEL ACG>AC

Format: CHR:POS TYPE REF>ALT

Key Reference

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.