-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_loader.py
More file actions
47 lines (35 loc) · 1.45 KB
/
data_loader.py
File metadata and controls
47 lines (35 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import pandas as pd
class DataLoader:
def __init__(self, csv_path):
self.csv_path = csv_path
def load_data(self):
df = pd.read_csv(self.csv_path)
df.columns = df.columns.str.strip()
column_mapping = {
'rmsd/ub': 'rmsd_ub',
'rmsd/lb': 'rmsd_lb',
'Binding Affinity': 'binding_affinity',
'Ligand': 'ligand',
'rmsd': 'rmsd_ub'
}
for old_col, new_col in column_mapping.items():
if old_col in df.columns:
df.rename(columns={old_col: new_col}, inplace=True)
df = df.drop_duplicates()
numeric_cols = ['binding_affinity', 'rmsd_ub', 'rmsd_lb']
for col in numeric_cols:
if col in df.columns:
df[col] = pd.to_numeric(df[col], errors='coerce')
return df
def get_top_ligands(self, df):
if not all(col in df.columns for col in ['ligand', 'binding_affinity', 'rmsd_ub', 'rmsd_lb']):
return pd.DataFrame()
filtered_df = df[
(df['rmsd_ub'] == 0) &
(df['rmsd_lb'] == 0)
].copy()
if len(filtered_df) == 0:
filtered_df = df.copy()
filtered_df = filtered_df.sort_values('binding_affinity')
top_ligands = filtered_df.head(10).copy()
return top_ligands