Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Arian Jamasb committed Jul 8, 2024
1 parent 21a6080 commit e3234f3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion biopandas/mol2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
files in pandas DataFrames.
"""

from .pandas_mol2 import PandasMol2
from .mol2_io import split_multimol2
from .pandas_mol2 import PandasMol2

__all__ = ["PandasMol2", "split_multimol2"]
17 changes: 12 additions & 5 deletions biopandas/mol2/pandas_mol2.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
""" Class for working with Tripos MOL2 files"""

# BioPandas
# Author: Sebastian Raschka <[email protected]>
# License: BSD 3 clause
# Project Website: http://rasbt.github.io/biopandas/
# Code Repository: https://github.com/rasbt/biopandas

import pandas as pd
import numpy as np
from .mol2_io import split_multimol2
import pandas as pd

from .mol2_io import split_multimol2

COLUMN_NAMES = (
"atom_id",
Expand Down Expand Up @@ -167,7 +168,9 @@ def read_mol2_from_list(self, mol2_lines, mol2_code, columns=None):
def _construct_df(self, mol2_lines, col_names, col_types):
"""Construct DataFrames from list of PDB lines."""
return self._atomsection_to_pandas(
self._get_atomsection(mol2_lines), col_names=col_names, col_types=col_types
self._get_atomsection(mol2_lines),
col_names=col_names,
col_types=col_types,
)

@staticmethod
Expand Down Expand Up @@ -195,7 +198,9 @@ def _get_atomsection(mol2_lst):
@staticmethod
def _atomsection_to_pandas(mol2_atom_lst, col_names, col_types):

df = pd.DataFrame([lst.split() for lst in mol2_atom_lst], columns=col_names)
df = pd.DataFrame(
[lst.split() for lst in mol2_atom_lst], columns=col_names
)

for i in range(df.shape[1]):
df[col_names[i]] = df[col_names[i]].astype(col_types[i])
Expand Down Expand Up @@ -281,4 +286,6 @@ def distance_df(df, xyz=(0.00, 0.00, 0.00)):
"""

return np.sqrt(np.sum(df[["x", "y", "z"]].subtract(xyz, axis=1) ** 2, axis=1))
return np.sqrt(
np.sum(df[["x", "y", "z"]].subtract(xyz, axis=1) ** 2, axis=1)
)
13 changes: 10 additions & 3 deletions biopandas/mol2/tests/test_mol2_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Code Repository: https://github.com/rasbt/biopandas

import os

from biopandas.mol2.mol2_io import split_multimol2
from biopandas.testutils import assert_raises

Expand All @@ -13,15 +14,19 @@

def test_split_multimol2():
all_mol2 = []
for i in split_multimol2(os.path.join(this_dir, "data", "40_mol2_files.mol2")):
for i in split_multimol2(
os.path.join(this_dir, "data", "40_mol2_files.mol2")
):
all_mol2.append(i[0])
assert all_mol2[1] == "ZINC04084113"
assert len(all_mol2) == 40


def test_split_multimol2_wrong_format():

expect = "Wrong file format;" "allowed file formats are .mol2 and .mol2.gz."
expect = (
"Wrong file format;" "allowed file formats are .mol2 and .mol2.gz."
)

def run_code():
next(split_multimol2("40_mol2_files.pdb"))
Expand All @@ -31,7 +36,9 @@ def run_code():

def test_split_multimol2_gz():
all_mol2 = []
for i in split_multimol2(os.path.join(this_dir, "data", "40_mol2_files.mol2.gz")):
for i in split_multimol2(
os.path.join(this_dir, "data", "40_mol2_files.mol2.gz")
):
all_mol2.append(i[0])
assert all_mol2[1].decode() == "ZINC04084113"
assert len(all_mol2) == 40
6 changes: 5 additions & 1 deletion biopandas/mol2/tests/test_pandas_mol2.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
""" Utility function for reading Tripos MOL2 files from files"""

# BioPandas
# Author: Sebastian Raschka <[email protected]>
# License: BSD 3 clause
# Project Website: http://rasbt.github.io/biopandas/
# Code Repository: https://github.com/rasbt/biopandas

import os

from biopandas.mol2 import PandasMol2
from biopandas.mol2.mol2_io import split_multimol2
from biopandas.testutils import assert_raises
Expand Down Expand Up @@ -48,7 +50,9 @@ def test_read_mol2_from_list():
data_path = os.path.join(this_dir, "data", "40_mol2_files.mol2")
mol2 = next(split_multimol2(data_path))

pdmol = PandasMol2().read_mol2_from_list(mol2_lines=mol2[1], mol2_code=mol2[0])
pdmol = PandasMol2().read_mol2_from_list(
mol2_lines=mol2[1], mol2_code=mol2[0]
)
assert pdmol.df.shape == (65, 9)
assert pdmol.code == "ZINC38611810"

Expand Down

0 comments on commit e3234f3

Please sign in to comment.