linnarsson-lab / loom-viewer

Tool for sharing, browsing and visualizing single-cell data stored in the Loom file format
BSD 2-Clause "Simplified" License
35 stars 6 forks source link

Helper functions for listing/creating/opening loom files in the loom-datasets folder #143

Open JobLeonard opened 6 years ago

JobLeonard commented 6 years ago

Take the following example from the loompy API walkthrough:

import numpy as np
import loompy
filename = "test.loom"
matrix = np.arange(10000).reshape(100,100)
row_attrs = { "SomeRowAttr": np.arange(100) }
col_attrs = { "SomeColAttr": np.arange(100) }
loompy.create(filename, matrix, row_attrs, col_attrs)

Assuming this was run from a Jupyter notebook, this would create test.loom in the same folder as the notebook.

Let's say that we now want to open this test file in the loom viewer. What needs to be done?

In other words, setting up loom files for viewing requires quite a bit of tiny steps.

The last two points are currently done via the CLI, and I'm working on a web-based option for it.

However, when using the loompy library in (for example) a Jupyter notebook or the Python REPL, each of these points could be simplified via helper functions, which shouldn't take too much hassle to write. After all, the logic for the following already present in the loom-viewer CLI code:

Refactoring this code into functions that can be imported and used from within other Python code could make it a bit easier to integrate using the loom-viewer with loompy (especially for new users).

I can think of a one more that could make life a bit simpler.

This would make the above example easy to integrate with loom-viewer, without adding a lot of syntax, and also keeping the distinction between loompy and loom-viewer conventions:

import numpy as np
import loompy
from loom_viewer import dataset_path`
project = "Test Project/"
filename = "test.loom"
matrix = np.arange(10000).reshape(100,100)
row_attrs = { "SomeRowAttr": np.arange(100) }
col_attrs = { "SomeColAttr": np.arange(100) }
loompy.create(dataset_path() + project + filename, matrix, row_attrs, col_attrs)