VCF Variant Annotation
When to Use
- Annotate genetic variants from VCF files
- Classify variant types from allele changes
- Process VCF INFO fields
Input
/root/input.vcf: VCF v4.2 format file
- Read the VCF header and one or more data lines first to confirm the expected columns before parsing (
CHROM,POS,REF,ALT).
Minimal Workflow
Minimal Workflow
- Read
/root/input.vcfand extractCHROM,POS,REF, andALTfrom each non-header record. - Classify each ALT allele directly from the REF/ALT values using the length-based rules in this skill; do not infer type from INFO when REF/ALT already determine it.
- Write
/root/output.txtin the exact formatCHR:POS TYPE REF>ALT, with one output line per ALT allele. - After writing the file, read it back and confirm every line matches the required format.
Variant Type Rules
Based on REF vs ALT:
- SNP: REF and ALT differ by 1 base
- MNP: REF and ALT differ by multiple bases (same length)
- INS: ALT longer than REF (insertion)
- DEL: ALT shorter than REF (deletion)
Classify each REF/ALT pair by direct length comparison:
- If
len(REF) == 1andlen(ALT) == 1, classify asSNP - If
len(REF) == len(ALT)and length > 1, classify asMNP - If
len(ALT) > len(REF), classify asINS - If
len(ALT) < len(REF), classify asDEL - If
ALTcontains multiple comma-separated alleles, classify each ALT allele separately against the same REF.
Output Format
To /root/output.txt:
chr1:100 SNP A>G
chr2:200 INS T>TA
Format: CHR:POS TYPE REF>ALT
- Match the output schema exactly: write one annotation per line as
CHR:POS TYPE REF>ALTwith no extra text. - If a record has multiple ALT alleles, emit one output line per ALT allele.
VCF Parsing
- Skip VCF metadata lines starting with
##and the column header line starting with#CHROM - CHROM: chromosome
- POS: position
- REF: reference allele (column 4)
- ALT: alternate allele(s) (column 5)
- Process only tab-delimited variant data rows using
CHROM,POS,REF, andALT - For simple type annotation, classify directly from
REFandALTwithout using INFO unless the task explicitly requires it
Tips
- Parse VCF with pysam or plain text parsing if the file is simple
- Prefer simple field-based parsing for straightforward VCF-to-text transformations
- Classify each ALT allele independently from its REF/ALT length relationship
- Use
/root/input.vcfas input and write final results to/root/output.txtexactly as requested - After writing
/root/output.txt, read it back and confirm every line matchesCHR:POS TYPE REF>ALT