Ejemplo n.º 1
0
def check(filename):
    print(filename)
    genome = dt.parse(filename)

    for rsid, genotypes in sorted(rules.items()):
        negative = False
        if rsid.endswith("-"):
            negative = True
            rsid = rsid[:-1]

        snp = genome[rsid]
        if negative:
            snp = ~snp

        hit = False
        for genotype, descr in genotypes.items():
            if snp == genotype:
                hit = True
                lines = descr.split("\n")
                print("%10s %2s: %s" % (rsid, genotype, lines[0]))
                for line in lines[1:]:
                    print("%10s %2s  %s" % ("", "", line))

        if not hit:
            print("%10s %2s  %s" % (rsid, "", "<No match>"))
    print("")
Ejemplo n.º 2
0
def main(files):
  if not files:
    print("Usage: bone-strength [ file(s) ]")
    print("The files must be human genomes in 23andMe-format.")
    return 1

  for file in files:
    genome = dt.parse(file)
    scores = bone_strength(genome)

    print("Bone-strength estimated from genome %s" % file)
    print("(Higher points is stronger bone)\n")

    # Add totals
    max_total = sum(p for p,_ in scores.values())
    total = sum(p for _,p in scores.values())
    scores["Total score"] = (max_total, total)

    for title, (max_score, score) in scores.items():
      print("  %18s: %2d of %2d" % (title, score, max_score))

    print("")

    for rsid in ["rs2707466", "rs2908004", "rs7776725", "rs9525638"]:
        if rsid not in genome:
            print(("Note: %s wasn't in this genome; scores may be a bit " +
                  "too high") % rsid)
Ejemplo n.º 3
0
def check(filename):
    print(filename)
    genome = dt.parse(filename)

    for rsid, genotypes in sorted(rules.items()):
        negative = False
        if rsid.endswith("-"):
            negative = True
            rsid = rsid[:-1]

        snp = genome[rsid]
        if negative:
            snp = ~snp

        hit = False
        for genotype, descr in genotypes.items():
            if snp == genotype:
                hit = True
                lines = descr.split("\n")
                print("%10s %2s: %s" % (rsid, genotype, lines[0]))
                for line in lines[1:]:
                    print("%10s %2s  %s" % ("", "", line))

        if not hit:
            print("%10s %2s  %s" % (rsid, "", "<No match>"))
    print("")
Ejemplo n.º 4
0
def report_bone_strength(files):
  if not files:
    print("Usage: bone-strength [ file(s) ]")
    print("The files must be human genomes in 23andMe-format.")
    return 1

  for file in files:
    genome = dt.parse(file)
    scores = bone_strength(genome)

    print("Bone-strength estimated from genome %s" % file)
    print("(Higher points is stronger bone)\n")

    # Add totals
    max_total = sum(p for p,_ in scores.values())
    total = sum(p for _,p in scores.values())
    scores["Total score"] = (max_total, total)

    for title, (max_score, score) in scores.items():
      print("  %18s: %2d of %2d" % (title, score, max_score))

    print("")

    for rsid in ["rs2707466", "rs2908004", "rs7776725", "rs9525638"]:
        if rsid not in genome:
            print(("Note: %s wasn't in this genome; scores may be a bit " +
                  "too high") % rsid)
Ejemplo n.º 5
0
def all_benchmarks(filename, times):
    results = {}
    genome = dna_traits.parse(filename)

    for name, code in sorted(benchmarks.items()):
        log("Benchmarking %s x %d ... " % (repr(name), times))
        try:
            results[name] = benchmark(times, code, filename=filename,
                    genome=genome, random=random)
        except Exception as e:
            log("e")
        finally:
            log("\n")

    return results
Ejemplo n.º 6
0
def all_benchmarks(filename, times):
    results = {}
    genome = dna_traits.parse(filename)

    for name, code in sorted(benchmarks.items()):
        log("Benchmarking %s x %d ... " % (repr(name), times))
        try:
            results[name] = benchmark(times,
                                      code,
                                      filename=filename,
                                      genome=genome,
                                      random=random)
        except Exception as e:
            log("e")
        finally:
            log("\n")

    return results
Ejemplo n.º 7
0
 def parse(name):
     sys.stdout.write("Parsing %s" % name)
     sys.stdout.flush()
     return dt.parse(name)
Ejemplo n.º 8
0
 def parse(name):
     sys.stdout.write("Parsing %s" % name)
     sys.stdout.flush()
     return dt.parse(name)
Ejemplo n.º 9
0
 def setUpClass(cls):
     cls.genome = dt.parse("../genomes/genome.txt")
Ejemplo n.º 10
0
#!/usr/bin/env python

"""
Runs SNPedia criteria gs237 on a genome, determining whether a person (of
European descent) is likely to have blue eyes.

In my experience, this rule set is kinda flaky, but serves her as an example
on how to use the Python API.
"""

import sys
import dna_traits as dt

def gs237(genome):
    """Returns whether SNPedia gs237 criteria matches genome."""
    return all(genome.match((("rs4778241", "CC"),
                             ("rs12913832", "GG"),
                             ("rs7495174", "AA"),
                             ("rs8028689", "TT"),
                             ("rs7183877", "CC"),
                             ("rs1800401", "GG"))))

if __name__ == "__main__":
    for file in sys.argv[1:]:
        genome = dt.parse(file)
        print("%s: Blue eyes (gs237): %s" % (file,
            "Likely" if gs237(genome) else "Unlikely"))
Ejemplo n.º 11
0
def blue_eyes(filename):
    """Runs the SNPedia gs237 criterion for determining likelyhood of blue
    eyes."""
    genome = dt.parse(filename)
    result = "Likely" if gs237(genome) else "Unlikely"
    return "%s: Blue eyes (gs237): %s" % (filename, resul)
Ejemplo n.º 12
0
 def setUpClass(cls):
     cls.genome = dt.parse("../genomes/genome.txt")
Ejemplo n.º 13
0
        return "Likely, if European"
    else:
        return "Unlikely?"

def skin_complexion(genome):
    snp = genome.rs1426654

    if snp == "AA":
        return "Likely light-skinned of European descent"

    if snp == "GA" or snp == "AG":
        return "Possibly mixed African-European ancestry"

    if snp == "GG":
        return "Likely dark-skinned of Asian or African ancestry"

    return "Unknown"

def profile(g):
    return {
        "Gender": "Male" if g.male else "Female",
        "Blue eyes": blue_eyes(g),
        "Skin color": skin_complexion(g),
    }

if __name__ == "__main__":
    for file in sys.argv[1:]:
        print(file)
        for k,v in profile(dt.parse(file)).items():
            print("%-18s %s" % (k+":",v))
Ejemplo n.º 14
0
    if title is not None:
        print(title)
        if underline is not None:
            print(underline * len(title))

    width = max(map(len, report.keys()))
    for key, value in sorted(report.items()):
        lines = value.split("\n")
        if lines == 1:
            print("%-*s %s" % (width + 1, "%s:" % key, value))
        else:
            print("%-*s %s" % (width + 1, "%s:" % key, lines[0]))
            for line in lines[1:]:
                print("%-*s %s" % (width + 1, " " * (len(key) + 1), line))

    if title is not None:
        print("")


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: health-risks genome(s)")
        sys.exit(1)

    for filename in sys.argv[1:]:
        print("%s\n" % filename)
        genome = dt.parse(filename)
        print_report("Health report", health_report(genome))
        print_report("Inherited conditions", inherited_conditions(genome))
        print_report("Traits", traits_report(genome))
Ejemplo n.º 15
0
    """Prints a dict with some text formatting."""
    if title is not None:
        print(title)
        if underline is not None:
            print(underline*len(title))

    width = max(map(len, report.keys()))
    for key, value in sorted(report.items()):
        lines = value.split("\n")
        if lines == 1:
            print("%-*s %s" % (width+1, "%s:" % key, value))
        else:
            print("%-*s %s" % (width+1, "%s:" % key, lines[0]))
            for line in lines[1:]:
                print("%-*s %s" % (width+1, " "*(len(key)+1), line))

    if title is not None:
        print("")

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: health-risks genome(s)")
        sys.exit(1)

    for filename in sys.argv[1:]:
        print("%s\n" % filename)
        genome = dt.parse(filename)
        print_report("Health report", health_report(genome))
        print_report("Inherited conditions", inherited_conditions(genome))
        print_report("Traits", traits_report(genome))
Ejemplo n.º 16
0
def blue_eyes(filename):
    """Runs the SNPedia gs237 criterion for determining likelyhood of blue
    eyes."""
    genome = dt.parse(filename)
    result = "Likely" if gs237(genome) else "Unlikely"
    return "%s: Blue eyes (gs237): %s" % (filename, resul)
Ejemplo n.º 17
0

def skin_complexion(genome):
    snp = genome.rs1426654

    if snp == "AA":
        return "Likely light-skinned of European descent"

    if snp == "GA" or snp == "AG":
        return "Possibly mixed African-European ancestry"

    if snp == "GG":
        return "Likely dark-skinned of Asian or African ancestry"

    return "Unknown"


def profile(g):
    return {
        "Gender": "Male" if g.male else "Female",
        "Blue eyes": blue_eyes(g),
        "Skin color": skin_complexion(g),
    }


if __name__ == "__main__":
    for file in sys.argv[1:]:
        print(file)
        for k, v in profile(dt.parse(file)).items():
            print("%-18s %s" % (k + ":", v))