Skip to content

Code overview

Xian Chang edited this page Mar 9, 2026 · 5 revisions

This page goes through the broad steps of the pipeline and where the code can be found. The general workflow of the pipeline is to run either stoat graph or stoat vcf to produce an intermediate genotype file, then run stoat stats to do the statistics on it.

Important classes

Subcommand workflow

stoat graph takes as input a graph with embedded haplotypes and for each snarl and partitions them based on the path they take through the snarl's netgraph. This is done by calling partition_embedded_paths_in_snarl() for each snarl. It then writes an intermediate snarl file containing the genotype for each embedded path.

stoat vcf runs through the snarls twice: once to find all possible paths through every snarl (the potential alleles), and a second time to match the samples in the VCF to the alleles found in the snarls. An intermediate snarl file can be written after each of these steps. The general algorithm is:

  1. Fill in the SnarlDataCollection with walks through each snarl (the alleles for the snarl). This is done using the get_all_walks_through_snarl() function.
  2. Find the genotypes of samples in the VCF by calling genotype_snarls_by_chr_from_vcf()
    1. Parse the VCF with a VCFParser, optionally resolving contradictions in the calls.
    2. Build a EdgeBySampleMatrix. This is build once per chromosome (or chunk of VCF, as long as chunks are non-overlapping along the top-level chain). For each sample, the matrix stores a boolean for whether or not the sample traverses each edge. The edges found from the VCF are added to the EdgeBySampleMatrix by calling load_vcf_chunk().
    3. For each sample, assign an allele to each sample by calling add_alleles_by_sample() with a function that matches the alleles found in step 1 with the sample's path stored in the edge matrix.

This is where all the statistics happens. It takes as input a phenotype file and the intermediate genotype file from either stoat graph or stoat vcf.

  1. The genotypes file is loaded as a SnarlDataCollection
  2. The phenotype file is loaded as the appropriate type of FeatureBySampleTable
  3. Statistics are done using a SnarlAnalyzer with some additional stats functions
  4. The final output is written using a Writer

Clone this wiki locally