Skip to content

Commit

Permalink
Merge pull request #2 from David-Araripe/dev
Browse files Browse the repository at this point in the history
Add development changes for a new release
  • Loading branch information
David-Araripe authored Jul 19, 2024
2 parents 54a8951 + 6ff8c09 commit 57a1e38
Show file tree
Hide file tree
Showing 9 changed files with 1,402 additions and 983 deletions.
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
[![GitHub Actions](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2FDavid-Araripe%2FUniProtMapper%2Fbadge%3Fref%3Dmaster&style=flat-square)](https://actions-badge.atrox.dev/David-Araripe/UniProtMapper/goto?ref=master)
[![Downloads:PyPI](https://img.shields.io/pypi/dm/uniprot-id-mapper?style=flat-square)](https://pypi.org/project/uniprot-id-mapper/)

# UniProtMapper
# UniProtMapper <img align="left" width="40" height="40" src="https://raw.githubusercontent.com/whitead/protein-emoji/main/src/protein-72-color.svg">

A Python wrapper for UniProt's [Retrieve/ID Mapping](https://www.uniprot.org/id-mapping) RESTful API. This package supports the following functionalities:

1. Map (almost) any UniProt [cross-referenced IDs](https://github.com/David-Araripe/UniProtMapper/blob/master/src/UniProtMapper/resources/uniprot_mapping_dbs.json) to other identifiers & vice-versa;
2. Programmatically retrieve any of the supported [return fields](https://www.uniprot.org/help/return_fields) from both UniProt-SwissProt and UniProt-TrEMBL (unreviewed) databases;
2. Programmatically retrieve any of the supported [return](https://www.uniprot.org/help/return_fields) and [cross-reference fields](https://www.uniprot.org/help/return_fields_databases) from both UniProt-SwissProt and UniProt-TrEMBL (unreviewed) databases;

For these, check [Example 1](#example-1-mapping-ids) and [Example 2](#example-2-retrieving-information) below. Both functionalities can also be accessed through the CLI. For more information, check [CLI](#cli).
For these, check [Example 1](#example-1-mapping-ids) and [Example 2](#example-2-retrieving-information) below. Both functionalities can also be accessed through the CLI. For more information, check [CLI](#-cli).

## Installation
## 📦 Installation

From PyPI:
``` Shell
Expand All @@ -32,7 +32,7 @@ git clone https://github.com/David-Araripe/UniProtMapper
cd UniProtMapper
python -m pip install .
```
# Usage
# 🛠️ Usage
## Example 1: Mapping IDs
To map IDs, the user can either call the object directly or use the `get` method to obtain the response. The different identifiers that are used by the API are designated by the `from_db` and `to_db` parameters. For example:

Expand All @@ -59,7 +59,7 @@ Where failed corresponds to a list of the identifiers that failed to be mapped a

## Example 2: Retrieving information

The supported [return fields](https://www.uniprot.org/help/return_fields) are both accessible through UniProt's website or by the property `.fields_table`. For example:
The supported [return](https://www.uniprot.org/help/return_fields) and [cross-reference fields](https://www.uniprot.org/help/return_fields_databases) are both accessible through UniProt's website or by the attribute `ProtMapper.fields_table`. For example:

```Python
from UniProtMapper import ProtMapper
Expand All @@ -68,13 +68,13 @@ mapper = ProtMapper()
df = mapper.fields_table
df.head()
```
| | Label | Legacy Returned Field | Returned Field | Field Type |
|---:|:---------------------|:------------------------|:-----------------|:-----------------|
| 0 | Entry | id | accession | Names & Taxonomy |
| 1 | Entry Name | entry name | id | Names & Taxonomy |
| 2 | Gene Names | genes | gene_names | Names & Taxonomy |
| 3 | Gene Names (primary) | genes(PREFERRED) | gene_primary | Names & Taxonomy |
| 4 | Gene Names (synonym) | genes(ALTERNATIVE) | gene_synonym | Names & Taxonomy |
| | label | returned_field | field_type | has_full_version | type |
|---:|:---------------------|:-----------------|:-----------------|:-------------------|:--------------|
| 0 | Entry | accession | Names & Taxonomy | yes | uniprot_field |
| 1 | Entry Name | id | Names & Taxonomy | yes | uniprot_field |
| 2 | Gene Names | gene_names | Names & Taxonomy | yes | uniprot_field |
| 3 | Gene Names (primary) | gene_primary | Names & Taxonomy | yes | uniprot_field |
| 4 | Gene Names (synonym) | gene_synonym | Names & Taxonomy | yes | uniprot_field |

To retrieve information, the user can either call the object directly or use the `get` method to obtain the response. For example:

Expand All @@ -86,7 +86,7 @@ result, failed = mapper(["Q02880"])
>>> Fetched: 1 / 1
```

Custom returned fields can be retrieved by passing a list of fields to the `fields` parameter. These fields need to be within `UniProtRetriever.fields_table["Returned_Field"]` and will be returned with columns named as their respective `Label`.
Custom returned fields can be retrieved by passing a list of fields to the `fields` parameter. These fields need to be within `UniProtRetriever.fields_table["returned_field"]` and will be returned with columns named as their respective `Label`.

The object already has a list of default fields under `self.default_fields`, but these are ignored if the parameter `fields` is passed.

Expand All @@ -95,7 +95,7 @@ fields = ["accession", "organism_name", "structure_3d"]
result, failed = mapper.get(["Q02880"], fields=fields)
```

# CLI
# 💻 CLI

The package also comes with a CLI that can be used to map IDs and retrieve information. To map IDs, the user can use the `protmap` command, accessible after installation. Here is a list of the available arguments, shown by `protmap -h`:

Expand Down Expand Up @@ -135,4 +135,9 @@ optional arguments:
Usage example, retrieving default fields from `<pkg_path>/resources/cli_return_fields.txt`:
<p align="center">
<img src="https://github.com/David-Araripe/UniProtMapper/blob/master/figures/cli_example_fig.png?raw=true" alt="Image displaying the output of UniProtMapper's CLI, protmap"/>
</p>
</p>

# 👏🏼 Credits:

- [UniProt](https://www.uniprot.org/) for providing the API and the amazing database;
- [Andrew White and the University of Rochester](https://github.com/whitead/protein-emoji) for the protein emoji;
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=61.0"]
requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2", "wheel"]
build-backend = "setuptools.build_meta"

[project]
Expand All @@ -16,6 +16,7 @@ classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.9",
Expand All @@ -42,6 +43,9 @@ protmap = "UniProtMapper.cli:main"
[tool.setuptools.dynamic]
version = {attr = "UniProtMapper.__version__"}

[tool.setuptools_scm]
write_to = "src/UniProtMapper/_version.py"

[tool.ruff]
line-length = 88
target-version = "py39"
Expand Down
8 changes: 6 additions & 2 deletions src/UniProtMapper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-
"""A Python wrapper for the UniProt id-mapping RESTful API: https://www.uniprot.org/id-mapping"""
try:
from .api import ProtMapper # noqa: F401
except ImportError: # when installing the package with setuptools_scm
pass

from .api import ProtMapper # noqa: F401
from .version_helper import get_version

__version__ = "1.1.1"
__version__ = get_version()
4 changes: 2 additions & 2 deletions src/UniProtMapper/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ def get(
fields = self.default_fields
else:
fields = np.char.lower(np.array(fields))
if not np.isin(fields, self.fields_table["Returned_Field"]).all():
if not np.isin(fields, self.fields_table["returned_field"]).all():
raise ValueError(
"Invalid fields. Valid fields are: "
f"{self.fields_table['Returned_Field'].values}"
f"{self.fields_table['returned_field'].values}"
)
if to_db not in ["UniProtKB-Swiss-Prot", "UniProtKB"]:
if fields is not None:
Expand Down
Loading

0 comments on commit 57a1e38

Please sign in to comment.