Giter Club home page Giter Club logo

svaha2's Introduction

svaha2: linear time, low-memory construction of variation graphs

Eric T Dawson
June 2019

Build Status

Intro

svaha2 is a reimplementation of the svaha algorithm for variation graph construction. It cleans up the code significantly and makes use of better parsing libraries. Performance is slightly improved.

With svaha2, you can make variation graphs from structural variants:

  • Deletions
  • Inversions
  • Insertions
  • SNPs
  • Duplications
  • Translocations
  • Breakpoints

In addition, there are currently some limitations on variants:

  • While variants may be nested, they cannot share a given breakpoint.
  • Variants may only possess a single alternate allele
  • Variants must possess the following fields:
    • SVTYPE (DEL, INS, INV, TRA)
    • END (DEL, INV, TRA)
    • CHR2 (TRA)
    • SEQ (INS)

Given a well-formed VCF and a FASTA reference, svaha2 can produce a GFA graph in a matter of minutes for as many as several hundred thousand variants in under 16GB of RAM.

Usage

svaha2: linear-time, low-memory construction of variation graphs.
Usage: svaha2 [options] -r <ref.fa> -v <variants.vcf>
options:
-m / --max-node-size : maximum length (in basepairs) of a node in the graph.
-r / --reference     : The reference genome to use for construction.
-v / --vcf           : A VCF file to use for construction.
-b / --bed           : a bed file to restrict chromosomes to.
-T / --no-translocations  : ignore interchromosomal variants.
-f / --flat          : use flat alternates (every allele is represented by at least one node).
-p / --paths         : output path information for variants.
-I / --insertions         : FASTA file of insertion variant sequences.

Algorithm

Roughly, the svaha algorithm works as follows:

1. Read in all variants. Compute the breakpoints for each variant, and store a map(basepair -> variant allele).
2. Add any breakpoints needed for maxmimum node size.
3. For each contig, sort its breakpoints. Remove any duplicates and any invalid ones (first/last base of sequence).
4. For each contig:
    5. For each breakpoint b in the contig's breakpoints  
        - Create a node
        - Fill it with the reference subseqence from the previous breakpoint to the current one.
        - If there is a variant at the node's position, cache the node in a map from position to node.
        - If the node is cached, also cache the preceding node.
        - If the variant is flat, or an insertion / substitution, create a node. Store it in a map from position to inserted nodes.  
        - Output the node in GFA format, add it the ref path if needed, and add an edge to the previous ref node if this node is also on the reference
        path.
6. For each contig  
    7. For each cached position-variant allele in the position->variant allele map. 
        - Collect the relevant nodes before / in / after the variant (depending on if it's flat or not).  
        - Create edges to represent the variant based on its SVTYPE.  
        - Ouput nodes and edges in GFA.  

Feature Roadmap

  • Lightweight storage of GFA paths (probably file backed). These are super expensive at the moment.
  • Output maps to memory-mapped files, rather than keeping them in memory.
  • Big performance boost by reducing number of loops (all variant types except interchromosomals). This requires file-backed maps.
  • Multiple variants at a site (will increase memory usage).
  • We build everything by contig right now. That's probably fine, but it could be too much for SNVs and indels.
  • Duplication handling. This is easy, but it's a bit moot given that aligners don't like cyclic structures.
  • Tabix / VCF-index handling. This will greatly improve memory usage by no longer requiring alleles to stay in memory.
  • GFA indexing using tinyGFA. This means we no longer need to cache nodes, just their IDs (128+bit struct -> 64bit Int).
  • Optional GFA1 / GFA2 output. Right now, we just output GFA1 (but this is easily converted with GFAKluge). All Links are valid Edges so this just requires adding the args and some hhandling logic.
  • Threading (zoom zoom). But we'll have to be careful about buffering output so the threads don't just thrash the disk and making sure to keep RAM usage down by getting rid of the reference sequences ASAP (although this is still a max of <4GB if we keep the whole Human genome).

svaha2's People

Contributors

edawson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

svaha2's Issues

Crazy long VCF lines silently fail

Long vcf lines (such as those with the SV sequence in the ref/alt fields) silently fail parsing. This is standard get_line behavior but is a major issue.

Temporarily, I've fixed this by making the maximum line length really large. This is not an efficient solution. I need to think about how to write a better line-by-line or htslib-style parser (or just htslib) for variants.

Test failed using test data "tgraph.vcf/fa"

Hello,when I use command:
svaha2 -r tgraph.fa -v tgraph.vcf > test.gfa
to generate GFA file,I failed with the error info:

`FASTA index found for tgraph.fa
Parsed fasta index with 1 entries.
Loading variants from tgraph.vcf
Parsed 6 variants.
Created map of contig to breakpoints from variants.
Contig x has 12 breakpoints.

Adding max-node-length breakpoints.
Contig x has 14 breakpoints.
Sorted and uniquified breakpoints
Building reference backbone for x.
terminate called after throwing an instance of 'std::out_of_range'
what(): at: key not present
Aborted`

I need your help,please!

rGFA output

Because we use a reference genome for input, we can easily generate rGFA. This also gets around the many issues of representing paths in GFA 1 and GFA 2.

We need only three tags to make minigraph-compatible rGFA output:

Tag Type Description
SN Z Name of stable sequence from which the segment is derived
SO i Offset on the stable sequence
SR i Rank. 0 if on a linear reference genome; >0 otherwise

For reference graphs, this is pretty simple. We'll need to implement pulling some type of VCF name in as well though.

Adjacent variants crash svaha2

I have repeatedly run into this issue so it's high time I write it down. Variants in a vcf with adjacent positions will cause a segfault, probably because of some sloppy pointer invalidation I coded in mid-thesis.

The right way to fix this is to make a map from genomic position -> a list of alleles/nodes, rather than a single entity. This increases the code complexity but would be a useful improvement.

GFA output does not include overlaps

The GFA output of svaha2 is currently valid GFA 1. However, minigraph requires GFA overlaps in its output. This means the current output of svaha2 is invalid as minigraph input, which is a real shame.

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.