Griddify
Redistribute tabular data into a grid for easy visualization and image-based deep learning. This library is greatly inspired by the excellent MolMap library.
Installation
git clone https://github.com/ersilia-os/griddify.git
cd griddify
pip install -e .
Note that you may have to install a C++ compiler. You can just use conda for that:
conda install -c conda-forge cxx-compiler
Step by step
Get a multidimensional dataset and preprocess it
In this example, we will use a dataset of 200 physicochemical descriptors calculated for about 10k compounds. You can get these data with the following command.
from griddify import datasets
data = datasets.get_compound_descriptors()
It is important that you preprocess your data (impute missing values, normalize, etc.). We provide functionality to do so.
from griddify import Preprocessing
pp = Preprocessing()
pp.fit(data)
data = pp.transform(data)
Create a 2D cloud of data features
Start by calculating distances between features.
from griddify import FeatureDistances
fd = FeatureDistances(metric="cosine").calculate(data)
You can now obtain a 2D cloud of your data features. By default, UMAP is used.
from griddify import Tabular2Cloud
tc = Tabular2Cloud()
tc.fit(fd)
Xc = tc.transform(fd)
It is always good to inspect the resulting projection. The cloud contains as many points as features exist in your dataset.
from griddify.plots import cloud_plot
cloud_plot(Xc)
Rearrange the 2D cloud onto a grid
Distribute cloud points on a grid using a linear assignment algorithm.
from griddify import Cloud2Grid
cg = Cloud2Grid()
cg.fit(Xc)
Xg = cg.transform(Xc)
You can check the rearrangement with an arrows plot.
from griddify.plots import arrows_plot
arrows_plot(Xc, Xg)
To continue with the next steps, it is actually more convenient to get mappings as integers. The following method gives you the size of the grid as well.
mappings, side = cg.get_mappings(Xc)
Rearrange your flat data points into grids
Let's go back to the original tabular data. We want to transform the input data, where each data sample is represented with a one-dimensional array, into an output data where each sample is represented with an image (i.e. a two-dimensional grid). Please ensure that data are normalize or scaled.
from griddify import Flat2Grid
fg = Flat2Grid(mappings, side)
Xi = fg.transform(data)
Explore one sample.
from griddify.plots import grid_plot
grid_plot(Xi[0])
Full pipeline
You can run the full pipeline described above in only a few lines of code.
from griddify import datasets
from griddify import Griddify
data = datasets.get_compound_descriptors()
gf = Griddify(preprocess=True)
gf.fit(data)
Xi = gf.transform(data)
You can find more examples as Jupyter Notebooks in the notebooks folder.
Learn more
The Ersilia Open Source Initiative is on a mission to strenghten research capacity in low income countries. Please reach out to us if you want to contribute: hello@ersilia.io
Metadata
Release files for griddify 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| griddify-0.0.2.tar.gz | 21.0 kB | Without provenance | Details for griddify-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| griddify-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for griddify-0.0.2-py3-none-any.whl |
Total release size: 41.8 kB
Release files / griddify-0.0.2.tar.gz
| Download URL | griddify-0.0.2.tar.gz |
|---|---|
| Size | 21.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6f875b1994d9041da87c14ed3d92b294840f9f2c1a5436164ad8eb9e659b51b
|
|
BLAKE2b-256 checksum How to use checksums |
18b236c593e650b7de612c27c45d8dd2e36dd0faa92f5ed52f04d60ec1a1cf9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.8
|
Release files / griddify-0.0.2-py3-none-any.whl
| Download URL | griddify-0.0.2-py3-none-any.whl |
|---|---|
| Size | 20.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
95dc6efa546ae7cedd9a54aa870e5c8b75e09e9d049e39e415abc5b2908b349c
|
|
BLAKE2b-256 checksum How to use checksums |
4f9624c314535a9376b5e91660ffc36e148d3416f32f038d8637ce0a147ce7d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.8
|
Security for griddify 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.