From 55ff60dac414abf7e3526e1bd772ed86798d9fa8 Mon Sep 17 00:00:00 2001 From: Clonder Date: Sun, 24 Nov 2024 14:59:12 +0100 Subject: [PATCH 1/3] Added library resourses and fixed configuration file --- pyproject.toml | 6 +----- requirements.txt | 3 +-- src/kinex/kinex.py | 10 ++++------ src/kinex/resources/__init__.py | 4 ++++ src/kinex/resources/config.json | 6 ++++++ 5 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 src/kinex/resources/config.json diff --git a/pyproject.toml b/pyproject.toml index 11aa38d..35296cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ dependencies = [ "scikit-learn", "umap-learn", "importlib-resources", - "tomli", + "requests", ] [project.optional-dependencies] @@ -29,10 +29,6 @@ dev = [ "furo" ] -[project.urls] -scoring_matrix_ser_thr = "https://zenodo.org/records/13964893/files/scoring_matrix_ser_thr_82k_sorted.csv.gz?download=1" -scoring_matrix_tyr = "https://zenodo.org/records/13964893/files/scoring_matrix_tyr_7k_sorted.csv.gz?download=1" - [tool.setuptools] package-dir = { "" = "src" } diff --git a/requirements.txt b/requirements.txt index e8e7d1f..cac5470 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,5 +6,4 @@ statsmodels plotly scikit-learn umap-learn -importlib-resources -tomli \ No newline at end of file +importlib-resources \ No newline at end of file diff --git a/src/kinex/kinex.py b/src/kinex/kinex.py index 1ad9651..6d66439 100644 --- a/src/kinex/kinex.py +++ b/src/kinex/kinex.py @@ -1,13 +1,12 @@ import bisect from collections import namedtuple from functools import reduce -import tomli import numpy as np import pandas as pd from kinex.functions import download_file_to_resource -from kinex.resources import get_pssm_ser_thr, get_pssm_tyr, get_scoring_matrix_ser_thr, get_scoring_matrix_tyr +from kinex.resources import get_pssm_ser_thr, get_pssm_tyr, get_scoring_matrix_ser_thr, get_scoring_matrix_tyr, get_configuration_file from kinex.score import Score from kinex.enrichment import Enrichment from kinex.sequence import get_sequence_object, SequenceType @@ -16,8 +15,7 @@ # Load the pyproject.toml file -with open("pyproject.toml", "rb") as f: - config = tomli.load(f) +config = get_configuration_file() class Kinex: """ @@ -89,7 +87,7 @@ def __init__(self, scoring_matrix_ser_thr = get_scoring_matrix_ser_thr() # Matrix is not provided and not found in the resources, download the default matrix if scoring_matrix_ser_thr is None: - scoring_matrix_ser_thr_url = config["project"]["urls"]["scoring_matrix_ser_thr"] + scoring_matrix_ser_thr_url = config["urls"]["scoring_matrix_ser_thr"] download_file_to_resource(scoring_matrix_ser_thr_url, 'default_scoring_matrix_ser_thr.csv.gz') scoring_matrix_ser_thr = get_scoring_matrix_ser_thr() @@ -97,7 +95,7 @@ def __init__(self, if scoring_matrix_tyr is None: scoring_matrix_tyr = get_scoring_matrix_tyr() if scoring_matrix_tyr is None: - scoring_matrix_tyr_url = config["project"]["urls"]["scoring_matrix_tyr"] + scoring_matrix_tyr_url = config["urls"]["scoring_matrix_tyr"] download_file_to_resource(scoring_matrix_tyr_url, 'default_scoring_matrix_tyr.csv.gz') scoring_matrix_tyr = get_scoring_matrix_tyr() diff --git a/src/kinex/resources/__init__.py b/src/kinex/resources/__init__.py index efd1a50..a2f0397 100644 --- a/src/kinex/resources/__init__.py +++ b/src/kinex/resources/__init__.py @@ -55,3 +55,7 @@ def get_scoring_matrix_tyr() -> pd.DataFrame: return pd.read_csv(file_path, compression='gzip') except FileNotFoundError: return None + +def get_configuration_file() -> dict: + with resources.files("kinex.resources").joinpath("config.json").open() as json_file: + return json.load(json_file) \ No newline at end of file diff --git a/src/kinex/resources/config.json b/src/kinex/resources/config.json new file mode 100644 index 0000000..f73e3bf --- /dev/null +++ b/src/kinex/resources/config.json @@ -0,0 +1,6 @@ +{ + "urls": { + "scoring_matrix_ser_thr": "https://zenodo.org/records/13964893/files/scoring_matrix_ser_thr_82k_sorted.csv.gz?download=1", + "scoring_matrix_tyr": "https://zenodo.org/records/13964893/files/scoring_matrix_tyr_7k_sorted.csv.gz?download=1" + } +} From 5a0734fc0c04cabf2f57c4c283a6dd9a0bf97ad9 Mon Sep 17 00:00:00 2001 From: Clonder Date: Sun, 24 Nov 2024 16:44:02 +0100 Subject: [PATCH 2/3] Changed the documentation for kinex init --- =0.12. | 65 ++++++++++++++++++++++++++++++++ docs/chapters/features/usage.rst | 49 ++++++++++++------------ 2 files changed, 90 insertions(+), 24 deletions(-) create mode 100644 =0.12. diff --git a/=0.12. b/=0.12. new file mode 100644 index 0000000..175742d --- /dev/null +++ b/=0.12. @@ -0,0 +1,65 @@ +Collecting esbonio + Downloading esbonio-0.16.5-py3-none-any.whl.metadata (4.7 kB) +Collecting sphinx (from esbonio) + Downloading sphinx-8.1.3-py3-none-any.whl.metadata (6.4 kB) +Requirement already satisfied: platformdirs in /home/clony/v/lib/python3.12/site-packages (from esbonio) (4.3.6) +Collecting pygls<2,>=1.1.0 (from esbonio) + Downloading pygls-1.3.1-py3-none-any.whl.metadata (4.7 kB) +Collecting pyspellchecker (from esbonio) + Downloading pyspellchecker-0.8.1-py3-none-any.whl.metadata (9.4 kB) +Collecting cattrs>=23.1.2 (from pygls<2,>=1.1.0->esbonio) + Downloading cattrs-24.1.2-py3-none-any.whl.metadata (8.4 kB) +Collecting lsprotocol==2023.0.1 (from pygls<2,>=1.1.0->esbonio) + Downloading lsprotocol-2023.0.1-py3-none-any.whl.metadata (2.2 kB) +Requirement already satisfied: attrs>=21.3.0 in /home/clony/v/lib/python3.12/site-packages (from lsprotocol==2023.0.1->pygls<2,>=1.1.0->esbonio) (24.2.0) +Collecting sphinxcontrib-applehelp>=1.0.7 (from sphinx->esbonio) + Downloading sphinxcontrib_applehelp-2.0.0-py3-none-any.whl.metadata (2.3 kB) +Collecting sphinxcontrib-devhelp>=1.0.6 (from sphinx->esbonio) + Downloading sphinxcontrib_devhelp-2.0.0-py3-none-any.whl.metadata (2.3 kB) +Collecting sphinxcontrib-htmlhelp>=2.0.6 (from sphinx->esbonio) + Downloading sphinxcontrib_htmlhelp-2.1.0-py3-none-any.whl.metadata (2.3 kB) +Collecting sphinxcontrib-jsmath>=1.0.1 (from sphinx->esbonio) + Downloading sphinxcontrib_jsmath-1.0.1-py2.py3-none-any.whl.metadata (1.4 kB) +Collecting sphinxcontrib-qthelp>=1.0.6 (from sphinx->esbonio) + Downloading sphinxcontrib_qthelp-2.0.0-py3-none-any.whl.metadata (2.3 kB) +Collecting sphinxcontrib-serializinghtml>=1.1.9 (from sphinx->esbonio) + Downloading sphinxcontrib_serializinghtml-2.0.0-py3-none-any.whl.metadata (2.4 kB) +Requirement already satisfied: Jinja2>=3.1 in /home/clony/v/lib/python3.12/site-packages (from sphinx->esbonio) (3.1.4) +Requirement already satisfied: Pygments>=2.17 in /home/clony/v/lib/python3.12/site-packages (from sphinx->esbonio) (2.18.0) +Collecting docutils<0.22,>=0.20 (from sphinx->esbonio) + Downloading docutils-0.21.2-py3-none-any.whl.metadata (2.8 kB) +Collecting snowballstemmer>=2.2 (from sphinx->esbonio) + Downloading snowballstemmer-2.2.0-py2.py3-none-any.whl.metadata (6.5 kB) +Requirement already satisfied: babel>=2.13 in /home/clony/v/lib/python3.12/site-packages (from sphinx->esbonio) (2.16.0) +Collecting alabaster>=0.7.14 (from sphinx->esbonio) + Downloading alabaster-1.0.0-py3-none-any.whl.metadata (2.8 kB) +Collecting imagesize>=1.3 (from sphinx->esbonio) + Downloading imagesize-1.4.1-py2.py3-none-any.whl.metadata (1.5 kB) +Requirement already satisfied: requests>=2.30.0 in /home/clony/v/lib/python3.12/site-packages (from sphinx->esbonio) (2.32.3) +Requirement already satisfied: packaging>=23.0 in /home/clony/v/lib/python3.12/site-packages (from sphinx->esbonio) (24.1) +Requirement already satisfied: MarkupSafe>=2.0 in /home/clony/v/lib/python3.12/site-packages (from Jinja2>=3.1->sphinx->esbonio) (3.0.2) +Requirement already satisfied: charset-normalizer<4,>=2 in /home/clony/v/lib/python3.12/site-packages (from requests>=2.30.0->sphinx->esbonio) (3.4.0) +Requirement already satisfied: idna<4,>=2.5 in /home/clony/v/lib/python3.12/site-packages (from requests>=2.30.0->sphinx->esbonio) (3.10) +Requirement already satisfied: urllib3<3,>=1.21.1 in /home/clony/v/lib/python3.12/site-packages (from requests>=2.30.0->sphinx->esbonio) (2.2.3) +Requirement already satisfied: certifi>=2017.4.17 in /home/clony/v/lib/python3.12/site-packages (from requests>=2.30.0->sphinx->esbonio) (2024.8.30) +Downloading esbonio-0.16.5-py3-none-any.whl (170 kB) +Downloading pygls-1.3.1-py3-none-any.whl (56 kB) +Downloading lsprotocol-2023.0.1-py3-none-any.whl (70 kB) +Downloading pyspellchecker-0.8.1-py3-none-any.whl (6.8 MB) + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.8/6.8 MB 41.7 MB/s eta 0:00:00 +Downloading sphinx-8.1.3-py3-none-any.whl (3.5 MB) + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.5/3.5 MB 56.8 MB/s eta 0:00:00 +Downloading alabaster-1.0.0-py3-none-any.whl (13 kB) +Downloading cattrs-24.1.2-py3-none-any.whl (66 kB) +Downloading docutils-0.21.2-py3-none-any.whl (587 kB) + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 587.4/587.4 kB 29.4 MB/s eta 0:00:00 +Downloading imagesize-1.4.1-py2.py3-none-any.whl (8.8 kB) +Downloading snowballstemmer-2.2.0-py2.py3-none-any.whl (93 kB) +Downloading sphinxcontrib_applehelp-2.0.0-py3-none-any.whl (119 kB) +Downloading sphinxcontrib_devhelp-2.0.0-py3-none-any.whl (82 kB) +Downloading sphinxcontrib_htmlhelp-2.1.0-py3-none-any.whl (98 kB) +Downloading sphinxcontrib_jsmath-1.0.1-py2.py3-none-any.whl (5.1 kB) +Downloading sphinxcontrib_qthelp-2.0.0-py3-none-any.whl (88 kB) +Downloading sphinxcontrib_serializinghtml-2.0.0-py3-none-any.whl (92 kB) +Installing collected packages: snowballstemmer, sphinxcontrib-serializinghtml, sphinxcontrib-qthelp, sphinxcontrib-jsmath, sphinxcontrib-htmlhelp, sphinxcontrib-devhelp, sphinxcontrib-applehelp, pyspellchecker, imagesize, docutils, cattrs, alabaster, sphinx, lsprotocol, pygls, esbonio +Successfully installed alabaster-1.0.0 cattrs-24.1.2 docutils-0.21.2 esbonio-0.16.5 imagesize-1.4.1 lsprotocol-2023.0.1 pygls-1.3.1 pyspellchecker-0.8.1 snowballstemmer-2.2.0 sphinx-8.1.3 sphinxcontrib-applehelp-2.0.0 sphinxcontrib-devhelp-2.0.0 sphinxcontrib-htmlhelp-2.1.0 sphinxcontrib-jsmath-1.0.1 sphinxcontrib-qthelp-2.0.0 sphinxcontrib-serializinghtml-2.0.0 diff --git a/docs/chapters/features/usage.rst b/docs/chapters/features/usage.rst index 0d90257..712b998 100644 --- a/docs/chapters/features/usage.rst +++ b/docs/chapters/features/usage.rst @@ -1,46 +1,47 @@ -Import package and initialise Kinex +Import Package and Initialize Kinex =================================== -1. Import kinex +1. **Import Kinex** .. code:: python - from kinex import Kinex + from kinex import Kinex -2. Read the scoring matrix +2. **Create a Kinex Object** + +- With Predefined Matrices: + +It will look in the resources to find the matrices. If it doesn't find them, it will download them and save them for future use. .. code:: python - scoring_matrix_ser_thr = pd.read_csv("https://zenodo.org/records/13964893/files/scoring_matrix_ser_thr_82k_sorted.csv.gz?download=1", compression="gzip") - scoring_matrix_tyr = pd.read_csv("https://zenodo.org/records/13964893/files/scoring_matrix_tyr_7k_sorted.csv.gz?download=1", compression="gzip") - scoring_matrix_ser_thr + kinex = Kinex() + +- With Your Custom Matrices: .. code:: python - AAK1 ACVR2A ... YSK4 ZAK - 0 -11.147481 -6.325340 ... -6.723077 -7.402360 - 1 -10.421859 -6.178601 ... -6.343452 -7.373478 - ... ... ... ... - 82753 8.074270 7.289390 ... 4.525527 4.837377 - 82754 8.623180 7.871226 ... 4.869195 5.062391 + scoring_matrix_ser_thr = pd.read_csv("path/to/scoring_matrix_ser_thr.csv") + scoring_matrix_tyr = pd.read_csv("path/to/scoring_matrix_tyr.csv") - [82755 rows x 303 columns] + kinex = Kinex(scoring_matrix_ser_thr, scoring_matrix_tyr) .. note:: - You can optionally save the scoring matrix locally for faster use in the future. + The matrix looks like this: .. code:: python - scoring_matrix_ser_thr.to_csv("scoring_matrix_ser_thr.csv") - scoring_matrix_tyr.to_csv("scoring_matrix_tyr.csv") + AAK1 ACVR2A ... YSK4 ZAK + 0 -11.147481 -6.325340 ... -6.723077 -7.402360 + 1 -10.421859 -6.178601 ... -6.343452 -7.373478 + ... ... ... ... + 82753 8.074270 7.289390 ... 4.525527 4.837377 + 82754 8.623180 7.871226 ... 4.869195 5.062391 - Or just download using the links: - `https://zenodo.org/records/13964893/files/scoring_matrix_ser_thr_82k_sorted.csv.gz?download=1 `_ - `https://zenodo.org/records/13964893/files/scoring_matrix_tyr_7k_sorted.csv.gz?download=1 `_ - -3. Create a kinex object +.. note:: -.. code:: python + Predefined matrices can be found here: - kinex = Kinex(scoring_matrix_ser_thr, scoring_matrix_tyr) + - `Scoring Matrix for Serine/Threonine `_ + - `Scoring Matrix for Tyrosine `_ From 65f8d19b533bb1e40c56ac353dd5374fc3d4b562 Mon Sep 17 00:00:00 2001 From: Clonder Date: Sun, 24 Nov 2024 18:36:07 +0100 Subject: [PATCH 3/3] Deleted file --- =0.12. | 65 ---------------------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 =0.12. diff --git a/=0.12. b/=0.12. deleted file mode 100644 index 175742d..0000000 --- a/=0.12. +++ /dev/null @@ -1,65 +0,0 @@ -Collecting esbonio - Downloading esbonio-0.16.5-py3-none-any.whl.metadata (4.7 kB) -Collecting sphinx (from esbonio) - Downloading sphinx-8.1.3-py3-none-any.whl.metadata (6.4 kB) -Requirement already satisfied: platformdirs in /home/clony/v/lib/python3.12/site-packages (from esbonio) (4.3.6) -Collecting pygls<2,>=1.1.0 (from esbonio) - Downloading pygls-1.3.1-py3-none-any.whl.metadata (4.7 kB) -Collecting pyspellchecker (from esbonio) - Downloading pyspellchecker-0.8.1-py3-none-any.whl.metadata (9.4 kB) -Collecting cattrs>=23.1.2 (from pygls<2,>=1.1.0->esbonio) - Downloading cattrs-24.1.2-py3-none-any.whl.metadata (8.4 kB) -Collecting lsprotocol==2023.0.1 (from pygls<2,>=1.1.0->esbonio) - Downloading lsprotocol-2023.0.1-py3-none-any.whl.metadata (2.2 kB) -Requirement already satisfied: attrs>=21.3.0 in /home/clony/v/lib/python3.12/site-packages (from lsprotocol==2023.0.1->pygls<2,>=1.1.0->esbonio) (24.2.0) -Collecting sphinxcontrib-applehelp>=1.0.7 (from sphinx->esbonio) - Downloading sphinxcontrib_applehelp-2.0.0-py3-none-any.whl.metadata (2.3 kB) -Collecting sphinxcontrib-devhelp>=1.0.6 (from sphinx->esbonio) - Downloading sphinxcontrib_devhelp-2.0.0-py3-none-any.whl.metadata (2.3 kB) -Collecting sphinxcontrib-htmlhelp>=2.0.6 (from sphinx->esbonio) - Downloading sphinxcontrib_htmlhelp-2.1.0-py3-none-any.whl.metadata (2.3 kB) -Collecting sphinxcontrib-jsmath>=1.0.1 (from sphinx->esbonio) - Downloading sphinxcontrib_jsmath-1.0.1-py2.py3-none-any.whl.metadata (1.4 kB) -Collecting sphinxcontrib-qthelp>=1.0.6 (from sphinx->esbonio) - Downloading sphinxcontrib_qthelp-2.0.0-py3-none-any.whl.metadata (2.3 kB) -Collecting sphinxcontrib-serializinghtml>=1.1.9 (from sphinx->esbonio) - Downloading sphinxcontrib_serializinghtml-2.0.0-py3-none-any.whl.metadata (2.4 kB) -Requirement already satisfied: Jinja2>=3.1 in /home/clony/v/lib/python3.12/site-packages (from sphinx->esbonio) (3.1.4) -Requirement already satisfied: Pygments>=2.17 in /home/clony/v/lib/python3.12/site-packages (from sphinx->esbonio) (2.18.0) -Collecting docutils<0.22,>=0.20 (from sphinx->esbonio) - Downloading docutils-0.21.2-py3-none-any.whl.metadata (2.8 kB) -Collecting snowballstemmer>=2.2 (from sphinx->esbonio) - Downloading snowballstemmer-2.2.0-py2.py3-none-any.whl.metadata (6.5 kB) -Requirement already satisfied: babel>=2.13 in /home/clony/v/lib/python3.12/site-packages (from sphinx->esbonio) (2.16.0) -Collecting alabaster>=0.7.14 (from sphinx->esbonio) - Downloading alabaster-1.0.0-py3-none-any.whl.metadata (2.8 kB) -Collecting imagesize>=1.3 (from sphinx->esbonio) - Downloading imagesize-1.4.1-py2.py3-none-any.whl.metadata (1.5 kB) -Requirement already satisfied: requests>=2.30.0 in /home/clony/v/lib/python3.12/site-packages (from sphinx->esbonio) (2.32.3) -Requirement already satisfied: packaging>=23.0 in /home/clony/v/lib/python3.12/site-packages (from sphinx->esbonio) (24.1) -Requirement already satisfied: MarkupSafe>=2.0 in /home/clony/v/lib/python3.12/site-packages (from Jinja2>=3.1->sphinx->esbonio) (3.0.2) -Requirement already satisfied: charset-normalizer<4,>=2 in /home/clony/v/lib/python3.12/site-packages (from requests>=2.30.0->sphinx->esbonio) (3.4.0) -Requirement already satisfied: idna<4,>=2.5 in /home/clony/v/lib/python3.12/site-packages (from requests>=2.30.0->sphinx->esbonio) (3.10) -Requirement already satisfied: urllib3<3,>=1.21.1 in /home/clony/v/lib/python3.12/site-packages (from requests>=2.30.0->sphinx->esbonio) (2.2.3) -Requirement already satisfied: certifi>=2017.4.17 in /home/clony/v/lib/python3.12/site-packages (from requests>=2.30.0->sphinx->esbonio) (2024.8.30) -Downloading esbonio-0.16.5-py3-none-any.whl (170 kB) -Downloading pygls-1.3.1-py3-none-any.whl (56 kB) -Downloading lsprotocol-2023.0.1-py3-none-any.whl (70 kB) -Downloading pyspellchecker-0.8.1-py3-none-any.whl (6.8 MB) - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.8/6.8 MB 41.7 MB/s eta 0:00:00 -Downloading sphinx-8.1.3-py3-none-any.whl (3.5 MB) - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.5/3.5 MB 56.8 MB/s eta 0:00:00 -Downloading alabaster-1.0.0-py3-none-any.whl (13 kB) -Downloading cattrs-24.1.2-py3-none-any.whl (66 kB) -Downloading docutils-0.21.2-py3-none-any.whl (587 kB) - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 587.4/587.4 kB 29.4 MB/s eta 0:00:00 -Downloading imagesize-1.4.1-py2.py3-none-any.whl (8.8 kB) -Downloading snowballstemmer-2.2.0-py2.py3-none-any.whl (93 kB) -Downloading sphinxcontrib_applehelp-2.0.0-py3-none-any.whl (119 kB) -Downloading sphinxcontrib_devhelp-2.0.0-py3-none-any.whl (82 kB) -Downloading sphinxcontrib_htmlhelp-2.1.0-py3-none-any.whl (98 kB) -Downloading sphinxcontrib_jsmath-1.0.1-py2.py3-none-any.whl (5.1 kB) -Downloading sphinxcontrib_qthelp-2.0.0-py3-none-any.whl (88 kB) -Downloading sphinxcontrib_serializinghtml-2.0.0-py3-none-any.whl (92 kB) -Installing collected packages: snowballstemmer, sphinxcontrib-serializinghtml, sphinxcontrib-qthelp, sphinxcontrib-jsmath, sphinxcontrib-htmlhelp, sphinxcontrib-devhelp, sphinxcontrib-applehelp, pyspellchecker, imagesize, docutils, cattrs, alabaster, sphinx, lsprotocol, pygls, esbonio -Successfully installed alabaster-1.0.0 cattrs-24.1.2 docutils-0.21.2 esbonio-0.16.5 imagesize-1.4.1 lsprotocol-2023.0.1 pygls-1.3.1 pyspellchecker-0.8.1 snowballstemmer-2.2.0 sphinx-8.1.3 sphinxcontrib-applehelp-2.0.0 sphinxcontrib-devhelp-2.0.0 sphinxcontrib-htmlhelp-2.1.0 sphinxcontrib-jsmath-1.0.1 sphinxcontrib-qthelp-2.0.0 sphinxcontrib-serializinghtml-2.0.0