Skip to content

Where should sc.datasets put data? #558

Closed

Description

@ivirshup

I'm adding that expression atlas downloader now (#489), and wondering where the files should go.

pbmc68k_reduced and toggleswitch put the datasets relative to where scanpy is installed (via __file__). All other functions place the data relative to where the python process was started.

While I like not storing the same files all over a filesystem, I'm not sure in the scanpy installation directory is the right place to be storing data.

Thoughts?

Activity

  1. flying-sheep commented on Mar 26, 2019

    @flying-sheep
    Member

    The scanpy install directory is super wrong, as it’s not writable for many people.

    There’s exactly one correct way of determining a global place for cache* files like this: appdirs.user_cache_dir(...)

    Alex and me talked in the past and decided for a visible directory in the working directory. I’d be up for changing it to user_cache_dir(…) for the data.

    *the data are cache files since reexccuting their function after deleting the files will redownload them without loss of information.

  2. maximilianh commented on Mar 26, 2019

    @maximilianh
    Contributor
  3. ivirshup commented on Mar 26, 2019

    @ivirshup
    MemberAuthor

    @flying-sheep That does look useful, though I definitely see a lot of toolkits using something like ~/.{toolkitname} on my mac. Personally, I'd look under my home directory first.

    I think if things are going to move, there should be a sensible default, but the location should be user configurable (probably through an environment variable). For example, the main hpc I'm on only gives me about 1gb of space where appdirs would put these files.

    @maximilianh Currently I don't get coordinates along with some other computed values like SC3 clustering. I also believe it's only a subset of the metadata. I think there's more through the array express api, but that was more of a pain to navigate.

    Was there anything in particular you wanted to see included?

  4. maximilianh commented on Mar 26, 2019

    @maximilianh
    Contributor
  5. flying-sheep commented on Mar 26, 2019

    @flying-sheep
    Member

    though I definitely see a lot of toolkits using something like ~/.{toolkitname} on my mac.

    There’s two possible reasons: 1.: We’re talking about something from the 80’s like SSH or BASH. They earned their right to things their way because they’re older than the standards they’re not following. Or 2.: Whoever designed this didn’t do their research and just hacked in first thing that came to mind. This is not an excuse.

    MacOS knows about ~/Library/Caches and to clean it out when disk space gets scarce. The same applies to Linux’ and Windows’ respective canonical cache directories. Each OS has that place specifically to place things like those datasets there.

    For example, the main hpc I'm on only gives me about 1gb of space where appdirs would put these files.

    Ouch. Seems like it’s time to file a bug report.

  6. falexwolf commented on Mar 26, 2019

    @falexwolf
    Member

    Hey! 😄

    I'd in principle happy if we move the default scanpy.settings.cachedir from ./cache/ to appdirs.user_cache_dir().

    However, if then any Scanpy installation breaks, as the main hpc I'm on 1gb of space where appdirs would put these files, I would probably not make this the default, but choose something like ~/cache-scanpy/, that is, a visible directory in home (if we really want, ~/.scanpy/ is also fine). Under https://scanpy.readthedocs.io/en/latest/api/index.html#settings, we could also talk about other alternatives.

    I second Isaac's concern. Like many others, I'm computing on AWS these days and there, the canonical way of making data locally accessible is via EBS volumes. Hence, I'm used to setting the cachedir to that mount point with a visible name, knowing that this can hold a lot of data. I'd manually clean it if something that I don't use often takes too much space.

    So, I fear that appdirs.user_cache_dir() is not smart enough to figure out locations on a Linux system that hold the size of data that we're typically talking about. It would for sure be the right solution for laptops and work stations etc.

  7. falexwolf commented on Mar 26, 2019

    @falexwolf
    Member

    PS: pbmc68k_reduced and toggleswitch are from back in the days; they should remain the only examples that actually have the data in the repository and the PyPI distributions. All other datasets should download their data from some stable URL...

  8. ivirshup commented on Mar 26, 2019

    @ivirshup
    MemberAuthor

    @maximilianh Sure! This gist has a script to download a dataset and write it to a .h5ad file. I think having scanpy and tqdm installed should be sufficient to run it. Usage should be:

     python3 download_expression_atlas.py {accession}
    

    where accession is something like: E-EHCA-2 or E-GEOD-98816.

    But what it does is just download and parse the expression .zip and "Experiment design file" from each dataset's download page (example). I think the experiment design files are a cleaned up version of the .sdrf file (some redundant fields are removed, field names can be less verbose).

  9. ivirshup commented on Mar 26, 2019

    @ivirshup
    MemberAuthor

    I think @falexwolf voiced my thoughts much more eloquently. A non-hidden directory in the root folder makes a sensible default to me. Would anyone be against also having some environmental variables/ a scanpy config (I’m thinking .cfg or .json) so this (and things like verbosity) don’t have to be set manually each session?

  10. maximilianh commented on Mar 26, 2019

    @maximilianh
    Contributor
  11. flying-sheep commented on Mar 26, 2019

    @flying-sheep
    Member

    the main hpc I'm on 1gb of space where appdirs would put these files

    That's a misconfigured server, not a normal case. We should use appdirs as default, catch a IOError on write, and send a nice message like

    Error: Cannot write to your cache directory. Please make sure there's space in {cache_dir!r} or override the cache directory by setting one of the $SCANPY_CACHE_DIR or $XDG_CACHE_DIR environment variables.

    All linux-based systems should set $XDG_CACHE_DIR if there's a better place than ~/.cache for such files.

  12. maximilianh commented on Mar 26, 2019

    @maximilianh
    Contributor
  13. flying-sheep commented on Mar 26, 2019

    @flying-sheep
    Member

    Sure, and I'm not against supporting special cases! Could you please explain the setup?

    Do you have a user home? Is there a canonical cache directory outside of the user home? Is there a way to detect that we are on such a system or a environment variable pointing to the canonical cache directory?

    Some systems are strange. We should be nice and support those systems while still doing the correct thing by default. We shouldn't do the wrong thing by default to accommodate strange cases.

  14. gokceneraslan commented on Mar 26, 2019

    @gokceneraslan
    Contributor

    @flyingsheep I can assure you, that's the normal case in academic HPC systems.

    I agree that this is a huge and common problem in many HPC systems. I usually install conda and R packages to non-home directories with bigger space to avoid issues on servers. One can fill up hundreds of MB by just installing a single package e.g. human genome from Bioconductor 😄

    Do you have a user home? Is there a canonical cache directory outside of the user home? Is there a way to detect that we are on such a system or a environment variable pointing to the canonical cache directory?

    There is a user home and the cache is ~/.cache and $XDG_CACHE_HOME is undefined (at least in my case). Some pip wheel files are there for example.

    Although it's painful to work in such systems, I believe it's user's responsibility to fix this. One idea might be to print a warning when the cache directory is created for the first time along with the path itself to inform the user about where files are.

  15. ivirshup commented on Mar 27, 2019

    @ivirshup
    MemberAuthor

    @gokceneraslan Totally agree it's the user's responsibility. I would say that it's the devs responsibility to make it as easy as possible for the user. How about printing the absolute path of the data's destination on download?

    @flying-sheep Would there necessarily be an error if space ran out? I could probably fit a few datasets in 2gb. From your previous depiction, I thought the older ones would just be deleted, right? If you had space for a couple datasets, wouldn't it be likely that installing a couple things with pip would clear these datasets on a system like we're describing? I'm not sure I find this behavior intuitive for this use case.

    Also here's the docs for my HPCs filesystem. I don't have an XDG_CACHE_HOME variable set when I log in.

    I'm also not sure scanpy fits the app model. When I look in my ~/Library/Caches/ I see things like Illustrator, VSCode, and Slack. When I think about example datasets that are available through scientific computing packages I think of:

    • scikit-learn – ~/scikit_learn_data
    • seaborn – ~/seaborn-data
    • NLTK – ~/nltk_data
    • keras and tensorflow – ~/.keras/datasets
    • conda – ~/miniconda3/
    • intake – ~/.intake/cache/ (specifically for caching feature)
    • CRAN and bioconductor data packages – same place as packages I think
  16. flying-sheep commented on Mar 27, 2019

    @flying-sheep
    Member

    Some pip wheel files are there for example.

    And scipy is also some 100 MB right?

    Totally agree it's the user's responsibility. I would say that it's the devs responsibility to make it as easy as possible for the user.

    That's exactly my stance as well.

    How about printing the absolute path of the data's destination on download?

    I thought that too. Only we should do it not just on download, but on every use, e.g. “reading cached data from ~/.cache/scanpy/paul15.h5ad”

    And put help on how to change the cache dir in the settings docs

    I thought the older ones would just be deleted, right?

    Since those systems aren't configured well, probably not. On those systems, it would just be another directory. But on a laptop with a common Linux distribution, there would be a pop-up once your disk space gets low, which allows you to clear that directory with a click.

    If you had space for a couple datasets, wouldn't it be likely that installing a couple things with pip would clear these datasets on a system like we're describing? I'm not sure I find this behavior intuitive for this use case.

    You'd not notice it much, because datasets are just being re-downloaded on demand. That's a feature!

    [We don't have XDG_CACHE_HOME set]

    Yes, because you only need it if you want your cache files to not be in ~/.cache

    When I think about example datasets that are available through scientific computing packages I think of […]

    I'm on mobile, so I don't want to check all of those, but

    • miniconda is somewhere else for me by default, and it contains everything, not just data
    • nltk pops up a window asking you to where to put stuff, and recommends /use/local/share/nltk_data for global installs, with no recommendation for per-user installs.

    I have a lot more stuff in my cache dir, not just applications.

    And as said: for good reason, because the OS often knows about this, which helps the user to delete the stuff with one click if needed.


    My personal hell certainly includes dozens of libraries and applications putting all kinds of crap in unhidden directories in my home. All of them have a different way to configure that location or none at all. Chills me right to the core.

  17. flying-sheep commented on Mar 27, 2019

    @flying-sheep
    Member

    I'm thinking.

    My favorite command line interfaces have the ability to query options and set options globally by writing to a config file (jupyter, npm, git, …)

    Maybe we should give scanpy that ability. People could use that if they use scanpy mainly through scripts.

    $ scanpy settings
    Config file: ~/.config/scanpy/scanpy.toml
    cachedir='~/.cache/scanpy' (default)
    ...
    $ scanpy settings cachedir '/my/path'
    Set cachedir to '/my/path' in ~/.config/scanpy/scanpy.toml
    $ scanpy settings cachedir
    /my/path

    And of course we also have a python API for this. People who use scanpy mainly interactively can use that one.

  18. flying-sheep commented on Mar 27, 2019

    @flying-sheep
    Member

    So the user experience will be:

    1. They’ll go through the example notebooks where they’ll learn how to download data

      → The notebooks should mention where to configure the cache directory

    2. They’ll download data, probably not paying attention to the output immediately

      → We should mention where the data are every time they get loaded (Either from the web or from the cache dir. Maybe even mention that the location can be configured in settings?)

    3. Maybe they’ll eventually look at the settings module in the online documentation

      → We should explain there that the default uses appdirs, and what directories that maps to on different OSs

    4. A user in some misconfigured HPC environment who manages to not see any of the warnings will end up filling heir home directory by downloading data to the default directory (Is that possible or will there be no error?)

      → We should mention that the directoy can be globally configured for all libraries and applications using XDG_CACHE_HOME, and for scanpy using scanpy settings cachedir .... or scanpy.settings.cachedir = ....

  19. ivirshup commented on Mar 30, 2019

    @ivirshup
    MemberAuthor

    And scipy is also some 100 MB right?

    Scipy is actually under ~/.cache on my mac, ¯\_(ツ)_/¯

    Only we should do it not just on download, but on every use, e.g. “reading cached data from ~/.cache/scanpy/paul15.h5ad”

    I think I'd prefer printing on write, info logging on read. I'd put a higher precedence on changing stuff on disk rather than reading.

    miniconda is somewhere else for me by default, and it contains everything

    I like this model of having all the data in one place, makes it much easier to have multiple environments and uninstall things.

    You'd not notice it much, because datasets are just being re-downloaded on demand

    So the compute nodes on this HPC have limited internet connectivity. One of the use cases I'd had for adding the expression atlas was to be able to easily try a method across a bunch of test datasets. If those datasets were being implicitly cleared from disk, I'd find that confusing. I guess I don't think of downloaded datasets being cached in the way you've defined before. If I've downloaded a dataset though sklearn or tensorflow , I expect it to stay on disk.

    My favorite command line interfaces have the ability to query options and set options globally by writing to a config file

    I'm not sure I'd want to support a command line interface just for configs, if there was more it could do, maybe. Also, there's gotta be a generic tool for this, right?

  20. ivirshup commented on Mar 30, 2019

    @ivirshup
    MemberAuthor

    I've punted on this issue for getting the expression atlas downloader added. I think it'd be worth changing the default data directory at the same time as dealing with configuration more generally, so related breaking changes can happen together.

    I was writing up how I'd like configuration to work when I realized the implementation could be getting complicated enough it might be worth just using a library. Everett seems nice, but maybe a little immature. I like the ability to use context managers (making testing easier) and the auto documentation features.

    Generally, I think there should be a longer planning discussion about how configuration works. But that could be multiple issues. For example:

    • Could we not change global state for plotting? We could shift over to using the pyplot.rc_context manager internally.
    • What's the appropriate way to set logging level? It seems to keep changing and breaking things
    • What's the appropriate precedence for config setting? I'd think set in session > environment variable > config file > defaults.
  21. ivirshup commented on Mar 30, 2019

    @ivirshup
    MemberAuthor

    @flying-sheep that user experience seems pretty reasonable. I'm wondering if we couldn't cut down on the need to explain by adopting a convention of referencing relevant settings in any function that access them? For example, the docs for expression_atlas would have a reference to dataset_dir?

    Also on point 4, I've definitely had conda exit with helpful errors when I ran out of space.

  22. flying-sheep commented on Mar 30, 2019

    @flying-sheep
    Member

    Scipy is actually under ~/.cache on my mac, ¯\(ツ)/¯

    Sorry, I was too terse here: What I meant is that a wheel cached by pip (such as scipy) ends up in ~/.cache. And since some of those wheels are big, you need to clean that directory from time to time anyway if you have little space.

    I think I'd prefer printing on write, info logging on read. I'd put a higher precedence on changing stuff on disk rather than reading.

    My idea was that showing it every time would help people discover this. But the default scanpy log level is INFO anyway, right? So it would get shown by default if we info-log it?

    I like this model of having all the data in one place, makes it much easier to have multiple environments and uninstall things.

    Me too: All cache data in ~/.cache, all configs in ~/.config, …

    If you need to uninstall a thing that behaves correctly, you can just do package-manager uninstall thing && rm -rf ~/.{cache,config,local/share}/thing/

    If those datasets were being implicitly cleared from disk, I'd find that confusing. I guess I don't think of downloaded datasets being cached in the way you've defined before. If I've downloaded a dataset though sklearn or tensorflow , I expect it to stay on disk.

    As said: it doesn’t happen automatically on desktops, they show you a popup asking you to do it.

    I think the HPC servers don’t help you with your tiny $HOME, so everything you download manually or cache just stays there.

    On a well-configured system with little space in $HOME, you’d have $XDG_CACHE_DIR point to a separate disk that has more space and isn’t backupped. In an ideal world everyone would respect that and your $HOME would never be filled up with ephemeral files.

    I'm not sure I'd want to support a command line interface just for configs, if there was more it could do, maybe. Also, there's gotta be a generic tool for this, right?

    The idea we agreed on was to allow something similar as jupyter: Just delegate scanpy foocmd to scanpy-foocmd except for 1-3 built-in commands. Other people are interested in creating those scripts (and did so already, but for the time being just call scanpy-mycommand with a dash in there)

    I was writing up how I'd like configuration to work when I realized the implementation could be getting complicated enough it might be worth just using a library. […] Generally, I think there should be a longer planning discussion about how configuration works.

    Agreed, probably in an extra issue.

    I'm wondering if we couldn't cut down on the need to explain by adopting a convention of referencing relevant settings in any function that access them? For example, the docs for expression_atlas would have a reference to dataset_dir?

    sounds great!

  23. falexwolf commented on Mar 31, 2019

    @falexwolf
    Member

    These and similar discussions tend to get very long and complicated! 🙂

    So, excuse if I'm not addressing everything; it's probably even not on purpose. I wrote my response here (#573) so that it directly includes the use case of the expression atlas.

    I'm closing this issue. We can follow up on PR-related things in the PR. And on all other topics in issues dedicated to these topics.

  24. flying-sheep commented on Apr 1, 2019

    @flying-sheep
    Member

    So either we now continue the discussion in that completely unrelated PR or just accept whatever @ivirshup favors at the moment without discussion. This is the issue for exactly that discussion, and before we agree on something, #573 can’t change how things work.

  25. ivirshup commented on Apr 1, 2019

    @ivirshup
    MemberAuthor

    I totally agree that there are unresolved discussions here. I also think this issue has multiple conversations in it now, and it's probably a good idea to split it up.

    I think it's totally fine to not change the current behavior for now. I'd just note the initial PR didn't change where datasets are placed, and that change was in response to review. My intent was not to disregard this conversation, I had just assumed you and Alex had talked in a separate forum.

    Sorry about any confusion caused!

  26. flying-sheep commented on Apr 1, 2019

    @flying-sheep
    Member

    All good, thank you for your work!

  27. added a commit that references this issue on Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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