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

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

Open
JobLeonard opened this issue Jan 5, 2018 · 0 comments

Comments

@JobLeonard
Copy link
Contributor

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?

  • close the file
  • move file to project subfolder (say, TestProject) in loom-datasets folder,
    • the existence of a loom-datasets folder is very easy to miss for new users
    • assuming people use Finder on the Mac or Explorer on Windows, it can be surprisingly hard to locate the home folder in which the loom-datasets folder is generated by default. And even after finding my home folder on Windows, I think locating the the loom-datasets folder takes a bit of hunting:
      image
    • connecting to the loom file again later requires remembering the full path to the new location (on Windows, ~/ is not automatically expanded to the home folder)
  • metadata and attributes can currently be viewed without expansion
  • to see the genes, we'd need to expand it via the CLI (will have an interface through the website soon)
  • to see the tiles, they would have to be generated through the CLI too (same promise of web-interface).

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:

  • finding the dataset folder,
    • falling back to the (and when necessary creating a) default folder in the user's home folder
  • listing the whole dataset folder
  • listing the projects in the selected dataset folder,
  • listing the files in a project
  • finding all files matching a name
  • expanding all files/all files in a project/all files matching a name
  • starting the server from the default dataset folder
  • distinguishing between relative and absolute paths

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.

  • loom_viewer.dataset_path(), which return a string representing the expanded full path of ~/loom-datasets/ (or whatever the LOOM_PATH is set to, assuming we still support that)

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant