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.2.2
to
2.0.1
+82
tests/test_blosum.py
# Testing BLOSUM Handling
import blosum as bl
import pytest
from os import path
f = float("-inf")
@pytest.mark.parametrize(
"blosum_number,expected",
[
(45, [0, 1, -2, -5, 3, 1, -3, -5, -2, -2, 1, -5, f, f, f, f]),
(50, [0, 1, -1, -5, 3, 2, -4, -5, -3, -1, 1, -5, f, f, f, f]),
(62, [0, 0, -1, -4, 2, 1, -3, -4, -3, -2, 1, -4, f, f, f, f]),
(90, [0, 1, -2, -6, 2, 1, -4, -6, -4, -3, 0, -6, f, f, f, f]),
],
)
def test_blosum(blosum_number, expected):
bm = bl.BLOSUM(blosum_number)
get_test = []
for a in ["H", "K", "W", "U"]:
for b in ["R", "Q", "F", "*"]:
get_test.append(bm[a][b])
assert get_test == expected
def test_blosum_default():
bm = bl.BLOSUM(62, default=-99)
assert bm["non"]["existent"] == -99 # test default value
assert dict(bm["nonexistent"]) == dict() # test default value
assert bm["H"]["F"] == -1 # test real value
@pytest.mark.filterwarnings("ignore:Blosum")
def test_blosum_custom_file():
fp = path.join(path.dirname(__file__), "test.blosum")
bm = bl.BLOSUM(fp)
labels = ["A", "R", "N", "D"]
s = sum([bm[a][b] for b in labels for a in labels])
assert s == 19
@pytest.mark.filterwarnings("ignore:Blosum")
def test_blosum_custom_file_with_comments():
fp = path.join(path.dirname(__file__), "comments.blosum")
bm = bl.BLOSUM(fp)
labels = ["A", "R", "N", "D"]
s = sum([bm[a][b] for b in labels for a in labels])
assert s == 17
@pytest.mark.xfail
def test_blosum_invalid_file():
fp = path.join(path.dirname(__file__), "fail.blosum")
bm = bl.BLOSUM(fp)
bm["A"]["B"]
@pytest.mark.xfail
def test_blosum_invalid_file2():
fp = path.join(path.dirname(__file__), "fail2.blosum")
bm = bl.BLOSUM(fp)
bm["A"]["B"]
@pytest.mark.xfail
def test_blosum_empty():
bm = bl.BLOSUM(None)
bm["A"]["B"]
def test_magic_repr():
assert repr(bl.BLOSUM(62)) == "BLOSUM(62, default=float('-inf'))"
assert repr(bl.BLOSUM(62, default=float("inf"))) == "BLOSUM(62, default=float('inf'))"
assert repr(bl.BLOSUM(62, default=0)) == "BLOSUM(62, default=0)"
fp = path.join(path.dirname(__file__), "test.blosum")
assert repr(bl.BLOSUM(fp, default=0)) == f'BLOSUM("{fp}", default=0)'
# Testing BLOSUM Handling
import blosum as bl
import pytest
from os import path
f = float("-inf")
@pytest.mark.filterwarnings("ignore:Blosum")
def test_loadMatrix_eq_blosum():
fp = path.join(path.dirname(__file__), "test.blosum")
bm = dict(bl.BLOSUM(fp))
assert bm == bl.loadMatrix(fp)
+15
-7
Metadata-Version: 2.1
Name: blosum
Version: 1.2.2
Version: 2.0.1
Summary: A simple BLOSUM toolbox without dependencies.

@@ -41,3 +41,3 @@ Home-page: https://github.com/not-a-feature/blosum

`blosum` offers a robust and easy-to-expand implementation without relying on third-party libraries.
`blosum` offers a robust and easy-to-expand implementation without relying on third-party libraries.

@@ -63,3 +63,3 @@

### Default BLOSUM
### Default BLOSUM
This package provides the most commonly used BLOSUM matrices.

@@ -72,3 +72,4 @@ You can choose from BLOSUM 45, 50, 62, 80 and 90.

matrix = bl.BLOSUM(62)
```
val = matrix["A"]["Y"]
```

@@ -81,2 +82,3 @@ ### Custom matrix

matrix = bl.BLOSUM("path/to/blosum.file")
val = matrix["A"]["Y"]
```

@@ -101,6 +103,12 @@

```python
val = matrix["AY"]
val = matrix["A"]["Y"]
```
To get a defaultdict of the row with a given key use:
If the key cannot be found, the default value is returned. It is `float("-inf")`.
```python
val_dict = matrix["A"]
```
If the key cannot be found, the default value `float("-inf")` is returned.
It is possible to set a custom default score:

@@ -113,3 +121,3 @@ ```python

```
Copyright (C) 2022 by Jules Kreuer - @not_a_feature
Copyright (C) 2023 by Jules Kreuer - @not_a_feature
This piece of software is published unter the GNU General Public License v3.0

@@ -116,0 +124,0 @@ TLDR:

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

`blosum` offers a robust and easy-to-expand implementation without relying on third-party libraries.
`blosum` offers a robust and easy-to-expand implementation without relying on third-party libraries.

@@ -39,3 +39,3 @@

### Default BLOSUM
### Default BLOSUM
This package provides the most commonly used BLOSUM matrices.

@@ -48,3 +48,4 @@ You can choose from BLOSUM 45, 50, 62, 80 and 90.

matrix = bl.BLOSUM(62)
```
val = matrix["A"]["Y"]
```

@@ -57,2 +58,3 @@ ### Custom matrix

matrix = bl.BLOSUM("path/to/blosum.file")
val = matrix["A"]["Y"]
```

@@ -77,6 +79,12 @@

```python
val = matrix["AY"]
val = matrix["A"]["Y"]
```
To get a defaultdict of the row with a given key use:
If the key cannot be found, the default value is returned. It is `float("-inf")`.
```python
val_dict = matrix["A"]
```
If the key cannot be found, the default value `float("-inf")` is returned.
It is possible to set a custom default score:

@@ -89,3 +97,3 @@ ```python

```
Copyright (C) 2022 by Jules Kreuer - @not_a_feature
Copyright (C) 2023 by Jules Kreuer - @not_a_feature
This piece of software is published unter the GNU General Public License v3.0

@@ -92,0 +100,0 @@ TLDR:

[metadata]
name = blosum
version = 1.2.2
version = 2.0.1
description = A simple BLOSUM toolbox without dependencies.

@@ -5,0 +5,0 @@ long_description = file: README.md

Metadata-Version: 2.1
Name: blosum
Version: 1.2.2
Version: 2.0.1
Summary: A simple BLOSUM toolbox without dependencies.

@@ -41,3 +41,3 @@ Home-page: https://github.com/not-a-feature/blosum

`blosum` offers a robust and easy-to-expand implementation without relying on third-party libraries.
`blosum` offers a robust and easy-to-expand implementation without relying on third-party libraries.

@@ -63,3 +63,3 @@

### Default BLOSUM
### Default BLOSUM
This package provides the most commonly used BLOSUM matrices.

@@ -72,3 +72,4 @@ You can choose from BLOSUM 45, 50, 62, 80 and 90.

matrix = bl.BLOSUM(62)
```
val = matrix["A"]["Y"]
```

@@ -81,2 +82,3 @@ ### Custom matrix

matrix = bl.BLOSUM("path/to/blosum.file")
val = matrix["A"]["Y"]
```

@@ -101,6 +103,12 @@

```python
val = matrix["AY"]
val = matrix["A"]["Y"]
```
To get a defaultdict of the row with a given key use:
If the key cannot be found, the default value is returned. It is `float("-inf")`.
```python
val_dict = matrix["A"]
```
If the key cannot be found, the default value `float("-inf")` is returned.
It is possible to set a custom default score:

@@ -113,3 +121,3 @@ ```python

```
Copyright (C) 2022 by Jules Kreuer - @not_a_feature
Copyright (C) 2023 by Jules Kreuer - @not_a_feature
This piece of software is published unter the GNU General Public License v3.0

@@ -116,0 +124,0 @@ TLDR:

@@ -14,2 +14,4 @@ LICENSE

src/blosum.egg-info/requires.txt
src/blosum.egg-info/top_level.txt
src/blosum.egg-info/top_level.txt
tests/test_blosum.py
tests/test_loadMatrix.py

@@ -17,3 +17,3 @@ """

class BLOSUM(defaultdict): # type: ignore
def __init__(self, n, default: float = float("-inf")):
def __init__(self, n: Union[int, str], default: float = float("-inf")):
"""

@@ -23,12 +23,15 @@ Object to easily access a blosum matrix.

Input:
Either n ϵ {45,50,62,80,90} or path
Input
-----
Either n ϵ {45,50,62,80,90} or path
n: Int, which BLOSUM Matrix to use.
Choice between: 45,50,62,80 and 90
Data gathered from https://www.ncbi.nlm.nih.gov/IEB/ToolBox/C_DOC/lxr/source/data/
n: int, which BLOSUM Matrix to use.
Choice between: 45,50,62,80 and 90
Data gathered from https://www.ncbi.nlm.nih.gov/IEB/ToolBox/C_DOC/lxr/source/data/
path: String, path to a Blosum matrix.
File in a format like:
https://www.ncbi.nlm.nih.gov/IEB/ToolBox/C_DOC/lxr/source/data/BLOSUM62
path: string, path to a Blosum matrix.
File in a format like:
https://www.ncbi.nlm.nih.gov/IEB/ToolBox/C_DOC/lxr/source/data/BLOSUM62
default: float, default -inf
"""

@@ -40,8 +43,11 @@

# Using default matrix
if n in [45, 50, 62, 80, 90]:
super().__init__(lambda: default, default_blosum[n])
if isinstance(n, int) and n in [45, 50, 62, 80, 90]:
matrix = {}
for k, v in default_blosum[n].items():
matrix[k] = defaultdict(lambda: default, v)
super().__init__(lambda: defaultdict(lambda: default), matrix)
# load custom matrix
elif isinstance(n, str):
super().__init__(lambda: default, loadMatrix(n))
super().__init__(lambda: defaultdict(lambda: default), loadMatrix(n))
else:

@@ -79,3 +85,6 @@ raise (

def loadMatrix(path: str) -> Union[Dict[str, int], Dict[str, float]]:
def loadMatrix(
path: str,
default: float = float("-inf"),
) -> DefaultDict[str, DefaultDict[str, float]]:
"""

@@ -86,6 +95,9 @@ Reads a Blosum matrix from file.

Input:
Input
-----
path: str, path to a file.
default: float, default value "-inf"
Returns:
Returns
-------
blosumDict: Dictionary, The blosum dict

@@ -97,3 +109,5 @@ """

blosumDict = {}
blosumDict: DefaultDict[str, DefaultDict[str, float]] = defaultdict(
lambda: defaultdict(lambda: default)
)

@@ -126,7 +140,8 @@ header = True

for index, lab in enumerate(labelslist, start=1):
blosumDict[f"{linelist[0]}{lab}"] = float(linelist[index])
blosumDict[linelist[0]][lab] = float(linelist[index])
# Check quadratic
if not len(blosumDict) == len(labelslist) ** 2:
if not len(blosumDict) == len(labelslist):
raise EOFError("Blosum file is not quadratic.")
return blosumDict

Sorry, the diff of this file is too big to display