Skip to content

Expression atlas - #573

Merged
falexwolf merged 17 commits into
scverse:masterfrom
ivirshup:expression_atlas
Apr 4, 2019
Merged

falexwolf merged 17 commits into
scverse:masterfrom
ivirshup:expression_atlas

Conversation

@ivirshup

@ivirshup ivirshup commented Mar 30, 2019 •

Copy link
Copy Markdown
Member

Adding an expression atlas downloader to sc.datasets (proposed in #489).

I've punted on replacing where datasets are downloaded by just making it a variable in settings, since it seems contentious where datasets should be downloaded by default #558.

@flying-sheep when I build the docs locally, the link to the expression atlas doesn't format properly on the main API page, but does on it's own page. Any ideas on if we can get that to work?

@ivirshup

Copy link
Copy Markdown
Member Author

Changing to WIP since I'd like to improve failure handling before this gets merged.

@ivirshup ivirshup changed the title Expression atlas [WIP] Expression atlas Mar 30, 2019
@ivirshup

Copy link
Copy Markdown
Member Author

That should do it. Ready for review

@ivirshup ivirshup changed the title [WIP] Expression atlas Expression atlas Mar 30, 2019

download_experiment(accession)

print("Downloaded {} to {}".format(accession, experiment_dir.absolute()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, the default logging level is warning, not info.

It's strange to use logg.warn as we don't want to print WARNING, so, I guess, simply using print is fine... (it won't appear in a logging file, but no one is using this functionality anyway, so we can drop it...)

Can you add a comment on that one can change settings.datasetsdir?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd gone with printing for downloading since I believe the progress bars go to stdout anyways, so it's not adding noise to a previously silent operation.

Also, I had been thinking about trying to make logging a bit more consistent and easy to implement (#472), and might pick that up once I've got bandwidth.

Should the comment about settings.datasetdir go into the function docs or the printed message?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about the printed message...

Making logging more consistent would be terrific. :D

@falexwolf

Copy link
Copy Markdown
Member

Isaac,

this is great, thank you so much!

Regarding the default for the dataset directory. I like this solution!

Very small edits in addition to what I commented in the code:

Notes:

  • By having a datasets dir, which is separate from the cache dir (which make sense), I guess, we can also use user_cache_dir(…) as the default for the cache dir (which would hopefully choose something in ~/.cache on a Linux system, probably via ~/.cache/scanpy/, I think this what you, also Phil (!) and Gökcen favored if I'm correctly summarizing the long thread?
  • We already had a Scanpy config in the beginning (was an .ini) and we can reintroduce it in the future, and it should probably go into ~/.config/scanpy.ini (or .json or .yaml). No reason not to have it. No need to have a CLI for this purpose.
  • We can replace .settings with an instance of a class ._settings.Settings. By that, attributes get auto-documented, we can do nice checks on setting attributes via properties, and we can also directly write to a ~/.config/scanpy.ini file...
  • pyplot.rc_context sounds awesome.
  • Precedence for settings is correct as stated in Where should sc.datasets put data? #558 (comment), this is also how I had it before removing the config file...

ivirshup added 5 commits April 1, 2019 12:34
These tests get skipped by default, unless pytest is run with `pytest --internet-tests`. This is because they take a while to run, and could cause spurious failed builds on travis.

I've move `conftest.py` to the root of the repository since I was getting errors for the added flags with it's previous position. It looked like the file under `scanpy/test/conftest.py` might not have been getting evaluated, as documented by under the [`confcutdir`](https://docs.pytest.org/en/latest/reference.html#confval-confcutdir) config variable for pytest. I tried setting that as well, but it didn't seem to work.
@ivirshup

ivirshup commented Apr 1, 2019

Copy link
Copy Markdown
Member Author

Can we call this epi_sc_expression_atlas instead of expression_atlas?

Definitely agree it's good to specify it's from EBI. Would ebi_expression_atlas be alright? ebi_sc_expression_atlas feels a little verbose for me. I think it's implied it's single cell, plus it's explicit in the doc-string.

For the time being, can we make this settings.datasetsdir instead of settings.dataset_dir and add it here:

Changed the name. It looks like the main docs aren't being generated from scanpy/scanpy/api/__init__.py, but from docs/api/index.rst instead. Which is correct?

Can we point it to the home directory by default, I'd say ~/scanpy-datasets/?

Changed.

Does this mean config changes should also happen in this PR? I think this may cause trouble (HPC environments with small ~ allocations) without allowing default configuration at the same time. I had previously figured that setting up a config file could be factored out to a separate PR.

To be able to put off adding the config for now, we could temporarily special case a SCANPY_DATASETDIR environment variable.

@ivirshup

ivirshup commented Apr 1, 2019 •

Copy link
Copy Markdown
Member Author

Oh, I also added tests for example dataset loading since checking they worked manually was a pain. These won't run by default (they take a while, and can fail for network access reasons), but will run with pytest --internet-tests. Note that test_burczynski06 will fail until this get's rebased on master. Thoughts?

Also travis failed this for scanpy/tests/test_marker_gene_overlap.py failing an assertion on the first time around, but passed when I triggered a new build. Not sure what's up with that.

@flying-sheep
flying-sheep self-requested a review April 1, 2019 07:43
Comment thread scanpy/settings.py Outdated
"""Default cache directory.
"""

datasetdir = Path.home() / "scanpy_datasets"

@flying-sheep flying-sheep Apr 1, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Veto, see #558. I consider creating ~/something-visible a completely unacceptable default for a library.

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.

I think it would be best to leave this change out of this PR. We can do a separate one once we have decided on how to tackle this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I also think it would be a good idea to leave changing the default to a separate PR.

You'll see I initially made this a non-breaking change (datasetdir = Path("./data")), just changed to this going off feedback from Alex.

I'm gonna wait on actually modifying the code for a minute to make the eventual rebase easier.

@flying-sheep flying-sheep Apr 1, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, great. I think the changes to the default (./data → ~/???) should be in a PR that also changes what’s printed on download/read of such files, and we can figure out there how to detect if we’re on a linux server (where ~/scanpy_data would make sense) or on a desktop system (where it doesn’t)

As an aside: Windows Explorer’s default view doesn’t show you your %HOME%, so ~/scanpy_datasets wouldn’t even be visible there. @falexwolf, @ivirshup: In summary: This topic requires discussion, it’s more complex than it seems, and I’ve read up a lot on it, so I think you should either leave the decision to me or let me explain it to you in all its tiring depth. I’ll do it if you think it’s worth your time.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind sharing some links which explain why this is important? I'll admit, it does not seem very complex to me at the moment, but I also don't know much about this topic.

Also, a more general question, does scanpy work on windows?

@flying-sheep flying-sheep Apr 2, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly there’s no writeup. It’s a lot of different observations I made and discussions in different projects. If you search XDG_CONFIG_HOME and XDG_CACHE_HOME you’ll find a lot of people requesting that (e.g. mwaskom/seaborn#1530)

The question “why not” is always answered with “we didn’t think about it” or “we followed what others did (without thinking about it)”, and the answer to “why don’t you change” is always “we have been doing it for too long, people will get confused”. So I won’t wait until somebody is able to say the latter about scanpy.

So yeah: What appdirs and similar modules do as well as the discussions in those modules’ issue trackers is pretty much the best one can get as a writeup. One then cross-references what one’s library/app needs to write to some global location (executables? config? cache? logs? documents?) with the locations those modules provide. Then one saves those files there instead of coming up with something themselves because many people have thought a long time about this to create that module.


About Windows: Yes! I think it’s important to keep it that way. I recently read this blog post and fully agree with the author:

[…] a Ruby that works well on native Windows will help Ruby adoption a lot and eliminate drain to other frameworks. Installing a whole brand new OS is just too much of a barrier. Just install Linux is not a solution.

The same applies to everything of course. Many just start out and aren’t fed up by Windows enough to ditch it, so making the start on Windows as smooth as possible helps adoption by new people a lot.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check out that issue.

I have nothing against windows support, I just can't help on any issues related to it. I was mostly wondering if all the dependencies worked on windows, and if there's a reason there aren't appveyor builds.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requested change is resolved now, right?

@ivirshup

ivirshup commented Apr 2, 2019

Copy link
Copy Markdown
Member Author

@falexwolf, @flying-sheep

Just to recap what's left to be resolved here

  • I'll reset the default value of datasetdir to the current value "./data"
  • Related, how about datasetdir instead of datasetsdir? It matches more to cachedir and figdir. Also, by analogy, it's "potato sack" not "potatoes sack" so "dataset directory" sounds more natural that "datasets directory" to me.
  • ebi_expression_atlas vs ebi_sc_expression_atlas
  • Potentially adding a class for settings right now?
    • I think this becomes more important if datasetdir is documented. I bet people will set it with a str instead of a Path and that'll break things.

Comment thread docs/api/index.rst Resolved
Comment thread scanpy/settings.py Outdated
"""Default cache directory.
"""

datasetdir = Path.home() / "scanpy_datasets"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind sharing some links which explain why this is important? I'll admit, it does not seem very complex to me at the moment, but I also don't know much about this topic.

Also, a more general question, does scanpy work on windows?

@falexwolf

Copy link
Copy Markdown
Member

OK guys, I'm happy with all that!

I suggested datasetsdir over datasetdir because the module is called datasets and it's a place where many datasets end up. But, Isaac, you're the native speaker, so you're choice.

Regarding making a settings a class: happy to if you feel you want to do that already in this PR.

Really just change scanpy/settings.py to scanpy/_settings.py, put a Settings class in that file and generate an instance upon importing Scanpy. You could also just make datasetdir the only property and add all other attributes of the current scanpy/settings module as simple attributes. Then, all of this should be 10 min of work.

ivirshup added 2 commits April 4, 2019 00:12
This will definitley cause errors on master. Let's call it an excuse to increase test coverage?

Basically, I just went through making import patterns compatable with the new settings class. Those imports are pretty ugly at the moment, and there might be a better way to do them.
@falexwolf

Copy link
Copy Markdown
Member

Wow, you already did it! Fantastic! 😄

@ivirshup

ivirshup commented Apr 3, 2019

Copy link
Copy Markdown
Member Author

Went with properties for everything except private variables. Took a little longer than 10 minutes, but I think it's mostly there.

Got all the tests to pass on my machine, but I bet other things will fail. I also haven't tested what'll happen with the docs, though I did have to modify some of the documentation code.

  • The verbosity settings might be trouble. I changed the value again... but this should stop an error I'm getting with bbknn and be consistent with the python logging module.
  • The settings imports are ugly. Wasn't sure how to import a variable from a parent module. Is this possible?

@ivirshup

ivirshup commented Apr 4, 2019

Copy link
Copy Markdown
Member Author

Assuming this build passes, is this good to go?

@falexwolf

Copy link
Copy Markdown
Member

Went with properties for everything except private variables. Took a little longer than 10 minutes, but I think it's mostly there.

Yes, now that you made everything a property, I would have expected it to take much longer than 10 minutes. It's great that you did!

I'll make some tiny additions and merge.

Comment thread scanpy/__init__.py
from .settings import set_figure_params
from ._settings import settings

set_figure_params = settings.set_figure_params

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got, you made it a member function...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it a method for the class in anticipation of making the updated rc_params a dict in the object, then using that dict with mpl.rc_context

@falexwolf

Copy link
Copy Markdown
Member

Ah, I cannot push to your fork it seems. I think you would have had to set "allow maintainers to edit" or something on the right-hand side. I'm simply merging this and editing after that.

@falexwolf
falexwolf merged commit ec48368 into scverse:master Apr 4, 2019
@falexwolf

Copy link
Copy Markdown
Member

Here we go: a06c304

@ivirshup

ivirshup commented Apr 4, 2019 •

Copy link
Copy Markdown
Member Author

Oh, huh, I thought allowing modifications was on by default. My bad.

Yes, now that you made everything a property, I would have expected it to take much longer than 10 minutes. It's great that you did!

I figured it'd be good to with everything being consistent. Plus documentation for the settings is now available through ?sc.settings.{setting}!

@ivirshup

ivirshup commented Apr 4, 2019

Copy link
Copy Markdown
Member Author

Oh! I keep forgetting to ask: Why did the original scanpy config file get removed?

@falexwolf

Copy link
Copy Markdown
Member

I figured it'd be good to with everything being consistent. Plus documentation for the settings is now available through ?sc.settings.{setting}!

Of course, it's much better to be consistent. I was just suggesting a quick solution that wouldn't have been worse than the current one... ;)

A complete automatic documentation is now also available from
https://scanpy.readthedocs.io/en/latest/api/scanpy._settings.ScanpyConfig.html
under
https://scanpy.readthedocs.io/en/latest/api/index.html#settings

scanpy config: At some point almost 2 years ago, I removed a lot of stuff that I didn't think was essential to clean up the project. It was just an element of that. I'm very happy to introduce it again; these days, the project is much more major and indeed has many config options (there were only few at the time) and hence it would indeed merit having a config file.

@falexwolf

falexwolf commented Apr 4, 2019 •

Copy link
Copy Markdown
Member

Only strange thing is the getdoc function.

To be more verbose, one could also change all the cryptic abbreviations to:

directory_cache
directory_figures
directory_datasets
directory_write (but this should be deprecated anyway, wasn't a great idea... reminiscent from the very early CLI time of scanpy)

or something. It's great that this is super easy without breaking backwards compat now that everything is properties. :)

@ivirshup

ivirshup commented Apr 4, 2019

Copy link
Copy Markdown
Member Author

Only strange thing is the getdoc function.

It looks like instance methods can't have new attributes assigned (probably have slots). It's possible the .getdoc attribute could be added to the classes method (not sure if that's the right way to say that, here's an example):

class Foo(object):
    def bar(self):
        return 1

# Setting an attribute on the method of an instance raises an error
Foo().bar.x = 1
# AttributeError: 'method' object has no attribute 'x'

# Setting an attribute on the method of a class seems fine:
Foo.bar.x = 1 
Foo().bar.x
# 1

awnimo pushed a commit to dpeerlab/scanpy that referenced this pull request Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants