Skip to content

Commit df40966

Browse files
authored
Merge pull request #1 from arvkevi/handle_new_formats
Handle new formats
2 parents b508556 + e1c4115 commit df40966

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

sn.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,37 @@ def _23andme_exome(path):
7171
yield SNP(name=r.ID, chromosome=r.CHROM, position=r.POS,
7272
genotype=sample.gt_bases.replace("/", ""))
7373

74+
def _23andme_ancestry(path):
75+
handle = csv.DictReader(open(path, "r"),
76+
fieldnames=["name", "chromosome", "position", "allele1", "allele2"],
77+
delimiter="\t")
78+
for row in handle:
79+
if not row["name"].startswith(("#", "rsid")):
80+
row["genotype"] = "{}{}".format(row.pop("allele1"), row.pop("allele2"))
81+
yield SNP(**row)
82+
83+
def _genes_for_good(path):
84+
if vcf is None:
85+
raise RuntimeError("PyVCF not available, please 'easy_install' it.")
86+
87+
try:
88+
for r in vcf.VCFReader(open(path, "rb"), compressed=True):
89+
if not r.is_snp:
90+
continue # XXX Is it even possible?
91+
for sample in r.samples:
92+
yield SNP(name=r.ID, chromosome=r.CHROM, position=r.POS,
93+
genotype=sample.gt_bases.replace("/", ""))
94+
except OSError:
95+
# the gfg format is is likely version 1.1
96+
for snp in _23andme(path):
97+
yield snp
98+
99+
def _iyg(path):
100+
handle = csv.DictReader(open(path, "r"),
101+
fieldnames=["name", "genotype"], delimiter="\t")
102+
for row in handle:
103+
yield SNP(name=row["name"], chromosome=None, position=0,
104+
genotype=row["genotype"])
74105

75106
def decodeme(path):
76107
handle = csv.DictReader(open(path, "r"),
@@ -124,6 +155,9 @@ def parse(path, source=None):
124155
try:
125156
handler = {"23andme": _23andme,
126157
"23andme-exome-vcf": _23andme_exome,
158+
"ancestry": _23andme_ancestry,
159+
"genes-for-good": _genes_for_good,
160+
"IYG": _iyg,
127161
"ftdna-illumina": ftdna,
128162
"decodeme": decodeme,
129163
"vcf": _23andme_exome,

0 commit comments

Comments
 (0)