|
1 | 1 | # Python Library for Loading and Manipulating lyDATA Tables |
2 | 2 |
|
3 | | -[](https://github.com/lycosystem/lydata/actions/workflows/build.yml) |
4 | | -[](https://github.com/lycosystem/lydata/actions/workflows/tests.yml) |
5 | | -[](https://lydata.readthedocs.io/en/stable/?badge=stable) |
| 3 | +[](https://github.com/lycosystem/lydata-package/actions/workflows/release.yml) |
| 4 | +[](https://github.com/lycosystem/lydata-package/actions/workflows/tests.yml) |
| 5 | +[](https://lydata.readthedocs.io/stable/?badge=stable) |
| 6 | +[](https://htmlpreview.github.io/?https://github.com/lycosystem/lydata-package/blob/python-coverage-comment-action-data/htmlcov/index.html) |
6 | 7 |
|
7 | 8 | This repository provides a Python library for loading, manipulating, and validating the datasets available on [lyDATA](https://github.com/lycosystem/lydata). |
8 | 9 |
|
@@ -36,72 +37,57 @@ pip install -e . |
36 | 37 | The first and most common use case would probably listing and loading the published datasets: |
37 | 38 |
|
38 | 39 | ```python |
39 | | -import lydata |
40 | | - |
41 | | -for dataset_spec in lydata.available_datasets( |
42 | | - year=2023, # show all datasets added in 2023 |
43 | | - use_github=True, # do not search on disk, but rather on GitHub |
44 | | - ref="61a17e", # may be some specific hash/tag/branch |
45 | | -): |
46 | | - print(dataset_spec.name) |
47 | | - |
48 | | -# output: |
49 | | -# 2023-clb-multisite |
50 | | -# 2023-isb-multisite |
51 | | - |
52 | | -first_dataset = next(lydata.load_datasets( |
53 | | - subsite="oropharynx", # merge data that include oropharyngeal tumor patients |
54 | | - use_github=True, # again, search GitHub, not on disk (which is the default) |
55 | | -)) |
56 | | -print(first_dataset.head()) |
57 | | - |
58 | | -# output: |
59 | | -# patient ... positive_dissected |
60 | | -# # ... contra |
61 | | -# id institution sex ... III IV V |
62 | | -# 0 P011 Centre Léon Bérard male ... 0.0 0.0 0.0 |
63 | | -# 1 P012 Centre Léon Bérard female ... 0.0 0.0 0.0 |
64 | | -# 2 P014 Centre Léon Bérard male ... 0.0 0.0 NaN |
65 | | -# 3 P015 Centre Léon Bérard male ... 0.0 0.0 NaN |
66 | | -# 4 P018 Centre Léon Bérard male ... NaN NaN NaN |
67 | | -# |
68 | | -# [5 rows x 82 columns] |
| 40 | +>>> import lydata |
| 41 | +>>> for dataset_spec in lydata.available_datasets( |
| 42 | +... year=2023, # show all datasets added in 2023 |
| 43 | +... ref="61a17e", # may be some specific hash/tag/branch |
| 44 | +... ): |
| 45 | +... print(dataset_spec.name) |
| 46 | +2023-clb-multisite |
| 47 | +2023-isb-multisite |
| 48 | + |
| 49 | +# return generator of datasets that include oropharyngeal tumor patients |
| 50 | +>>> first_dataset = next(lydata.load_datasets(subsite="oropharynx")) |
| 51 | +>>> print(first_dataset.head()) |
| 52 | +... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE |
| 53 | + patient ... positive_dissected |
| 54 | + # ... contra |
| 55 | + id institution sex ... III IV V |
| 56 | +0 P011 Centre Léon Bérard male ... 0.0 0.0 0.0 |
| 57 | +1 P012 Centre Léon Bérard female ... 0.0 0.0 0.0 |
| 58 | +2 P014 Centre Léon Bérard male ... 0.0 0.0 NaN |
| 59 | +3 P015 Centre Léon Bérard male ... 0.0 0.0 NaN |
| 60 | +4 P018 Centre Léon Bérard male ... NaN NaN NaN |
| 61 | +[5 rows x 82 columns] |
| 62 | + |
69 | 63 | ``` |
70 | 64 |
|
71 | 65 | And since the three-level header of the tables is a little unwieldy at times, we also provide some shortcodes via a custom pandas accessor. As soon as `lydata` is imported it can be used like this: |
72 | 66 |
|
73 | 67 | ```python |
74 | | -print(first_dataset.ly.age) |
75 | | - |
76 | | -# output: |
77 | | -# 0 67 |
78 | | -# 1 62 |
79 | | -# .. |
80 | | -# 261 60 |
81 | | -# 262 60 |
82 | | -# Name: (patient, #, age), Length: 263, dtype: int64 |
| 68 | +>>> print(first_dataset.ly.age) |
| 69 | +... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE |
| 70 | +0 67 |
| 71 | +1 62 |
| 72 | + ... |
| 73 | +261 60 |
| 74 | +262 60 |
| 75 | +Name: (patient, #, age), Length: 263, dtype: int64 |
| 76 | + |
83 | 77 | ``` |
84 | 78 |
|
85 | 79 | And we have implemented `Q` and `C` objects inspired by Django that allow easier querying of the tables: |
86 | 80 |
|
87 | 81 | ```python |
88 | | -from lydata import C |
| 82 | +>>> from lydata import C |
89 | 83 |
|
90 | 84 | # select patients younger than 50 that are not HPV positive (includes NaNs) |
91 | | -query_result = first_dataset.ly.query((C("age") < 50) & ~(C("hpv") == True)) |
92 | | -print(query_result) |
93 | | - |
94 | | -# output: |
95 | | -# patient ... positive_dissected |
96 | | -# # ... contra |
97 | | -# id institution sex age ... II III IV V |
98 | | -# 2 P014 Centre Léon Bérard male 43 ... 1.0 0.0 0.0 NaN |
99 | | -# 7 P024 Centre Léon Bérard male 45 ... NaN NaN NaN NaN |
100 | | -# .. ... ... ... .. ... ... ... ... ... |
101 | | -# 212 P270 Centre Léon Bérard male 47 ... 0.0 0.0 0.0 NaN |
102 | | -# 217 P275 Centre Léon Bérard male 49 ... 0.0 0.0 0.0 NaN |
103 | | -# |
104 | | -# [13 rows x 82 columns] |
| 85 | +>>> query_result = first_dataset.ly.query((C("age") < 50) & ~(C("hpv") == True)) |
| 86 | +>>> (query_result.ly.age < 50).all() |
| 87 | +np.True_ |
| 88 | +>>> (query_result.ly.hpv == False).all() |
| 89 | +np.True_ |
| 90 | + |
105 | 91 | ``` |
106 | 92 |
|
107 | 93 | For more details and further examples or use-cases, have a look at the [official documentation](https://lydata.readthedocs.org/) |
0 commit comments