{"id":13937163,"url":"https://github.com/cslarsen/dna-traits","last_synced_at":"2025-07-19T04:34:05.608Z","repository":{"id":12981439,"uuid":"15660211","full_name":"cslarsen/dna-traits","owner":"cslarsen","description":"A fast 23andMe genome text file parser, now superseded by arv","archived":false,"fork":false,"pushed_at":"2017-11-12T00:42:59.000Z","size":291,"stargazers_count":65,"open_issues_count":0,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-10T22:37:27.687Z","etag":null,"topics":["23andme","bioinformatics","dna","genomics","health-report","python","snpedia","snps"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cslarsen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-05T22:45:02.000Z","updated_at":"2025-03-05T10:29:21.000Z","dependencies_parsed_at":"2022-07-08T05:05:18.390Z","dependency_job_id":null,"html_url":"https://github.com/cslarsen/dna-traits","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cslarsen/dna-traits","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cslarsen%2Fdna-traits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cslarsen%2Fdna-traits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cslarsen%2Fdna-traits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cslarsen%2Fdna-traits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cslarsen","download_url":"https://codeload.github.com/cslarsen/dna-traits/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cslarsen%2Fdna-traits/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265888951,"owners_count":23844537,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["23andme","bioinformatics","dna","genomics","health-report","python","snpedia","snps"],"created_at":"2024-08-07T23:03:20.794Z","updated_at":"2025-07-19T04:34:05.587Z","avatar_url":"https://github.com/cslarsen.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"Project has moved!\n==================\n\n**This project has been abandoned in favor of the newer and better\nhttps://github.com/cslarsen/arv — which is faster, installable via pip and\nworks on both Python 2 and 3.**\n\nThe dna-traits 23andMe parser library\n=====================================\n\n\nThis is a *very* fast 23andMe raw genome file parser, letting you lookup SNPs\nfrom RSIDs in Python:\n\n    import dna_traits as dt\n\n    genome = dt.parse(\"genome.txt\")\n\n    gender = \"man\" if genome.y_chromosome else \"woman\"\n    complexion = \"light\" if genome.rs1426654 == \"AA\" else \"dark\"\n\n    eye_color = dt.unphased_match(genome.rs12913832, {\n        \"AA\": \"brown\",\n        \"AG\": \"brown or green\",\n        \"GG\": \"blue\"})\n\n    print(\"You are a {gender} with {eye_color} eyes and {complexion} skin.\".format(\n        gender=gender, eye_color=eye_color, complexion=complexion))\n\nIn my case, this little program produces\n\n    You are a man with blue eyes and light skin.\n\nThe need for speed\n==================\n\nOn *my* machine, a 2010-era MBP with SSD, I can parse a 24 Mb file using\nPython's `csv` module and create a dictionary in 2.5 seconds. Pandas takes\naround 2.1 seconds, and I've seen some parsers take up to 8.\n\nIn comparison, `dna_traits` takes only **0.12 seconds** (g++ 5.3), and uses\ndramatically less memory (six bytes per SNP, containing its nucleotide pair,\nchromosome and position). A more recent 2013-era, Intel Xeon Linux box does the\nsame **in a blazing 0.07 seconds**!\n\nWhile I love Pandas for its power and generality, this library is fast because\nit is meticulously specialized:  The finely-tuned C++ backend memory maps the\nfile and *never* scans backwards — every single byte is touched exactly once.\nThe SNPs are stored in a memory efficient packed struct and stored in Google's\ndense hash map, keyed by its 32-bit RSID.\n\nThe Python API\n==============\n\nThe project is split up into two parts: A C++ API, and a Python 2 module\nfront-end. It should be straight-forward to create bindings for other languages\nas well.\n\nHere are some examples illustrating various facets of the Python API:\n\n    \u003e\u003e\u003e import dna_traits as dt\n    \u003e\u003e\u003e genome = dt.parse(\"genome.txt\")\n    \u003e\u003e\u003e genome\n    \u003cGenome: SNPs=949905, y_chromosome=True, orientation=1\u003e\n    \u003e\u003e\u003e genome.male\n    True\n    \u003e\u003e\u003e genome[\"rs123\"]\n    SNP(genotype='AA', rsid='rs123', orientation=1, chromosome=7, position=24966446)\n    \u003e\u003e\u003e snp = genome.rs123\n    \u003e\u003e\u003e snp.homozygous\n    True\n    \u003e\u003e\u003e ~snp\n    SNP(genotype='TT', rsid='rs123', orientation=1, chromosome=7, position=24966446)\n\nMore information can be found in `py-dnatraits/README.md`\n\nCurrent issues\n==============\n\n  * The Python module is not ready for PyPi\n\n  * Depends on GNU Make, but an incomplete CMake configuration is in progress.\n\n  * The Python API is currenty somewhat limited and inconsistent, but still\n    very much usable!\n\n  * Doesn't parse 23andMe internal IDs yet.\n\n  * Although loading the file is fast, whole genome iteration is insanely slow\n    in Python. It's because I don't really expose an iterator from C++ to\n    Python yet.\n\nBuilding\n========\n\nThe main build system is GNU Make, but I am slowly transitioning to CMake.\n\nRequirements\n------------\n\n  * A C++11 compiler\n\n  * Google sparse hash map\n\n  * Genome files in 23andMe format. Many people have uploaded theirs on the\n    net for free use. See for example OpenSNP.  If you're a 23andMe\n    customer, you can download your own from them.\n\n  * Python development files, if you want to build the Python module.\n\nGNU Make\n--------\n\nIf Google dense hash map is located in `/usr/local/include`, build\neverything, including the Python API, with:\n\n    $ make -j all CXXFLAGS=-I/usr/local/include\n\nBuild the `check` target to check if everything works.\n\n    $ make check\n\nCMake\n-----\n\nI'm transitioning to CMake, but it's currently not working properly. See\n`build-ninja.sh` and `build-make.sh` to test out the current status.\n\nExample of inferring phenotypes\n===============================\n\nSNPedia contains the `gs237` criteria for determining whether a person has\nblue eyes. At http://snpedia.com/index.php/Gs237/criteria the rule set says:\n\n    and(\n      rs4778241(C;C),\n      rs12913832(G;G),\n      rs7495174(A;A),\n      rs8028689(T;T),\n      rs7183877(C;C),\n      rs1800401(C;C))\n\nIn C++ this would be:\n\n    static bool gs237(const Genome\u0026 genome)\n    {\n      return genome[ 4778241] ==  CC\n          \u0026\u0026 genome[12913832] ==  GG\n          \u0026\u0026 genome[ 7495174] ==  AA\n          \u0026\u0026 genome[ 8028689] ==  TT\n          \u0026\u0026 genome[ 7183877] ==  CC\n          \u0026\u0026 genome[ 1800401] == ~CC;\n    }\n\nThe only thing to note is each SNP's orientation. 23andMe uses positive\norientation, while SNPedia has varying orientation. That's why we flip the\norientation in the last check for the `rs1800401` SNP \n\nIn Python, this can be done in any number of ways, but one way is to use the\n``Genome.match`` function:\n\n    all(genome.match(((\"rs4778241\",  \"CC\"),\n                      (\"rs12913832\", \"GG\"),\n                      (\"rs7495174\",  \"AA\"),\n                      (\"rs8028689\",  \"TT\"),\n                      (\"rs7183877\",  \"CC\"),\n                      (\"rs1800401\",  \"GG\"))))\n\n\nExample reports\n===============\n\nI've implemented some of the 23andMe health reports, traits and conditions. You\ncan see the content here:\n\n  * Traits,\n    https://github.com/cslarsen/dna-traits/blob/master/py-dnatraits/dna_traits/traits.py\n  * Health,\n    https://github.com/cslarsen/dna-traits/blob/master/py-dnatraits/dna_traits/health.py\n  * Conditions,\n    https://github.com/cslarsen/dna-traits/blob/master/py-dnatraits/dna_traits/conditions.py\n\nNote that there might very well be errors in the above reports, so use with\ncare! In particular, the odds ratios are most likely very incorrect.  The best\nbet is the traits. These should be correct, as well as some simple health\nreports. So, the main goal is for this to be educational. In other words,\nexplore on your own.\n\nLicense\n=======\n\nCopyright (C) 2014, 2016 Christian Stigen Larsen  \nhttps://csl.name\n\nDistributed under GPL v3 or later. See the file COPYING for the full license.\nThis software makes use of open source software; see LICENSES for details.\n\nAdditional disclaimer\n=====================\n\nIn addition to the GPL v3 license terms, and given that this code deals with\nhealth-related issues, I want to stress that the provided code most likely\ncontains errors, or invalid genome reports.  Results from this code must be\ninterpreted as HIGHLY SPECULATIVE and may even be downright INCORRECT. Always\nconsult a medical expert for guidance.  I take NO RESPONSIBILITY whatsoever for\nany consequences of using this code, including but not limited to loss of life,\nmoney, spuses, self-esteem and so on. Use at YOUR OWN RISK.\n\nThe indended use is for casual, educational purposes. If this code is used for\nresearch purposes, I would be happy if you should cite me. If so, beware that\nthe parser code may contain serious errors. I would advise you to check for\nupdates, and also to double-check results with other parsers.\n\nPlaces of interest\n==================\n\n  * SNPedia, http://snpedia.com\n  * OpenSNP, http://opensnp.org/genotypes\n  * dbSNP, http://www.ncbi.nlm.nih.gov/SNP/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcslarsen%2Fdna-traits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcslarsen%2Fdna-traits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcslarsen%2Fdna-traits/lists"}