Skip to content

geno_lewm.deploy.import_.twentythreeandme

twentythreeandme

23andMe raw genotype importer.

parse_23andme

parse_23andme(path: str | Path) -> tuple[ArrayGenotypeCall, ...]

Parse common 23andMe raw-data rows into normalized genotype calls.

Source code in geno_lewm/deploy/import_/twentythreeandme.py
def parse_23andme(path: str | Path) -> tuple[ArrayGenotypeCall, ...]:
    """Parse common 23andMe raw-data rows into normalized genotype calls."""
    calls: list[ArrayGenotypeCall] = []
    for line_no, line in read_text_lines(path):
        fields = line.split()
        if _is_header(fields):
            continue
        if len(fields) != 4:
            raise VcfParseError(
                "23andMe row must contain rsid, chromosome, position, genotype",
                details={"line": line_no, "field_count": len(fields)},
            )
        rsid, chrom, pos, genotype = fields
        calls.append(
            ArrayGenotypeCall(
                provider=_PROVIDER,
                rsid=rsid,
                chrom=chrom,
                pos=parse_pos(pos, provider=_PROVIDER, line_no=line_no),
                genotype=genotype,
                line_no=line_no,
            )
        )
    return tuple(calls)

convert_23andme_to_vcf

convert_23andme_to_vcf(input_path: str | Path, output_path: str | Path, reference_alleles: ReferenceAlleles, *, sample_id: str = 'sample') -> VcfConversionSummary

Convert 23andMe raw genotype text to a local VCF file.

Source code in geno_lewm/deploy/import_/twentythreeandme.py
def convert_23andme_to_vcf(
    input_path: str | Path,
    output_path: str | Path,
    reference_alleles: ReferenceAlleles,
    *,
    sample_id: str = "sample",
) -> VcfConversionSummary:
    """Convert 23andMe raw genotype text to a local VCF file."""
    return convert_array_calls_to_vcf(
        parse_23andme(input_path),
        output_path,
        reference_alleles,
        sample_id=sample_id,
    )