discotoolkit 1.2.2__tar.gz → 1.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/PKG-INFO +8 -8
  2. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/README.md +7 -7
  3. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit/GlobalVariable.py +16 -9
  4. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit/__init__.py +1 -1
  5. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit.egg-info/PKG-INFO +8 -8
  6. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit.egg-info/SOURCES.txt +1 -0
  7. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/setup.py +1 -1
  8. discotoolkit-1.3.0/tests/test_metadata_helpers.py +49 -0
  9. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/tests/test_settings.py +26 -6
  10. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/MANIFEST.in +0 -0
  11. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit/CELLiD.py +0 -0
  12. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit/CellMapper.py +0 -0
  13. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit/DiscoClass.py +0 -0
  14. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit/DownloadDiscoData.py +0 -0
  15. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit/GeneSearch.py +0 -0
  16. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit/GetMetadata.py +0 -0
  17. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit/Utilities.py +0 -0
  18. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit.egg-info/dependency_links.txt +0 -0
  19. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit.egg-info/requires.txt +0 -0
  20. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/discotoolkit.egg-info/top_level.txt +0 -0
  21. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/pyproject.toml +0 -0
  22. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/requirements.txt +0 -0
  23. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/setup.cfg +0 -0
  24. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/tests/test_docs.py +0 -0
  25. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/tests/test_gene_search.py +0 -0
  26. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/tests/test_reference_loading.py +0 -0
  27. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/tests/test_server_contract.py +0 -0
  28. {discotoolkit-1.2.2 → discotoolkit-1.3.0}/tests/test_version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: discotoolkit
3
- Version: 1.2.2
3
+ Version: 1.3.0
4
4
  Summary: DISCOtoolkit is an python package that allows users to access data and use the tools provided by the DISCO database.
5
5
  Home-page: https://disco.bii.a-star.edu.sg/
6
6
  Author: Li Mengwei, Rom Uddamvathanak
@@ -43,7 +43,7 @@ Dynamic: summary
43
43
  -->
44
44
  [![Documentation](https://img.shields.io/badge/docs-disco.bii.a--star.edu.sg-blue)](https://disco.bii.a-star.edu.sg/v1/docs/toolkit/guide/) [![Downloads](https://static.pepy.tech/personalized-badge/discotoolkit?period=total&units=international_system&left_color=black&right_color=orange&left_text=Downloads)](https://pepy.tech/project/discotoolkit) [![PyPI version](https://img.shields.io/pypi/v/discotoolkit)](https://pypi.org/project/discotoolkit)
45
45
 
46
- # DISCOtoolkit 1.2.2
46
+ # DISCOtoolkit 1.3.0
47
47
 
48
48
  DISCOtoolkit is a Python package for accessing the data and tools of the [DISCO database](https://disco.bii.a-star.edu.sg/) (DISCO v1). Read the documentation, with tutorials and the API reference, at [disco.bii.a-star.edu.sg/v1/docs/toolkit/guide](https://disco.bii.a-star.edu.sg/v1/docs/toolkit/guide/).
49
49
 
@@ -52,7 +52,7 @@ DISCOtoolkit is a Python package for accessing the data and tools of the [DISCO
52
52
  - CELLiD: cell type annotation
53
53
  - scEnrichment: gene set enrichment using DISCO DEGs
54
54
 
55
- > **Use DISCO v1.** The toolkit is developed and tested against **DISCO v1**, which is the default, and that is the server we recommend. DISCO v2 has its own R package ([DISCOtoolkit](https://github.com/JinmiaoChenLab/DISCOtoolkit)). The Python package can be pointed at a v2 server, but that is not tested; see [Choosing a server](#choosing-a-server).
55
+ > **For DISCO v1.** The toolkit is built for and tested against **DISCO v1**, which it uses by default. DISCO v2 is not supported; it has its own R package, [DISCOtoolkit](https://github.com/JinmiaoChenLab/DISCOtoolkit).
56
56
 
57
57
  ## Quickstart (Google Colab)
58
58
 
@@ -96,17 +96,17 @@ python -m ipykernel install --user --name disco --display-name "disco"
96
96
  python -m pip install -U discotoolkit
97
97
  ```
98
98
 
99
- ## Choosing a server
99
+ ## Server
100
100
 
101
101
  ```python
102
102
  import discotoolkit as dt
103
103
 
104
- dt.get_server() # 'https://disco.bii.a-star.edu.sg/disco_v3_api/' (DISCO v1, the default)
105
- dt.set_server("v2") # DISCO v2 (not tested; DISCO v1 is the supported server)
106
- dt.set_server("https://my.server/disco_v3_api/") # any server with the same API
104
+ dt.get_server() # 'https://disco.bii.a-star.edu.sg/disco_v3_api/' (DISCO v1)
105
+ dt.set_server("https://my.mirror/disco_v3_api/") # a mirror or test copy of DISCO v1
107
106
  ```
108
107
 
109
- or set the `DISCO_API_URL` environment variable before importing the package.
108
+ or set the `DISCO_API_URL` environment variable before importing the package. The tests use this
109
+ to run against a local copy of DISCO v1.
110
110
 
111
111
  ## Testing
112
112
 
@@ -8,7 +8,7 @@
8
8
  -->
9
9
  [![Documentation](https://img.shields.io/badge/docs-disco.bii.a--star.edu.sg-blue)](https://disco.bii.a-star.edu.sg/v1/docs/toolkit/guide/) [![Downloads](https://static.pepy.tech/personalized-badge/discotoolkit?period=total&units=international_system&left_color=black&right_color=orange&left_text=Downloads)](https://pepy.tech/project/discotoolkit) [![PyPI version](https://img.shields.io/pypi/v/discotoolkit)](https://pypi.org/project/discotoolkit)
10
10
 
11
- # DISCOtoolkit 1.2.2
11
+ # DISCOtoolkit 1.3.0
12
12
 
13
13
  DISCOtoolkit is a Python package for accessing the data and tools of the [DISCO database](https://disco.bii.a-star.edu.sg/) (DISCO v1). Read the documentation, with tutorials and the API reference, at [disco.bii.a-star.edu.sg/v1/docs/toolkit/guide](https://disco.bii.a-star.edu.sg/v1/docs/toolkit/guide/).
14
14
 
@@ -17,7 +17,7 @@ DISCOtoolkit is a Python package for accessing the data and tools of the [DISCO
17
17
  - CELLiD: cell type annotation
18
18
  - scEnrichment: gene set enrichment using DISCO DEGs
19
19
 
20
- > **Use DISCO v1.** The toolkit is developed and tested against **DISCO v1**, which is the default, and that is the server we recommend. DISCO v2 has its own R package ([DISCOtoolkit](https://github.com/JinmiaoChenLab/DISCOtoolkit)). The Python package can be pointed at a v2 server, but that is not tested; see [Choosing a server](#choosing-a-server).
20
+ > **For DISCO v1.** The toolkit is built for and tested against **DISCO v1**, which it uses by default. DISCO v2 is not supported; it has its own R package, [DISCOtoolkit](https://github.com/JinmiaoChenLab/DISCOtoolkit).
21
21
 
22
22
  ## Quickstart (Google Colab)
23
23
 
@@ -61,17 +61,17 @@ python -m ipykernel install --user --name disco --display-name "disco"
61
61
  python -m pip install -U discotoolkit
62
62
  ```
63
63
 
64
- ## Choosing a server
64
+ ## Server
65
65
 
66
66
  ```python
67
67
  import discotoolkit as dt
68
68
 
69
- dt.get_server() # 'https://disco.bii.a-star.edu.sg/disco_v3_api/' (DISCO v1, the default)
70
- dt.set_server("v2") # DISCO v2 (not tested; DISCO v1 is the supported server)
71
- dt.set_server("https://my.server/disco_v3_api/") # any server with the same API
69
+ dt.get_server() # 'https://disco.bii.a-star.edu.sg/disco_v3_api/' (DISCO v1)
70
+ dt.set_server("https://my.mirror/disco_v3_api/") # a mirror or test copy of DISCO v1
72
71
  ```
73
72
 
74
- or set the `DISCO_API_URL` environment variable before importing the package.
73
+ or set the `DISCO_API_URL` environment variable before importing the package. The tests use this
74
+ to run against a local copy of DISCO v1.
75
75
 
76
76
  ## Testing
77
77
 
@@ -2,13 +2,13 @@
2
2
  Settings shared by the rest of the package: logging, the request timeout and --
3
3
  most importantly -- which DISCO server the toolkit talks to.
4
4
 
5
- By default the toolkit talks to DISCO v1 (https://disco.bii.a-star.edu.sg). DISCO v1 is the
6
- server the toolkit is developed and tested against, and the one we recommend. Other servers
7
- are possible but untested (the "v2" preset in particular):
5
+ The toolkit is built for, and tested against, DISCO v1 (https://disco.bii.a-star.edu.sg), and
6
+ talks to it by default. DISCO v2 is not supported: it has its own R package (DISCOtoolkit).
7
+
8
+ For a mirror or a test copy of DISCO v1 there is still a way to point it elsewhere:
8
9
 
9
10
  import discotoolkit as dt
10
- dt.set_server("v2") # a named preset
11
- dt.set_server("https://my.server/disco_v3_api/") # any server with the same API
11
+ dt.set_server("https://my.mirror/disco_v3_api/")
12
12
 
13
13
  or set the DISCO_API_URL environment variable before importing the package.
14
14
  """
@@ -21,19 +21,26 @@ logging.basicConfig(level=logging.INFO)
21
21
  # seconds to wait for the server; the reference downloads are tens of MB
22
22
  timeout = 600
23
23
 
24
- # The API roots the toolkit knows by name. Both serve the same `toolkit/...` endpoints.
24
+ # The API roots the toolkit knows by name.
25
25
  SERVERS = {
26
26
  "v1": "https://disco.bii.a-star.edu.sg/disco_v3_api/",
27
- "v2": "https://immunesinglecell.org/disco_v3_api/",
28
27
  }
29
28
  DEFAULT_SERVER = "v1"
30
29
 
30
+ # Removed in 1.3.0: the toolkit was never tested against DISCO v2, which has its own R package.
31
+ _UNSUPPORTED = {
32
+ "v2": "DISCO v2 is not supported by the Python toolkit, which is built and tested for DISCO v1 "
33
+ "(the default). For DISCO v2 use its R package: https://github.com/JinmiaoChenLab/DISCOtoolkit",
34
+ }
35
+
31
36
 
32
37
  def _normalise(server: str) -> str:
33
38
  """Turn a preset name or a URL into an API root that ends with exactly one '/'."""
34
39
  if not isinstance(server, str) or not server.strip():
35
40
  raise ValueError("server must be a preset name (%s) or a URL" % ", ".join(SERVERS))
36
41
  server = server.strip()
42
+ if server.lower() in _UNSUPPORTED:
43
+ raise ValueError(_UNSUPPORTED[server.lower()])
37
44
  if server.lower() in SERVERS:
38
45
  return SERVERS[server.lower()]
39
46
  if not server.lower().startswith(("http://", "https://")):
@@ -50,8 +57,8 @@ def set_server(server: str) -> str:
50
57
  """Choose which DISCO server the toolkit uses for the rest of the session.
51
58
 
52
59
  Args:
53
- server (str): "v1", "v2", or the full URL of an API root such as
54
- "https://disco.bii.a-star.edu.sg/disco_v3_api/".
60
+ server (str): "v1" (DISCO v1, the default), or the full URL of the API root of a mirror
61
+ or test copy of DISCO v1, such as "http://127.0.0.1:8889/disco_v3_api/".
55
62
 
56
63
  Returns:
57
64
  str: the API root now in use.
@@ -5,4 +5,4 @@ from .CELLiD import *
5
5
  from .GeneSearch import *
6
6
  from .GlobalVariable import set_server, get_server
7
7
 
8
- __version__ = "1.2.2"
8
+ __version__ = "1.3.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: discotoolkit
3
- Version: 1.2.2
3
+ Version: 1.3.0
4
4
  Summary: DISCOtoolkit is an python package that allows users to access data and use the tools provided by the DISCO database.
5
5
  Home-page: https://disco.bii.a-star.edu.sg/
6
6
  Author: Li Mengwei, Rom Uddamvathanak
@@ -43,7 +43,7 @@ Dynamic: summary
43
43
  -->
44
44
  [![Documentation](https://img.shields.io/badge/docs-disco.bii.a--star.edu.sg-blue)](https://disco.bii.a-star.edu.sg/v1/docs/toolkit/guide/) [![Downloads](https://static.pepy.tech/personalized-badge/discotoolkit?period=total&units=international_system&left_color=black&right_color=orange&left_text=Downloads)](https://pepy.tech/project/discotoolkit) [![PyPI version](https://img.shields.io/pypi/v/discotoolkit)](https://pypi.org/project/discotoolkit)
45
45
 
46
- # DISCOtoolkit 1.2.2
46
+ # DISCOtoolkit 1.3.0
47
47
 
48
48
  DISCOtoolkit is a Python package for accessing the data and tools of the [DISCO database](https://disco.bii.a-star.edu.sg/) (DISCO v1). Read the documentation, with tutorials and the API reference, at [disco.bii.a-star.edu.sg/v1/docs/toolkit/guide](https://disco.bii.a-star.edu.sg/v1/docs/toolkit/guide/).
49
49
 
@@ -52,7 +52,7 @@ DISCOtoolkit is a Python package for accessing the data and tools of the [DISCO
52
52
  - CELLiD: cell type annotation
53
53
  - scEnrichment: gene set enrichment using DISCO DEGs
54
54
 
55
- > **Use DISCO v1.** The toolkit is developed and tested against **DISCO v1**, which is the default, and that is the server we recommend. DISCO v2 has its own R package ([DISCOtoolkit](https://github.com/JinmiaoChenLab/DISCOtoolkit)). The Python package can be pointed at a v2 server, but that is not tested; see [Choosing a server](#choosing-a-server).
55
+ > **For DISCO v1.** The toolkit is built for and tested against **DISCO v1**, which it uses by default. DISCO v2 is not supported; it has its own R package, [DISCOtoolkit](https://github.com/JinmiaoChenLab/DISCOtoolkit).
56
56
 
57
57
  ## Quickstart (Google Colab)
58
58
 
@@ -96,17 +96,17 @@ python -m ipykernel install --user --name disco --display-name "disco"
96
96
  python -m pip install -U discotoolkit
97
97
  ```
98
98
 
99
- ## Choosing a server
99
+ ## Server
100
100
 
101
101
  ```python
102
102
  import discotoolkit as dt
103
103
 
104
- dt.get_server() # 'https://disco.bii.a-star.edu.sg/disco_v3_api/' (DISCO v1, the default)
105
- dt.set_server("v2") # DISCO v2 (not tested; DISCO v1 is the supported server)
106
- dt.set_server("https://my.server/disco_v3_api/") # any server with the same API
104
+ dt.get_server() # 'https://disco.bii.a-star.edu.sg/disco_v3_api/' (DISCO v1)
105
+ dt.set_server("https://my.mirror/disco_v3_api/") # a mirror or test copy of DISCO v1
107
106
  ```
108
107
 
109
- or set the `DISCO_API_URL` environment variable before importing the package.
108
+ or set the `DISCO_API_URL` environment variable before importing the package. The tests use this
109
+ to run against a local copy of DISCO v1.
110
110
 
111
111
  ## Testing
112
112
 
@@ -19,6 +19,7 @@ discotoolkit.egg-info/requires.txt
19
19
  discotoolkit.egg-info/top_level.txt
20
20
  tests/test_docs.py
21
21
  tests/test_gene_search.py
22
+ tests/test_metadata_helpers.py
22
23
  tests/test_reference_loading.py
23
24
  tests/test_server_contract.py
24
25
  tests/test_settings.py
@@ -6,7 +6,7 @@ with open("requirements.txt", "r") as f:
6
6
 
7
7
  setup(
8
8
  name='discotoolkit',
9
- version="1.2.2",
9
+ version="1.3.0",
10
10
  url='https://disco.bii.a-star.edu.sg/',
11
11
  author='Li Mengwei, Rom Uddamvathanak',
12
12
  author_email='uddamvathanak_rom@immunol.a-star.edu.sg',
@@ -0,0 +1,49 @@
1
+ """
2
+ The metadata helpers people use to discover what they can filter on: list_all_columns and
3
+ list_metadata_item. No network: the metadata table is faked.
4
+
5
+ python tests/test_metadata_helpers.py
6
+ """
7
+ import os
8
+ import sys
9
+ from unittest import mock
10
+
11
+ import pandas as pd
12
+
13
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
14
+ from discotoolkit import GetMetadata # noqa: E402
15
+
16
+ TABLE = pd.DataFrame({
17
+ "sample_id": ["S1", "S2", "S3"],
18
+ "tissue": ["lung", "lung", "blood"],
19
+ "platform": ["10x3'", "10x5'", "10x3'"],
20
+ })
21
+
22
+
23
+ def test_list_all_columns_names_every_metadata_field():
24
+ with mock.patch.object(GetMetadata, "get_disco_metadata", return_value=TABLE):
25
+ assert GetMetadata.list_all_columns() == ["sample_id", "tissue", "platform"]
26
+
27
+
28
+ def test_list_metadata_item_gives_each_value_once():
29
+ with mock.patch.object(GetMetadata, "get_disco_metadata", return_value=TABLE):
30
+ assert sorted(GetMetadata.list_metadata_item("platform")) == ["10x3'", "10x5'"]
31
+ assert GetMetadata.list_metadata_item("no_such_field") is None
32
+
33
+
34
+ def _run_all():
35
+ tests = [(n, f) for n, f in sorted(globals().items()) if n.startswith("test_") and callable(f)]
36
+ failed = 0
37
+ for name, fn in tests:
38
+ try:
39
+ fn()
40
+ print(" PASS %s" % name)
41
+ except Exception as error:
42
+ failed += 1
43
+ print(" FAIL %s\n %s: %s" % (name, type(error).__name__, error))
44
+ print("\n%d/%d passed" % (len(tests) - failed, len(tests)))
45
+ return 1 if failed else 0
46
+
47
+
48
+ if __name__ == "__main__":
49
+ sys.exit(_run_all())
@@ -41,15 +41,29 @@ def test_api_url_joins_paths_with_exactly_one_slash():
41
41
  assert g.api_url("/toolkit/getSampleMetadata") == g.get_server() + "toolkit/getSampleMetadata"
42
42
 
43
43
 
44
- def test_named_presets_and_urls():
44
+ def test_v1_preset_and_urls_of_a_mirror():
45
45
  g = load()
46
- assert g.set_server("v2") == "https://immunesinglecell.org/disco_v3_api/"
47
- assert g.api_url("x") == "https://immunesinglecell.org/disco_v3_api/x" # takes effect at once
46
+ assert g.set_server("http://127.0.0.1:8889/disco_v3_api") == "http://127.0.0.1:8889/disco_v3_api/"
47
+ assert g.api_url("x") == "http://127.0.0.1:8889/disco_v3_api/x" # takes effect at once
48
48
  assert g.set_server("V1") == g.SERVERS["v1"] # preset names are case-insensitive
49
49
  assert g.set_server("https://example.org/api") == "https://example.org/api/" # trailing slash added
50
50
  assert g.set_server("http://localhost:8889/disco_v3_api///") == "http://localhost:8889/disco_v3_api/"
51
51
 
52
52
 
53
+ def test_disco_v2_is_refused_with_a_pointer_to_the_r_package():
54
+ g = load()
55
+ before = g.get_server()
56
+ for name in ("v2", "V2"):
57
+ try:
58
+ g.set_server(name)
59
+ except ValueError as error:
60
+ assert "R package" in str(error) and "DISCOtoolkit" in str(error), error
61
+ else:
62
+ raise AssertionError("set_server(%r) was accepted" % name)
63
+ assert g.get_server() == before
64
+ assert list(g.SERVERS) == ["v1"]
65
+
66
+
53
67
  def test_bad_servers_are_rejected_without_changing_the_current_one():
54
68
  g = load()
55
69
  before = g.get_server()
@@ -64,14 +78,20 @@ def test_bad_servers_are_rejected_without_changing_the_current_one():
64
78
 
65
79
 
66
80
  def test_environment_variable_sets_the_starting_server():
67
- assert load("v2").get_server() == "https://immunesinglecell.org/disco_v3_api/"
68
81
  assert load("https://example.org/disco_v3_api").get_server() == "https://example.org/disco_v3_api/"
82
+ # asking for v2 through the environment fails loudly rather than quietly using v1
83
+ try:
84
+ load("v2")
85
+ except ValueError:
86
+ pass
87
+ else:
88
+ raise AssertionError("DISCO_API_URL=v2 was accepted")
69
89
 
70
90
 
71
91
  def test_old_prefix_variable_still_readable():
72
92
  g = load()
73
- g.set_server("v2")
74
- assert g.prefix_disco_url == "https://immunesinglecell.org/disco_v3_api/"
93
+ g.set_server("https://example.org/disco_v3_api/")
94
+ assert g.prefix_disco_url == "https://example.org/disco_v3_api/"
75
95
 
76
96
 
77
97
  def _run_all():
File without changes
File without changes