ENPICOM Logo API Docs Python SDK Docs Events

enpi_api.examples.apps.phylogeny

Phylogeny

Phylogeny prioritizes clusters based on size and content. For clusters of interest, interactive tree visualizations are generated that link visual variables such as color, shape, and size to available assay data, providing a versatile system to pick candidates for follow-up analysis.

Example Phylogeny run configuration

Showcases show to start a phylogenetic tree computation with Phylogeny.

from enpi_api.l2.client.enpi_api_client import EnpiApiClient
from enpi_api.l2.types.cluster import ClusterId, ClusterRunId

with EnpiApiClient() as enpi_client:
    """We are assuming that the Clustering run referenced below ran successfully"""

    cluster_run_id = ClusterRunId("590a42b4-16e5-408c-9457-9b1dd64b6bdb")
    cluster_id = ClusterId(1)

    trees = enpi_client.phylogeny_api.start(
        cluster_run_id=cluster_run_id,  # Unique identifier of a Clustering run
        cluster_id=cluster_id,  # ID of one of the clusters, which are results of Clustering run.
        # This ID is unique only within the scope of a single Clustering run (e.g.
        # multiple Clustering run results can have a cluster with ID = 1 )
    ).wait()

    print(trees)

Get trees computed for a cluster

Showcases how get info on trees computed for a given cluster.

from enpi_api.l2.client.enpi_api_client import EnpiApiClient
from enpi_api.l2.types.workflow import WorkflowExecutionTaskId

with EnpiApiClient() as enpi_client:
    """We are assuming that the Clustering run referenced below ran successfully and
    a phylogenetic tree was computed for it"""

    task_id = WorkflowExecutionTaskId(123)

    trees = enpi_client.phylogeny_api.get_phylogeny_by_task_id(
        task_id=task_id,  # ID of the phylogenetic tree task
    )

    print(trees)

Export tree as a TSV

Showcases how to export a successfully computed phylogenetic tree into a TSV file.

from enpi_api.l2.client.enpi_api_client import EnpiApiClient
from enpi_api.l2.types.cluster import ClusterId, ClusterRunId

with EnpiApiClient() as enpi_client:
    """A phylogenetic tree has to be computed first before being exported, then it can either
    be directly passed to export or can be fetched with `enpi_client.phylogeny_api.get_trees`"""

    trees = enpi_client.phylogeny_api.start(
        cluster_run_id=ClusterRunId("590a42b4-16e5-408c-9457-9b1dd64b6bdb"),
        cluster_id=ClusterId(1),
    ).wait()

    # Only one phylogenetic tree can be exported at a time
    assert len(trees) > 0, """At least one valid phylogenetic tree is required to continue.
    Please check your input data and the phylogenetic tree run configuration."""
    phylogeny = trees[0]

    # Export phylogenetic tree into a TSV file
    path = enpi_client.phylogeny_api.export_phylogeny_as_tsv(
        phylogeny=phylogeny,  # Phylogenetic tree to export
        output_directory="/home/example_user/",  # Directory in which the file will be stored
    ).wait()

    print(path)

    """
    A variant of this export that returns a DataFrame is also available:

    df = enpi_client.phylogeny_api.export_phylogeny_as_df(
        phylogeny=phylogeny,  # Phylogenetic tree to export
    )

    print(df)
    """
 1'''
 2# Phylogeny
 3
 4Phylogeny prioritizes clusters based on size and content. For clusters of interest, interactive tree visualizations are generated
 5that link visual variables such as color, shape, and size to available assay data, providing a versatile system to pick candidates for follow-up analysis.
 6
 7
 8##Example Phylogeny run configuration
 9
10Showcases show to start a phylogenetic tree computation with Phylogeny.
11
12```python
13from enpi_api.l2.client.enpi_api_client import EnpiApiClient
14from enpi_api.l2.types.cluster import ClusterId, ClusterRunId
15
16with EnpiApiClient() as enpi_client:
17    """We are assuming that the Clustering run referenced below ran successfully"""
18
19    cluster_run_id = ClusterRunId("590a42b4-16e5-408c-9457-9b1dd64b6bdb")
20    cluster_id = ClusterId(1)
21
22    trees = enpi_client.phylogeny_api.start(
23        cluster_run_id=cluster_run_id,  # Unique identifier of a Clustering run
24        cluster_id=cluster_id,  # ID of one of the clusters, which are results of Clustering run.
25        # This ID is unique only within the scope of a single Clustering run (e.g.
26        # multiple Clustering run results can have a cluster with ID = 1 )
27    ).wait()
28
29    print(trees)
30
31```
32##Get trees computed for a cluster
33
34Showcases how get info on trees computed for a given cluster.
35
36```python
37from enpi_api.l2.client.enpi_api_client import EnpiApiClient
38from enpi_api.l2.types.workflow import WorkflowExecutionTaskId
39
40with EnpiApiClient() as enpi_client:
41    """We are assuming that the Clustering run referenced below ran successfully and
42    a phylogenetic tree was computed for it"""
43
44    task_id = WorkflowExecutionTaskId(123)
45
46    trees = enpi_client.phylogeny_api.get_phylogeny_by_task_id(
47        task_id=task_id,  # ID of the phylogenetic tree task
48    )
49
50    print(trees)
51
52```
53##Export tree as a TSV
54
55Showcases how to export a successfully computed phylogenetic tree into a TSV file.
56
57```python
58from enpi_api.l2.client.enpi_api_client import EnpiApiClient
59from enpi_api.l2.types.cluster import ClusterId, ClusterRunId
60
61with EnpiApiClient() as enpi_client:
62    """A phylogenetic tree has to be computed first before being exported, then it can either
63    be directly passed to export or can be fetched with `enpi_client.phylogeny_api.get_trees`"""
64
65    trees = enpi_client.phylogeny_api.start(
66        cluster_run_id=ClusterRunId("590a42b4-16e5-408c-9457-9b1dd64b6bdb"),
67        cluster_id=ClusterId(1),
68    ).wait()
69
70    # Only one phylogenetic tree can be exported at a time
71    assert len(trees) > 0, """At least one valid phylogenetic tree is required to continue.
72    Please check your input data and the phylogenetic tree run configuration."""
73    phylogeny = trees[0]
74
75    # Export phylogenetic tree into a TSV file
76    path = enpi_client.phylogeny_api.export_phylogeny_as_tsv(
77        phylogeny=phylogeny,  # Phylogenetic tree to export
78        output_directory="/home/example_user/",  # Directory in which the file will be stored
79    ).wait()
80
81    print(path)
82
83    """
84    A variant of this export that returns a DataFrame is also available:
85
86    df = enpi_client.phylogeny_api.export_phylogeny_as_df(
87        phylogeny=phylogeny,  # Phylogenetic tree to export
88    )
89
90    print(df)
91    """
92
93```
94'''