Interactive demo | genome1/11-dbSNP

Intro

Looks up a specific SNP. If not found, then provide a few suggestions.
If found exact match, then list out all the gene info like in the last notebook.
Run
Server offline
Idle

Parameters

Result

(none yet)

Sample api request

Source code

def endpoint(query:str="rs142") -> serve.html():
    """Looks up a specific SNP. If not found, then provide a few suggestions.
If found exact match, then list out all the gene info like in the last notebook."""
    res = None | applyCl.aS(lambda: ls(f"{base}/00-common_all.idx")) | ungroup(single=True, begin=True) | applyCl(cat(text=False) | aS(dill.loads) | op().items() | filt(op().startswith(query), 0) | randomize(None) | head(100) | deref(), pre=True) | cut(1) | joinStreams() | deref()
    targets = res | filt(op() == query, 0) | deref()
    if targets | shape(0): # grab detailed info about this SNP
        snp, chrPos = targets[0]
        chr_, pos = chrPos.split("-") | toInt()
        genesAtPos = cat("~/ssd2/repos/labs/mlexps/genome/10-gencode/chr2NamePos.pth", False) | aS(dill.loads) | op()[f"chr{chr_}"] | filt(~aS(lambda name,s,e: s <= pos <= e)) | cut(0) | deref()
        summary = f"""SNP {snp} found in chromosome {chr_} at {pos}. Genes nearby: {genesAtPos | join(', ')}""" | aS(fmt.pre)
        return [summary, *genesAtPos | apply(lambda gene: (gene | aS(fmt.h, level=3)) + lookupGene(gene))] | aS(fmt.col)
    else: # return plotly scatter plot
        return res | ~apply(lambda x,y: [x,*y.split("-")]) | toInt(1, 2) | deref() | aS(pd.DataFrame, columns=[*"zxy"]) | aS(px.scatter, x="x", y="y", labels={"x": "Chromosome", "y": "Position (bp)"}, hover_name="z") | toHtml()