コード例 #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("")
コード例 #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)
コード例 #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("")
コード例 #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)
コード例 #5
0
ファイル: bench.py プロジェクト: cslarsen/dna-traits
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
コード例 #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
コード例 #7
0
ファイル: haplotype.py プロジェクト: OasisYE/dna-traits
 def parse(name):
     sys.stdout.write("Parsing %s" % name)
     sys.stdout.flush()
     return dt.parse(name)
コード例 #8
0
ファイル: haplotype.py プロジェクト: WeHaveNoLife/dna-traits
 def parse(name):
     sys.stdout.write("Parsing %s" % name)
     sys.stdout.flush()
     return dt.parse(name)
コード例 #9
0
ファイル: test_dna_traits.py プロジェクト: OasisYE/dna-traits
 def setUpClass(cls):
     cls.genome = dt.parse("../genomes/genome.txt")
コード例 #10
0
ファイル: blue-eyes.py プロジェクト: WeHaveNoLife/dna-traits
#!/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"))
コード例 #11
0
ファイル: blue-eyes.py プロジェクト: cslarsen/dna-traits
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)
コード例 #12
0
 def setUpClass(cls):
     cls.genome = dt.parse("../genomes/genome.txt")
コード例 #13
0
ファイル: profile.py プロジェクト: WeHaveNoLife/dna-traits
        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))
コード例 #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))
コード例 #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))
コード例 #16
0
ファイル: blue-eyes.py プロジェクト: OasisYE/dna-traits
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)
コード例 #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))