Giter Club home page Giter Club logo

Comments (1)

ACEnglish avatar ACEnglish commented on June 24, 2024 1

For those specific examples, I would recommend pre-processing the variants to turn them into resolved variants. A <DEL> could be filled in by setting the REF to reference[entry.start:entry.end] and alt the first base of that sequence. An <INV> essentially the same thing for REF but with the reverse complement in the alt. I've also resolved <DUP> to simply be an insertion of the duplicated range.

Plus, once that's done, you can turn on sequence similarity, which is an important measure for accurately comparing SVs.

An example script for resolving SVs in a VCF is below.

resolve.py
"""
Given a VCF, fill in the <DEL>, <INV>, <DUP> ALT sequence
"""

import sys
import pysam
import truvari

MAX_SV = 100_000_000 # Filter things smaller than this

RC = str.maketrans("ATCG", "TAGC")
def do_rc(s):
    """
    Reverse complement a sequence
    """
    return s.translate(RC)[::-1]

def resolve(entry, ref):
    """
    """
    if entry.start > ref.get_reference_length(entry.chrom):
        return entry
    if entry.alts[0] in ['<CNV>', '<INS>']:
        return entry

    seq = ref.fetch(entry.chrom, entry.start, entry.stop)
    if entry.alts[0] == '<DEL>':
        entry.ref = seq
        entry.alts = [seq[0]]
    elif entry.alts[0] == '<INV>':
        entry.ref = seq
        entry.alts = [do_rc(seq)]
    elif entry.alts[0] == '<DUP>':
        entry.info['SVTYPE'] = 'INS'
        entry.ref = seq[0]
        entry.alts = [seq]
        entry.stop = entry.start + 1

    return entry

if __name__ == '__main__':
    vcf = pysam.VariantFile(sys.argv[1])
    ref = pysam.FastaFile(sys.argv[2])
    n_header = vcf.header.copy()
    
    out = pysam.VariantFile("/dev/stdout", 'w', header=n_header)
    for entry in vcf:
        if truvari.entry_size(entry) >= MAX_SV:
            continue
        if entry.alts[0].startswith("<"):
            entry = resolve(entry, ref)
        try:
            out.write(entry)
        except Exception:
            sys.stderr.write(f"{entry}\n{type(entry)}\n")

from truvari.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.