David Poznik, 23andMe
yhaplo identifies the Y-chromosome haplogroup of each male in a sample of one to
millions. It does not rely on any particular genotyping modality or platform, and it is
robust to missing data, genotype errors, mutation recurrence, and other complications.
Although full sequences yield the most granular haplogroup classifications, genotyping
arrays can yield reliable calls, provided a reasonable number of phylogenetically
informative variants has been assayed.
Briefly, haplogroup calling involves two steps. The program first builds an internal representation of the Y-chromosome phylogeny by reading its primary structure from (Newick-formatted) text and importing phylogenetically informative SNPs from the ISOGG database, affiliating each SNP with the appropriate node and growing the tree as necessary. It then traverses the tree for each individual, identifying the path of derived alleles leading to a haplogroup designation.
yhaplo is available for non-commercial use pursuant to the terms of the non-exclusive
license agreement, LICENSE.txt. To learn more about the algorithm,
please see our bioRxiv preprint:
Poznik GD. 2016. Identifying Y-chromosome haplogroups in arbitrarily large samples
of sequenced or genotyped men. bioRxiv doi: 10.1101/088716
To learn more about the software, please see the manual, yhaplo_manual.pdf.
For an overiew of command-line options, install the package and run yhaplo --help.
To install:
git clone [email protected]:23andMe/yhaplo.git
cd yhaplo
pip install --editable .To update:
cd /path/to/yhaplo
git pull # Update code
pip install --editable . # Update version numberTo include optional dependencies for various features:
pip install --editable .[vcf]Enables running on VCF/BCF inputpip install --editable .[plot]Enables tree plottingpip install --editable .[dev]Includes all optional dependencies, as well as development tools (e.g.,pytest)
To install multiple optional features, use a comma-separated list. For example:
pip install --editable .[vcf,plot]To run on example text data:
yhaplo --example_textThe --example_text option tells yhaplo to run on a subset of 1000 Genomes data
in sample-major text format. It also sets the --all_aux_output flag
to produce all auxiliary output.
Similarly, to run on example VCF data:
yhaplo --example_vcfTo run unit tests:
make testSee tests/ for test implementations.
Please note the following caveats before running yhaplo:
yhaplodoes not check for sex status; it assumes all individuals are male.yhaploexpects SNP coordinates consistent with the hg19/GRCh37 reference assembly.yhaploexpects data at a reasonable number of ISOGG SNPs. This assumption is violated by:- Variants-only sequence data
- Very low-coverage sequencing
- Genotyping arrays with few Y-chromosome probes
If, for a given individual, yhaplo observes no derived alleles at ISOGG SNPs on the upper
branches of the Y-chromosome phylogeny, it will call the individual haplogroup "A,"
since all human Y-chromosome lineages are technically sublineages of A.
Before concluding that the individual sample belongs to paragroup A (which
includes haplogroups A00, A0, A1a, and A1b1), run with the --anc_snps option, and check the
auxiliary output for ancestral alleles at haplogroup-BT SNPs. If you do not see any,
your data set probably violates one or more of the assumptions listed above.
In particular, "variants-only" VCF files restrict to SNPs at which alternative alleles
were observed, but ref/alt status is unimportant to yhaplo. What is important is
ancestral/derived status. The reference sequence contains many derived alleles,
and yhaplo will not be happy if you discard these valuable data. So please emit all
confident sites when calling variants. To limit file size, you could safely restrict to
positions in output/isogg.snps.unique.DATE.txt, as these are the only SNPs yhaplo
considers. To generate this file, just run yhaplo with no arguments.
The following input file types are supported:
- Indexed BCF:
.bcf,.bcf.csi - Indexed VCF:
.vcf.gz,.vcf.gz.tbi - Sample-major text:
.genos.txtor.genos.txt.gz- Row 0: Physical coordinates (GRCh37)
- Column 0: Individual identifiers
- Cell (i, j): Genotype for individual i at position j.
Values include {"A", "C", "G", "T", "."}, with "." indicating an unobserved value.
All output file formats are described in detail in yhaplo_manual.pdf.
The two primary output files are:
log.project_name.txtLog file containing details of the runhaplogroups.project_name.txtHaplogroup calls. The 4 columns are:- ID
- Haplogroup short form, with the name of a SNP observed in the derived state
- Haplogroup short form, with the name of a representative SNP
- Haplogroup long form, using Y-Chromosome Consortium nomenclature
yhaplo also produces a number of SNP tables, tree files, and auxiliary output files.
Please see yhaplo_manual.pdf and yhaplo --help for details.
See yhaplo/api/call_haplogroups.py.
The main command-line entry-point is yhaplo.
Additional commands include:
yhaplo-convert-to-genosyhaplo-plot-tree
The primary structure of the Y-chromosome tree is stored in
yhaplo/data/tree/.
Variant metadata are stored in yhaplo/data/variants/:
isogg.DATE.txtPhylogenetically informative SNPs scraped directly from the ISOGG website.
yhaploresolves errors and formatting inconsistencies and emits cleaned versions:isogg.snps.cleaned.DATE.txt,isogg.snps.unique.DATE.txt.
Seeyhaplo_manual.pdffor details.isogg.correct.*.txtCorrections to ISOGG dataisogg.multiallelic.txtPhysical coordinates of multiallelic sites to be excludedisogg.omit.*.txtSNPs to drop due to inconsistencies observed in test dataisogg.split.txtNot currently usedpreferred.snp_names.txtList of preferred SNP namesrepresentative.SNPs.*.txtSNPs deemed representative of corresponding haplogroups
The Tree class is defined in tree.py. It:
- Parses a Newick file to build primary tree
- Parses ISOGG table to add SNPs to nodes and grow tree
- Finds the derived path leading from the root to an individual
- Knows root, depth, haplogroup-to-node mappings, etc.
The Node class is defined in node.py. It:
- Represents a phylogenetic branch
- Knows parent, children, SNPs, etc.
The SNP class and related classes are defined in snp.py:
SNPKnows position, ancestral and derived alleles, node, etc.
The Sample class and its subclasses are defined in sample.py:
SampleKnows genotypes and haplogroup of an individualTextSampleSubclass for sample-major text inputVCFSampleSubclass for VCF/BCF input
The Path class is defined in path.py.
It represents a path through a tree and stores:
- The next node to visit
- A list of SNPs observed in the derived state
- The most derived SNP observed
- The number of ancestral alleles encountered
The Config class is defined in config.py.
It is a container for parameters, command-line options, and filenames.