Giter Club home page Giter Club logo

Comments (2)

tsvvas avatar tsvvas commented on July 19, 2024

Hi @spatts14 !

This is not a silly question in my opinion, as it is not evident from the tutorial. I am not a developer of the package, but I came up with a workaround.

from anndata import AnnData
from pandas import DataFrame

def get_tangram_predictions(adata: AnnData, perc=0, inplace=True) -> AnnData | DataFrame:
    tg_ct_pred = adata.obsm["tangram_ct_pred"]
    tg_ct_pred = tg_ct_pred.clip(
        tg_ct_pred.quantile(perc), tg_ct_pred.quantile(1 - perc), axis=1
    )
    tg_ct_pred = (tg_ct_pred - tg_ct_pred.min()) / (tg_ct_pred.max() - tg_ct_pred.min())

    df = DataFrame()
    df["tangram_prediction"] = tg_ct_pred.idxmax(axis=1)
    df["tangram_score"] = tg_ct_pred.apply(lambda x: max(x), axis=1)

    if inplace:
        adata.obs = adata.obs.join(df)
        return adata

    return df

This function is inspired by the construct_obs_plot function, which is hidden inside of the plot_cell_annotation_sc function, which plots the predicted annotations.

If you pass inplace=True, then the function will populate adata.obs with two new columns, called "tangram_prediction" and "tangram_score". Otherwise the function will return a dataframe with those columns.

Hope this helps,
Vasily

from tangram.

spatts14 avatar spatts14 commented on July 19, 2024

Thanks so much for your feedback! Sorry for the late response I somehow missed this. Really appreciate your detailed work around @tsvvas

from tangram.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.