Skip to content

Python API #24

@colganwi

Description

@colganwi

@gillichu @uym2 thanks for creating this fantastic tool! It would be helpful to have a python API so lightweight inference tasks can be easily run in a jupyter notebook. I suggest taking a pd.DataFrame/np.array character_matrix and optionally a nx.DiGraph topology as input and outputting a nxDiGraph since this will enable compatibility with TreeData.

character_matrix = pd.DataFrame(character_matrix)
tdata = td.TreeData(obs = cell_metadata, obms = {"characters":character_matrix})
# With TreeData
tdata.obst["tree"] = laml.run_laml(tdata.obsm["characters"],depth_key = "time")
# Without TreeData
tree = laml.run_laml(character_matrix,depth_key = "time")

The inferred branch lengths and characters for ancestral nodes can be represented as node attributes in the nx.DiGraph. I typically use tree.nodes["0"]["time"] to store node times and tree.nodes["0"]["characters"] to store characters. When LAML is used for branch length estimation you could also take an nx.DiGraph as input then return a copy with "time" and "characters" attributes added. The key where these values are stored (e.g. "time") could be modifies with a parameter such as depth_key.

Happy to go into more detail here if that would be helpful. The goal is to have a simple API that works with or without TreeData.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions