1+ import io
12from typing import List , Tuple , Dict , Union , Optional , Any
23
34import numpy as np
45import pandas as pd
56import tqdm
67from numpy import ndarray
78from pyteomics import proforma , mass
8- import importlib .resources as pkg_resources
9+ from importlib .resources import files
910import ideeplc .structure_feature
1011
1112
@@ -65,10 +66,8 @@ def aa_atomic_composition_array() -> Dict[str, np.ndarray]:
6566
6667def 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
8180def 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