Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewConfig.use_coordination with multiple coordinations of same type #271

Closed
NickAkhmetov opened this issue Aug 8, 2023 · 0 comments · Fixed by #274
Closed

ViewConfig.use_coordination with multiple coordinations of same type #271

NickAkhmetov opened this issue Aug 8, 2023 · 0 comments · Fixed by #274

Comments

@NickAkhmetov
Copy link
Collaborator

Configs generated by vitessce-python 1.0.9 (view conf version 1.0.7) then upgraded to 1.0.16 have obsLabelsType coordination spaces with more than one value when upgraded, each of which is included in the coordination scopes of views, e.g.:

Original 1.0.7 config, unabridged

{
  "coordinationSpace": {
    "dataset": { "A": "A" },
    "embeddingType": { "A": "UMAP" }
  },
  "datasets": [
    {
      "files": [
        {
          "fileType": "anndata-cells.zarr",
          "options": {
            "factors": [
              "obs/marker_gene_0",
              "obs/marker_gene_1",
              "obs/marker_gene_2",
              "obs/marker_gene_3",
              "obs/marker_gene_4"
            ],
            "mappings": { "UMAP": { "dims": [0, 1], "key": "obsm/X_umap" } }
          },
          "type": "cells",
          "url": "https://assets.hubmapconsortium.org/2dac500177620d78ca174c2c1d36a6c8/hubmap_ui/anndata-zarr/secondary_analysis.zarr"
        },
        {
          "fileType": "anndata-cell-sets.zarr",
          "options": [
            {
              "groupName": "Cell Ontology Annotation",
              "setName": "obs/predicted_label"
            },
            { "groupName": "Leiden", "setName": "obs/leiden" }
          ],
          "type": "cell-sets",
          "url": "https://assets.hubmapconsortium.org/2dac500177620d78ca174c2c1d36a6c8/hubmap_ui/anndata-zarr/secondary_analysis.zarr"
        },
        {
          "fileType": "anndata-expression-matrix.zarr",
          "options": {
            "geneAlias": "var/hugo_symbol",
            "matrix": "X",
            "matrixGeneFilter": "var/marker_genes_for_heatmap"
          },
          "type": "expression-matrix",
          "url": "https://assets.hubmapconsortium.org/2dac500177620d78ca174c2c1d36a6c8/hubmap_ui/anndata-zarr/secondary_analysis.zarr"
        }
      ],
      "name": "2dac500177620d78ca174c2c1d36a6c8",
      "uid": "A"
    }
  ],
  "description": "",
  "initStrategy": "auto",
  "layout": [
    {
      "component": "scatterplot",
      "coordinationScopes": { "dataset": "A", "embeddingType": "A" },
      "h": 6,
      "w": 6,
      "x": 0,
      "y": 0
    },
    {
      "component": "cellSets",
      "coordinationScopes": { "dataset": "A" },
      "h": 3,
      "w": 6,
      "x": 6,
      "y": 0
    },
    {
      "component": "genes",
      "coordinationScopes": { "dataset": "A" },
      "h": 3,
      "w": 6,
      "x": 6,
      "y": 4
    },
    {
      "component": "cellSetExpression",
      "coordinationScopes": { "dataset": "A" },
      "h": 4,
      "w": 5,
      "x": 7,
      "y": 6
    },
    {
      "component": "heatmap",
      "coordinationScopes": { "dataset": "A" },
      "h": 4,
      "w": 7,
      "x": 0,
      "y": 6
    }
  ],
  "name": "2dac500177620d78ca174c2c1d36a6c8",
  "version": "1.0.7"
}

Excerpt from 1.0.16 config with multiple `obsLabelsType` values in the `coordinationScopes` of views

"coordinationSpace": {
    "dataset": {
      "A": "A"
    },
    "embeddingType": {
      "A": "UMAP"
    },
    "obsLabelsType": {
      "A": "marker_gene_0",
      "B": "marker_gene_1",
      "C": "marker_gene_2",
      "D": "marker_gene_3",
      "E": "marker_gene_4"
    }
  },
  "layout": [
    {
      "component": "scatterplot",
      "x": 0,
      "y": 0,
      "w": 6,
      "h": 6,
      "coordinationScopes": {
        "dataset": "A",
        "embeddingType": "A",
        "obsLabelsType": [
          "A",
          "B",
          "C",
          "D",
          "E"
        ]
      }
    },
    {
      "component": "obsSets",
      "x": 6,
      "y": 0,
      "w": 6,
      "h": 3,
      "coordinationScopes": {
        "dataset": "A",
        "obsLabelsType": [
          "A",
          "B",
          "C",
          "D",
          "E"
        ]
      }
    },
    {
      "component": "featureList",
      "x": 6,
      "y": 4,
      "w": 6,
      "h": 3,
      "coordinationScopes": {
        "dataset": "A",
        "obsLabelsType": [
          "A",
          "B",
          "C",
          "D",
          "E"
        ]
      }
    },
    {
      "component": "obsSetFeatureValueDistribution",
      "x": 7,
      "y": 6,
      "w": 5,
      "h": 4,
      "coordinationScopes": {
        "dataset": "A",
        "obsLabelsType": [
          "A",
          "B",
          "C",
          "D",
          "E"
        ]
      }
    },
    {
      "component": "heatmap",
      "x": 0,
      "y": 6,
      "w": 7,
      "h": 4,
      "coordinationScopes": {
        "dataset": "A",
        "obsLabelsType": [
          "A",
          "B",
          "C",
          "D",
          "E"
        ]
      }
    }
  ],

Creating this coordination in the new version of vitessce-python is trickier. The use_coordination function replaces any current scopes with the new passed value, so passing it five instances of coordinations with the same type makes it update the coordinationScopes.obsLabelsType to A, then B, then C, then D, then finally E.

In order to achieve something close to the desired result (i.e. set multiple scopes for the same coordination type), I had to create a custom VitessceConfigCoordinationScope with the desired list set to the c_scope value:

from vitessce.config import VitessceConfigCoordinationScope

OBS_LABELS = 'obsLabelsType'
factors = [
    "marker_gene_0",
    "marker_gene_1",
    "marker_gene_2",
    "marker_gene_3",
    "marker_gene_4"
]

label_coordinations = vc.add_coordination(*[OBS_LABELS for _ in factors])

for i, factor in enumerate(factors):
    label_coordinations[i].set_value(factor)

scopes = [str(l.c_scope) for l in label_coordinations]

customScope = VitessceConfigCoordinationScope(
    c_type=OBS_LABELS, c_scope=scopes)

for v in views:
    v.use_coordination(customScope)

My suggested enhancement to make this more straightforward would be to add an allow_multiple_scopes_per_type arg (or similar) to allow the link_views and use_coordination components to link the view to all passed scopes of the same type at once; i.e. when this flag is true, the behavior of use_coordination should be adjusted to convert the coordinationScopes value to an array and append to it if there's a value already present, rather than replacing the existing value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant