Skip to content

Commit 607980f

Browse files
committed
Made changes in files import in utilities
1 parent 53d7a12 commit 607980f

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

ideeplc/utilities.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import io
12
from typing import List, Tuple, Dict, Union, Optional, Any
23

34
import numpy as np
45
import pandas as pd
56
import tqdm
67
from numpy import ndarray
78
from pyteomics import proforma, mass
8-
import importlib.resources as pkg_resources
9+
from importlib.resources import files
910
import ideeplc.structure_feature
1011

1112

@@ -65,10 +66,8 @@ def aa_atomic_composition_array() -> Dict[str, np.ndarray]:
6566

6667
def aa_chemical_feature() -> Dict[str, np.ndarray]:
6768
"""Get chemical features for amino acids."""
68-
with pkg_resources.files(ideeplc.structure_feature).joinpath("aa_stan.csv").open(
69-
"rb"
70-
) as f:
71-
df_aminoacids = pd.read_csv(f)
69+
content = files(ideeplc.structure_feature).joinpath("aa_stan.csv").read_bytes()
70+
df_aminoacids = pd.read_csv(io.BytesIO(content))
7271
# Convert the dataframe to a dictionary
7372
amino_acids = df_aminoacids.set_index("AA").T.to_dict("list")
7473
# Convert the dictionary to a dictionary of numpy arrays for each AA
@@ -80,10 +79,8 @@ def aa_chemical_feature() -> Dict[str, np.ndarray]:
8079

8180
def mod_chemical_features() -> Dict[str, Dict[str, Dict[str, float]]]:
8281
"""Get modification features."""
83-
with pkg_resources.files(ideeplc.structure_feature).joinpath("ptm_stan.csv").open(
84-
"rb"
85-
) as f:
86-
df = pd.read_csv(f)
82+
content = files(ideeplc.structure_feature).joinpath("ptm_stan.csv").read_bytes()
83+
df = pd.read_csv(io.BytesIO(content))
8784
# Convert the dataframe to a dictionary and transpose it
8885
df = df.set_index("name").T
8986
# Convert the DataFrame to a dictionary of modifications with their chemical features

0 commit comments

Comments
 (0)