harmonizome 1.0.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.
- harmonizome-1.0.0/.gitignore +173 -0
- harmonizome-1.0.0/LICENSE +21 -0
- harmonizome-1.0.0/MANIFEST.in +7 -0
- harmonizome-1.0.0/PKG-INFO +243 -0
- harmonizome-1.0.0/README.md +207 -0
- harmonizome-1.0.0/examples/__init__.py +1 -0
- harmonizome-1.0.0/examples/dataset_query.py +20 -0
- harmonizome-1.0.0/harmonizome/__init__.py +6 -0
- harmonizome-1.0.0/harmonizome/harmonizome.py +1032 -0
- harmonizome-1.0.0/harmonizome/harmonizome_cli.py +368 -0
- harmonizome-1.0.0/harmonizome/utils.py +21 -0
- harmonizome-1.0.0/harmonizome.egg-info/PKG-INFO +243 -0
- harmonizome-1.0.0/harmonizome.egg-info/SOURCES.txt +21 -0
- harmonizome-1.0.0/harmonizome.egg-info/dependency_links.txt +1 -0
- harmonizome-1.0.0/harmonizome.egg-info/entry_points.txt +2 -0
- harmonizome-1.0.0/harmonizome.egg-info/requires.txt +10 -0
- harmonizome-1.0.0/harmonizome.egg-info/top_level.txt +1 -0
- harmonizome-1.0.0/pyproject.toml +94 -0
- harmonizome-1.0.0/requirements.txt +4 -0
- harmonizome-1.0.0/setup.cfg +4 -0
- harmonizome-1.0.0/tests/__init__.py +1 -0
- harmonizome-1.0.0/tests/test_file_based_annotations.py +12 -0
- harmonizome-1.0.0/tests/test_harmonizome.py +88 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
110
|
+
.pdm.toml
|
|
111
|
+
|
|
112
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
113
|
+
__pypackages__/
|
|
114
|
+
|
|
115
|
+
# Celery stuff
|
|
116
|
+
celerybeat-schedule
|
|
117
|
+
celerybeat.pid
|
|
118
|
+
|
|
119
|
+
# SageMath parsed files
|
|
120
|
+
*.sage.py
|
|
121
|
+
|
|
122
|
+
# Environments
|
|
123
|
+
.env
|
|
124
|
+
.venv
|
|
125
|
+
env/
|
|
126
|
+
venv/
|
|
127
|
+
ENV/
|
|
128
|
+
env.bak/
|
|
129
|
+
venv.bak/
|
|
130
|
+
|
|
131
|
+
# Spyder project settings
|
|
132
|
+
.spyderproject
|
|
133
|
+
.spyproject
|
|
134
|
+
|
|
135
|
+
# Rope project settings
|
|
136
|
+
.ropeproject
|
|
137
|
+
|
|
138
|
+
# mkdocs documentation
|
|
139
|
+
/site
|
|
140
|
+
|
|
141
|
+
# mypy
|
|
142
|
+
.mypy_cache/
|
|
143
|
+
.dmypy.json
|
|
144
|
+
dmypy.json
|
|
145
|
+
|
|
146
|
+
# Pyre type checker
|
|
147
|
+
.pyre/
|
|
148
|
+
|
|
149
|
+
# pytype static type analyzer
|
|
150
|
+
.pytype/
|
|
151
|
+
|
|
152
|
+
# Cython debug symbols
|
|
153
|
+
cython_debug/
|
|
154
|
+
|
|
155
|
+
# PyCharm
|
|
156
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
157
|
+
# be added to the global gitignore or merged into this project gitignore. For a PyCharm
|
|
158
|
+
# project, uncomment the following line:
|
|
159
|
+
#.idea/
|
|
160
|
+
|
|
161
|
+
# Harmonizome specific
|
|
162
|
+
# Downloaded datasets
|
|
163
|
+
ENCODE/
|
|
164
|
+
GTEx/
|
|
165
|
+
MSigDB/
|
|
166
|
+
# ... other dataset directories
|
|
167
|
+
|
|
168
|
+
# Temporary files
|
|
169
|
+
*.tmp
|
|
170
|
+
*.temp
|
|
171
|
+
|
|
172
|
+
# Cache
|
|
173
|
+
.harmonizome_cache/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shaurita D. Hutchins
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: harmonizome
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python client for the Harmonizome API - a resource for exploring gene sets and their attributes
|
|
5
|
+
Author-email: "Shaurita D. Hutchins" <shaurita.d.hutchins@gmail.com>
|
|
6
|
+
Maintainer-email: "Shaurita D. Hutchins" <shaurita.d.hutchins@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://maayanlab.cloud/Harmonizome/
|
|
9
|
+
Project-URL: Documentation, https://maayanlab.cloud/Harmonizome/
|
|
10
|
+
Project-URL: Repository, https://github.com/sdhutchins/harmonizome
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/sdhutchins/harmonizome/issues
|
|
12
|
+
Keywords: bioinformatics,genomics,gene-sets,harmonizome,api-client
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Requires-Python: >=3.7
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: numpy>=1.19.0
|
|
27
|
+
Requires-Dist: pandas>=1.3.0
|
|
28
|
+
Requires-Dist: scipy>=1.7.0
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-cov>=2.0; extra == "dev"
|
|
32
|
+
Requires-Dist: black>=21.0; extra == "dev"
|
|
33
|
+
Requires-Dist: isort>=5.0; extra == "dev"
|
|
34
|
+
Requires-Dist: flake8>=3.8; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# Harmonizome Python Client
|
|
38
|
+
|
|
39
|
+
A Python client for the [Harmonizome API](https://maayanlab.cloud/Harmonizome/), a resource for exploring gene sets and their attributes across multiple datasets.
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install harmonizome
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from harmonizome import Harmonizome
|
|
51
|
+
|
|
52
|
+
# Get all available datasets
|
|
53
|
+
datasets = Harmonizome.DATASETS
|
|
54
|
+
print(f"Available datasets: {len(datasets)}")
|
|
55
|
+
|
|
56
|
+
# Get information about a specific gene
|
|
57
|
+
gene_info = Harmonizome.get('gene', 'BRCA1')
|
|
58
|
+
print(f"Gene: {gene_info['name']}")
|
|
59
|
+
|
|
60
|
+
# Download data for a specific dataset
|
|
61
|
+
for filename in Harmonizome.download(['ENCODE']):
|
|
62
|
+
print(f"Downloaded: {filename}")
|
|
63
|
+
|
|
64
|
+
# Load data as pandas DataFrames
|
|
65
|
+
for df in Harmonizome.download_df(['ENCODE'], sparse=False):
|
|
66
|
+
print(f"DataFrame shape: {df.shape}")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Features
|
|
70
|
+
|
|
71
|
+
- **API Access**: Query genes, gene sets, attributes, and datasets
|
|
72
|
+
- **Data Download**: Download complete datasets (~30GB total)
|
|
73
|
+
- **DataFrame Support**: Load data directly as pandas DataFrames
|
|
74
|
+
- **Sparse Matrix Support**: Efficient handling of large sparse datasets
|
|
75
|
+
- **Python 2/3 Compatibility**: Works with both Python 2.X and 3.X
|
|
76
|
+
|
|
77
|
+
## API Reference
|
|
78
|
+
|
|
79
|
+
### Core Methods
|
|
80
|
+
|
|
81
|
+
#### `Harmonizome.get(entity, name=None, start_at=None)`
|
|
82
|
+
Retrieve entities from the Harmonizome API.
|
|
83
|
+
|
|
84
|
+
- `entity`: Type of entity ('gene', 'gene_set', 'attribute', etc.)
|
|
85
|
+
- `name`: Specific entity name (optional)
|
|
86
|
+
- `start_at`: Cursor position for pagination (optional)
|
|
87
|
+
|
|
88
|
+
#### `Harmonizome.download(datasets=None, what=None)`
|
|
89
|
+
Download dataset files to local directories.
|
|
90
|
+
|
|
91
|
+
- `datasets`: List of dataset names (defaults to all datasets)
|
|
92
|
+
- `what`: List of file types to download (defaults to all types)
|
|
93
|
+
|
|
94
|
+
#### `Harmonizome.download_df(datasets=None, what=None, sparse=False)`
|
|
95
|
+
Download and load data as pandas DataFrames.
|
|
96
|
+
|
|
97
|
+
- `datasets`: List of dataset names
|
|
98
|
+
- `what`: List of file types to download
|
|
99
|
+
- `sparse`: Use sparse matrices for memory efficiency
|
|
100
|
+
|
|
101
|
+
### Entity Types
|
|
102
|
+
|
|
103
|
+
- `DATASET`: Dataset information
|
|
104
|
+
- `GENE`: Gene information
|
|
105
|
+
- `GENE_SET`: Gene set collections
|
|
106
|
+
- `ATTRIBUTE`: Gene attributes
|
|
107
|
+
- `GENE_FAMILY`: Gene family classifications
|
|
108
|
+
- `NAMING_AUTHORITY`: Naming authorities
|
|
109
|
+
- `PROTEIN`: Protein information
|
|
110
|
+
- `RESOURCE`: Data resources
|
|
111
|
+
|
|
112
|
+
## Examples
|
|
113
|
+
|
|
114
|
+
### Querying Genes
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
# Get all genes (paginated)
|
|
118
|
+
genes = Harmonizome.get('gene')
|
|
119
|
+
print(f"Found {len(genes['entities'])} genes")
|
|
120
|
+
|
|
121
|
+
# Get next page
|
|
122
|
+
next_genes = Harmonizome.next(genes)
|
|
123
|
+
|
|
124
|
+
# Get specific gene
|
|
125
|
+
brca1 = Harmonizome.get('gene', 'BRCA1')
|
|
126
|
+
print(f"BRCA1 description: {brca1['description']}")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Downloading Datasets
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
# Download all data (requires confirmation)
|
|
133
|
+
for filename in Harmonizome.download():
|
|
134
|
+
print(f"Downloaded: {filename}")
|
|
135
|
+
|
|
136
|
+
# Download specific datasets
|
|
137
|
+
datasets = ['ENCODE', 'GTEx']
|
|
138
|
+
for filename in Harmonizome.download(datasets):
|
|
139
|
+
print(f"Downloaded: {filename}")
|
|
140
|
+
|
|
141
|
+
# Download specific file types
|
|
142
|
+
file_types = ['gene_attribute_matrix.txt.gz']
|
|
143
|
+
for filename in Harmonizome.download(['ENCODE'], file_types):
|
|
144
|
+
print(f"Downloaded: {filename}")
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Working with DataFrames
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
# Load as regular DataFrames
|
|
151
|
+
for df in Harmonizome.download_df(['ENCODE']):
|
|
152
|
+
print(f"DataFrame: {df.shape}")
|
|
153
|
+
print(f"Columns: {df.columns[:5].tolist()}")
|
|
154
|
+
break
|
|
155
|
+
|
|
156
|
+
# Load as sparse DataFrames (memory efficient)
|
|
157
|
+
for df in Harmonizome.download_df(['ENCODE'], sparse=True):
|
|
158
|
+
print(f"Sparse DataFrame: {df.shape}")
|
|
159
|
+
print(f"Memory usage: {df.memory_usage(deep=True).sum() / 1024**2:.2f} MB")
|
|
160
|
+
break
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Working with Gene Associations as DataFrames
|
|
164
|
+
|
|
165
|
+
You can fetch all associations for a gene and convert them directly to a pandas DataFrame for easy filtering and export:
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from harmonizome import Harmonizome
|
|
169
|
+
|
|
170
|
+
gene = "STAT3"
|
|
171
|
+
gene_data = Harmonizome.get_gene_data(gene, use_cache=True)
|
|
172
|
+
|
|
173
|
+
# Get all associations as a DataFrame
|
|
174
|
+
df = gene_data.to_dataframe()
|
|
175
|
+
|
|
176
|
+
# List all unique dataset names
|
|
177
|
+
print("Available datasets for this gene:")
|
|
178
|
+
for i, dataset in enumerate(df["dataset"].unique(), 1):
|
|
179
|
+
print(f"{i}. {dataset}")
|
|
180
|
+
|
|
181
|
+
# Select a dataset by name
|
|
182
|
+
selected_dataset = df["dataset"].unique()[0] # or set to any dataset name from the list
|
|
183
|
+
print(f"\nSelected dataset: {selected_dataset}")
|
|
184
|
+
|
|
185
|
+
# Filter associations for the selected dataset
|
|
186
|
+
dataset_df = df[df["dataset"] == selected_dataset]
|
|
187
|
+
print(dataset_df)
|
|
188
|
+
|
|
189
|
+
# Save to CSV
|
|
190
|
+
safe_name = selected_dataset.replace(" ", "_").replace("/", "_")
|
|
191
|
+
dataset_df.to_csv(f"{gene.lower()}_{safe_name}_associations.csv", index=False)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### API Reference: GeneData.to_dataframe()
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
gene_data.to_dataframe(dataset: str = None) -> pandas.DataFrame
|
|
198
|
+
```
|
|
199
|
+
- Returns a DataFrame with columns: 'gene_set', 'dataset', 'thresholdValue', 'standardizedValue'.
|
|
200
|
+
- Optionally filter by dataset name.
|
|
201
|
+
|
|
202
|
+
## File Types
|
|
203
|
+
|
|
204
|
+
The following file types are available for download:
|
|
205
|
+
|
|
206
|
+
- `gene_attribute_matrix.txt.gz`: Gene-attribute association matrix
|
|
207
|
+
- `gene_list_terms.txt.gz`: List of genes with terms
|
|
208
|
+
- `attribute_list_entries.txt.gz`: List of attributes with entries
|
|
209
|
+
|
|
210
|
+
## Requirements
|
|
211
|
+
|
|
212
|
+
- Python 3.7+
|
|
213
|
+
- numpy >= 1.19.0
|
|
214
|
+
- pandas >= 1.3.0
|
|
215
|
+
- scipy >= 1.7.0
|
|
216
|
+
|
|
217
|
+
## Development
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
# Install development dependencies
|
|
221
|
+
pip install -e .
|
|
222
|
+
|
|
223
|
+
# Run tests
|
|
224
|
+
pytest
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## License
|
|
228
|
+
|
|
229
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
230
|
+
|
|
231
|
+
## Citation
|
|
232
|
+
|
|
233
|
+
If you use this package in your research, please cite:
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
Rouillard AD, Gundersen GW, Fernandez NF, Wang Z, Monteiro CD, McDermott MG, Ma'ayan A. The harmonizome: a collection of processed datasets gathered to serve and mine knowledge about genes and proteins. Database (Oxford). 2016 Jul 3;2016:baw100. doi: 10.1093/database/baw100.
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Links
|
|
240
|
+
|
|
241
|
+
- [Harmonizome Website](https://maayanlab.cloud/Harmonizome/)
|
|
242
|
+
- [API Documentation](https://maayanlab.cloud/Harmonizome/api)
|
|
243
|
+
- [GitHub Repository](https://github.com/maayanlab/harmonizome)
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Harmonizome Python Client
|
|
2
|
+
|
|
3
|
+
A Python client for the [Harmonizome API](https://maayanlab.cloud/Harmonizome/), a resource for exploring gene sets and their attributes across multiple datasets.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install harmonizome
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from harmonizome import Harmonizome
|
|
15
|
+
|
|
16
|
+
# Get all available datasets
|
|
17
|
+
datasets = Harmonizome.DATASETS
|
|
18
|
+
print(f"Available datasets: {len(datasets)}")
|
|
19
|
+
|
|
20
|
+
# Get information about a specific gene
|
|
21
|
+
gene_info = Harmonizome.get('gene', 'BRCA1')
|
|
22
|
+
print(f"Gene: {gene_info['name']}")
|
|
23
|
+
|
|
24
|
+
# Download data for a specific dataset
|
|
25
|
+
for filename in Harmonizome.download(['ENCODE']):
|
|
26
|
+
print(f"Downloaded: {filename}")
|
|
27
|
+
|
|
28
|
+
# Load data as pandas DataFrames
|
|
29
|
+
for df in Harmonizome.download_df(['ENCODE'], sparse=False):
|
|
30
|
+
print(f"DataFrame shape: {df.shape}")
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
- **API Access**: Query genes, gene sets, attributes, and datasets
|
|
36
|
+
- **Data Download**: Download complete datasets (~30GB total)
|
|
37
|
+
- **DataFrame Support**: Load data directly as pandas DataFrames
|
|
38
|
+
- **Sparse Matrix Support**: Efficient handling of large sparse datasets
|
|
39
|
+
- **Python 2/3 Compatibility**: Works with both Python 2.X and 3.X
|
|
40
|
+
|
|
41
|
+
## API Reference
|
|
42
|
+
|
|
43
|
+
### Core Methods
|
|
44
|
+
|
|
45
|
+
#### `Harmonizome.get(entity, name=None, start_at=None)`
|
|
46
|
+
Retrieve entities from the Harmonizome API.
|
|
47
|
+
|
|
48
|
+
- `entity`: Type of entity ('gene', 'gene_set', 'attribute', etc.)
|
|
49
|
+
- `name`: Specific entity name (optional)
|
|
50
|
+
- `start_at`: Cursor position for pagination (optional)
|
|
51
|
+
|
|
52
|
+
#### `Harmonizome.download(datasets=None, what=None)`
|
|
53
|
+
Download dataset files to local directories.
|
|
54
|
+
|
|
55
|
+
- `datasets`: List of dataset names (defaults to all datasets)
|
|
56
|
+
- `what`: List of file types to download (defaults to all types)
|
|
57
|
+
|
|
58
|
+
#### `Harmonizome.download_df(datasets=None, what=None, sparse=False)`
|
|
59
|
+
Download and load data as pandas DataFrames.
|
|
60
|
+
|
|
61
|
+
- `datasets`: List of dataset names
|
|
62
|
+
- `what`: List of file types to download
|
|
63
|
+
- `sparse`: Use sparse matrices for memory efficiency
|
|
64
|
+
|
|
65
|
+
### Entity Types
|
|
66
|
+
|
|
67
|
+
- `DATASET`: Dataset information
|
|
68
|
+
- `GENE`: Gene information
|
|
69
|
+
- `GENE_SET`: Gene set collections
|
|
70
|
+
- `ATTRIBUTE`: Gene attributes
|
|
71
|
+
- `GENE_FAMILY`: Gene family classifications
|
|
72
|
+
- `NAMING_AUTHORITY`: Naming authorities
|
|
73
|
+
- `PROTEIN`: Protein information
|
|
74
|
+
- `RESOURCE`: Data resources
|
|
75
|
+
|
|
76
|
+
## Examples
|
|
77
|
+
|
|
78
|
+
### Querying Genes
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
# Get all genes (paginated)
|
|
82
|
+
genes = Harmonizome.get('gene')
|
|
83
|
+
print(f"Found {len(genes['entities'])} genes")
|
|
84
|
+
|
|
85
|
+
# Get next page
|
|
86
|
+
next_genes = Harmonizome.next(genes)
|
|
87
|
+
|
|
88
|
+
# Get specific gene
|
|
89
|
+
brca1 = Harmonizome.get('gene', 'BRCA1')
|
|
90
|
+
print(f"BRCA1 description: {brca1['description']}")
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Downloading Datasets
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
# Download all data (requires confirmation)
|
|
97
|
+
for filename in Harmonizome.download():
|
|
98
|
+
print(f"Downloaded: {filename}")
|
|
99
|
+
|
|
100
|
+
# Download specific datasets
|
|
101
|
+
datasets = ['ENCODE', 'GTEx']
|
|
102
|
+
for filename in Harmonizome.download(datasets):
|
|
103
|
+
print(f"Downloaded: {filename}")
|
|
104
|
+
|
|
105
|
+
# Download specific file types
|
|
106
|
+
file_types = ['gene_attribute_matrix.txt.gz']
|
|
107
|
+
for filename in Harmonizome.download(['ENCODE'], file_types):
|
|
108
|
+
print(f"Downloaded: {filename}")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Working with DataFrames
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
# Load as regular DataFrames
|
|
115
|
+
for df in Harmonizome.download_df(['ENCODE']):
|
|
116
|
+
print(f"DataFrame: {df.shape}")
|
|
117
|
+
print(f"Columns: {df.columns[:5].tolist()}")
|
|
118
|
+
break
|
|
119
|
+
|
|
120
|
+
# Load as sparse DataFrames (memory efficient)
|
|
121
|
+
for df in Harmonizome.download_df(['ENCODE'], sparse=True):
|
|
122
|
+
print(f"Sparse DataFrame: {df.shape}")
|
|
123
|
+
print(f"Memory usage: {df.memory_usage(deep=True).sum() / 1024**2:.2f} MB")
|
|
124
|
+
break
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Working with Gene Associations as DataFrames
|
|
128
|
+
|
|
129
|
+
You can fetch all associations for a gene and convert them directly to a pandas DataFrame for easy filtering and export:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from harmonizome import Harmonizome
|
|
133
|
+
|
|
134
|
+
gene = "STAT3"
|
|
135
|
+
gene_data = Harmonizome.get_gene_data(gene, use_cache=True)
|
|
136
|
+
|
|
137
|
+
# Get all associations as a DataFrame
|
|
138
|
+
df = gene_data.to_dataframe()
|
|
139
|
+
|
|
140
|
+
# List all unique dataset names
|
|
141
|
+
print("Available datasets for this gene:")
|
|
142
|
+
for i, dataset in enumerate(df["dataset"].unique(), 1):
|
|
143
|
+
print(f"{i}. {dataset}")
|
|
144
|
+
|
|
145
|
+
# Select a dataset by name
|
|
146
|
+
selected_dataset = df["dataset"].unique()[0] # or set to any dataset name from the list
|
|
147
|
+
print(f"\nSelected dataset: {selected_dataset}")
|
|
148
|
+
|
|
149
|
+
# Filter associations for the selected dataset
|
|
150
|
+
dataset_df = df[df["dataset"] == selected_dataset]
|
|
151
|
+
print(dataset_df)
|
|
152
|
+
|
|
153
|
+
# Save to CSV
|
|
154
|
+
safe_name = selected_dataset.replace(" ", "_").replace("/", "_")
|
|
155
|
+
dataset_df.to_csv(f"{gene.lower()}_{safe_name}_associations.csv", index=False)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### API Reference: GeneData.to_dataframe()
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
gene_data.to_dataframe(dataset: str = None) -> pandas.DataFrame
|
|
162
|
+
```
|
|
163
|
+
- Returns a DataFrame with columns: 'gene_set', 'dataset', 'thresholdValue', 'standardizedValue'.
|
|
164
|
+
- Optionally filter by dataset name.
|
|
165
|
+
|
|
166
|
+
## File Types
|
|
167
|
+
|
|
168
|
+
The following file types are available for download:
|
|
169
|
+
|
|
170
|
+
- `gene_attribute_matrix.txt.gz`: Gene-attribute association matrix
|
|
171
|
+
- `gene_list_terms.txt.gz`: List of genes with terms
|
|
172
|
+
- `attribute_list_entries.txt.gz`: List of attributes with entries
|
|
173
|
+
|
|
174
|
+
## Requirements
|
|
175
|
+
|
|
176
|
+
- Python 3.7+
|
|
177
|
+
- numpy >= 1.19.0
|
|
178
|
+
- pandas >= 1.3.0
|
|
179
|
+
- scipy >= 1.7.0
|
|
180
|
+
|
|
181
|
+
## Development
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
# Install development dependencies
|
|
185
|
+
pip install -e .
|
|
186
|
+
|
|
187
|
+
# Run tests
|
|
188
|
+
pytest
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## License
|
|
192
|
+
|
|
193
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
194
|
+
|
|
195
|
+
## Citation
|
|
196
|
+
|
|
197
|
+
If you use this package in your research, please cite:
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
Rouillard AD, Gundersen GW, Fernandez NF, Wang Z, Monteiro CD, McDermott MG, Ma'ayan A. The harmonizome: a collection of processed datasets gathered to serve and mine knowledge about genes and proteins. Database (Oxford). 2016 Jul 3;2016:baw100. doi: 10.1093/database/baw100.
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Links
|
|
204
|
+
|
|
205
|
+
- [Harmonizome Website](https://maayanlab.cloud/Harmonizome/)
|
|
206
|
+
- [API Documentation](https://maayanlab.cloud/Harmonizome/api)
|
|
207
|
+
- [GitHub Repository](https://github.com/maayanlab/harmonizome)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Examples package for harmonizome."""
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from harmonizome import Harmonizome
|
|
2
|
+
|
|
3
|
+
gene = "STAT3"
|
|
4
|
+
gene_data = Harmonizome.get_gene_data(gene, use_cache=True)
|
|
5
|
+
|
|
6
|
+
# Get all associations as a DataFrame
|
|
7
|
+
df = gene_data.to_dataframe()
|
|
8
|
+
|
|
9
|
+
# Example: select a dataset by name (replace with your choice)
|
|
10
|
+
selected_dataset = df["dataset"].unique()[0] # or set to any dataset name from the list
|
|
11
|
+
print(f"\nSelected dataset: {selected_dataset}")
|
|
12
|
+
|
|
13
|
+
# Filter associations for the selected dataset
|
|
14
|
+
dataset_df = df[df["dataset"] == selected_dataset]
|
|
15
|
+
print(dataset_df)
|
|
16
|
+
|
|
17
|
+
# Save to CSV
|
|
18
|
+
safe_name = selected_dataset.replace(" ", "_").replace("/", "_")
|
|
19
|
+
dataset_df.to_csv(f"{gene.lower()}_{safe_name}_associations.csv", index=False)
|
|
20
|
+
print(f"Saved {len(dataset_df)} associations for dataset '{selected_dataset}' to {gene.lower()}_{safe_name}_associations.csv")
|