Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

blosum

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blosum - npm Package Compare versions

Comparing version
1.1.3
to
1.2.0
+11
-11
PKG-INFO
Metadata-Version: 2.1
Name: blosum
Version: 1.1.3
Version: 1.2.0
Summary: A simple BLOSUM toolbox without dependencies.

@@ -15,6 +15,7 @@ Home-page: https://github.com/not-a-feature/blosum

Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires-Python: >=3.8
Requires-Python: >=3.7
Description-Content-Type: text/markdown

@@ -31,2 +32,3 @@ Provides-Extra: testing

![Download Badge](https://img.shields.io/pypi/dm/blosum.svg)
[![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg?style=flat)](http://bioconda.github.io/recipes/blosum/README.html)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

@@ -54,2 +56,6 @@

Or by conda:
```bash
conda install blosum
```
## How to use

@@ -67,3 +73,3 @@

### Custom Matrix
### Custom matrix
In addition, own matrices can be loaded. For this, the path is given as an argument.

@@ -88,3 +94,4 @@

### Getting Values.
### Getting values:
Once loaded the `matrix` behaves like a `defaultdict`.
To get a value use:

@@ -96,8 +103,2 @@

Or get the dictionary representation of the BLOSUM matrix.
```python
blosum_dict = dict(matrix)
```
If the key cannot be found, the default value is returned. It is `float("-inf")`.

@@ -128,2 +129,1 @@ It is possible to set a custom default score:

Go to [DEPENDENCIES.md](https://github.com/not-a-feature/blosum/blob/main/DEPENDENCIES.md) to see all dependencies and licenses.

@@ -8,2 +8,3 @@ ![blosum](https://github.com/not-a-feature/blosum/raw/main/blosum.png)

![Download Badge](https://img.shields.io/pypi/dm/blosum.svg)
[![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg?style=flat)](http://bioconda.github.io/recipes/blosum/README.html)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

@@ -31,2 +32,6 @@

Or by conda:
```bash
conda install blosum
```
## How to use

@@ -44,3 +49,3 @@

### Custom Matrix
### Custom matrix
In addition, own matrices can be loaded. For this, the path is given as an argument.

@@ -65,3 +70,4 @@

### Getting Values.
### Getting values:
Once loaded the `matrix` behaves like a `defaultdict`.
To get a value use:

@@ -73,8 +79,2 @@

Or get the dictionary representation of the BLOSUM matrix.
```python
blosum_dict = dict(matrix)
```
If the key cannot be found, the default value is returned. It is `float("-inf")`.

@@ -104,2 +104,2 @@ It is possible to set a custom default score:

In addition to packages included in Python 3, this piece of software uses 3rd-party software packages for development purposes that are not required in the published version.
Go to [DEPENDENCIES.md](https://github.com/not-a-feature/blosum/blob/main/DEPENDENCIES.md) to see all dependencies and licenses.
Go to [DEPENDENCIES.md](https://github.com/not-a-feature/blosum/blob/main/DEPENDENCIES.md) to see all dependencies and licenses.
[metadata]
name = blosum
version = 1.1.3
version = 1.2.0
description = A simple BLOSUM toolbox without dependencies.

@@ -15,2 +15,3 @@ long_description = file: README.md

Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8

@@ -23,3 +24,3 @@ Programming Language :: Python :: 3.9

blosum
python_requires = >=3.8
python_requires = >=3.7
package_dir =

@@ -26,0 +27,0 @@ =src

Metadata-Version: 2.1
Name: blosum
Version: 1.1.3
Version: 1.2.0
Summary: A simple BLOSUM toolbox without dependencies.

@@ -15,6 +15,7 @@ Home-page: https://github.com/not-a-feature/blosum

Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires-Python: >=3.8
Requires-Python: >=3.7
Description-Content-Type: text/markdown

@@ -31,2 +32,3 @@ Provides-Extra: testing

![Download Badge](https://img.shields.io/pypi/dm/blosum.svg)
[![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-brightgreen.svg?style=flat)](http://bioconda.github.io/recipes/blosum/README.html)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

@@ -54,2 +56,6 @@

Or by conda:
```bash
conda install blosum
```
## How to use

@@ -67,3 +73,3 @@

### Custom Matrix
### Custom matrix
In addition, own matrices can be loaded. For this, the path is given as an argument.

@@ -88,3 +94,4 @@

### Getting Values.
### Getting values:
Once loaded the `matrix` behaves like a `defaultdict`.
To get a value use:

@@ -96,8 +103,2 @@

Or get the dictionary representation of the BLOSUM matrix.
```python
blosum_dict = dict(matrix)
```
If the key cannot be found, the default value is returned. It is `float("-inf")`.

@@ -128,2 +129,1 @@ It is possible to set a custom default score:

Go to [DEPENDENCIES.md](https://github.com/not-a-feature/blosum/blob/main/DEPENDENCIES.md) to see all dependencies and licenses.

@@ -1,5 +0,3 @@

from ._blosum import BLOSUM
from ._blosum import BLOSUM, loadMatrix
__all__ = [
"BLOSUM",
]
__all__ = ["BLOSUM", "loadMatrix"]

@@ -12,5 +12,7 @@ """

from ._data import default_blosum
from collections import defaultdict
from typing import Dict, Union, DefaultDict
class BLOSUM:
class BLOSUM(defaultdict): # type: ignore
def __init__(self, n, default: float = float("-inf")):

@@ -38,100 +40,88 @@ """

if n in [45, 50, 62, 80, 90]:
self.matrix = default_blosum[n]
super().__init__(lambda: default, default_blosum[n])
# load custom matrix
elif isinstance(n, str):
# load custom matrix
self.__loadMatrix(n)
super().__init__(lambda: default, loadMatrix(n))
else:
raise (BaseException("Can't initate empty BLOSUM Object"))
raise (
BaseException(
f"""Unknown BLOSUM Number '{n}'. Choose n ϵ {{45,50,62,80,90}} or provide a path to a matrix."""
)
)
def __loadMatrix(self, path: str) -> None:
def __str__(self) -> str:
"""
Reads a Blosum matrix from file.
File in a format like:
https://www.ncbi.nlm.nih.gov/IEB/ToolBox/C_DOC/lxr/source/data/BLOSUM62
Magic method to allow BLOSUM object printing.
"""
return f"BLOSUM({self.n}, default={self.default}, {dict(self)}"
Input:
path: str, path to a file.
Returns:
blosumDict: Dictionary, Blosum-Dict
def __repr__(self) -> str:
"""
Magic method to allow printing of the BLOSUM representation.
"""
if self.default == float("-inf"):
d = "float('-inf')"
elif self.default == float("inf"):
d = "float('inf')"
else:
d = str(self.default)
with open(path, "r") as f:
content = f.readlines()
if self.n in [45, 50, 62, 80, 90]:
n = self.n
else:
n = f'"{self.n}"'
blosumDict = {}
return f"BLOSUM({n}, default={d})"
header = True
for line in content:
line = line.strip()
# Skip comments starting with #
if line.startswith("#"):
continue
def loadMatrix(path: str) -> Union[Dict[str, int], Dict[str, float]]:
"""
Reads a Blosum matrix from file.
File in a format like:
https://www.ncbi.nlm.nih.gov/IEB/ToolBox/C_DOC/lxr/source/data/BLOSUM62
linelist = line.split()
Input:
path: str, path to a file.
# Extract labels only once
if header:
labelslist = linelist
header = False
Returns:
blosumDict: Dictionary, The blosum dict
"""
# Check if all AA are covered
if not len(labelslist) == 25:
warn(UserWarning("Blosum matrix may not cover all amino-acids"))
continue
with open(path, "r") as f:
content = f.readlines()
if not len(linelist) == len(labelslist) + 1:
# Check if line has as may entries as labels
raise EOFError("Blosum file is missing values.")
blosumDict = {}
# Add Line/Label combination to dict
for index, lab in enumerate(labelslist, start=1):
blosumDict[f"{linelist[0]}{lab}"] = float(linelist[index])
header = True
for line in content:
line = line.strip()
# Check quadratic
if not len(blosumDict) == len(labelslist) ** 2:
raise EOFError("Blosum file is not quadratic.")
self.matrix = blosumDict
# Skip comments starting with #
if line.startswith("#"):
continue
def keys(self):
"""
Returns the keys of the blosum matrix
"""
return self.matrix.keys()
linelist = line.split()
def __getitem__(self, key: str) -> float:
"""
Magic method to get the BLOSUM score.
# Extract labels only once
if header:
labelslist = linelist
header = False
Input:
key: String, Combination of both amino-acids.
Ouput:
score: Float, value or default value.isinstance(self.n, )
"""
# Check if all AA are covered
if not len(labelslist) == 25:
warn(UserWarning("Blosum matrix may not cover all amino-acids"))
continue
try:
score = self.matrix[key]
except KeyError:
score = self.default
if not len(linelist) == len(labelslist) + 1:
# Check if line has as may entries as labels
raise EOFError("Blosum file is missing values.")
return score
# Add Line/Label combination to dict
for index, lab in enumerate(labelslist, start=1):
blosumDict[f"{linelist[0]}{lab}"] = float(linelist[index])
def __str__(self) -> str:
"""
Magic method to allow BLOSUM object printing.
"""
return f"BLOSUM {self.n}\n{self.matrix}"
def __repr__(self) -> str:
"""
Magic method to allow printing of the BLOSUM representation.
"""
d = "float('-inf')" if self.default == float("-inf") else self.default
if self.n in [45, 50, 62, 80, 90]:
n = self.n
else:
n = f'"{self.n}"'
return f"BLOSUM({n}, default={d})"
# Check quadratic
if not len(blosumDict) == len(labelslist) ** 2:
raise EOFError("Blosum file is not quadratic.")
return blosumDict