-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdata_class.py
47 lines (41 loc) · 1.65 KB
/
data_class.py
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 numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler, StandardScaler
from sklearn.feature_selection import SelectFromModel, SelectKBest, chi2, VarianceThreshold, mutual_info_classif
"""
Data wrapper class
...
Attributes
----------
X : Dataframe
df of patients data; columns are genes, rows are patients
X_deseq : Dataframe
df of patient data used to run deseq2; rows are genes, columns are patient data
y: numpy array
class label of patients, y[i] is label for X[i]
"""
class DataClass():
def __init__(self, all_data, patients):
# remove space in sample Id
for i in range(len(patients)):
patients['Sample ID'][i] = patients['Sample ID'][i].strip()
self.patients = all_data[all_data['ID'].isin(np.array(patients['Sample ID']))]
self.Ids = self.patients['ID']
self.patient_data = patients
# class labels
y = []
for pid in self.Ids:
if patients[patients['Sample ID'] == pid]['Compare'].values[0] == 'Yes':
y.append(1)
else:
y.append(0)
self.y = np.array(y)
self.X = self.patients.reset_index().drop(['index'],axis=1)
drop_columns = ['Unnamed: 0', 'no_feature', 'ambiguous', 'ID']
for c in drop_columns:
if c in self.X.columns:
self.X = self.X.drop(columns=[c])
self.X_deseq = self.X.T
self.X_deseq = self.X_deseq.reset_index().drop(['index'],axis=1)
self.X_deseq.columns = self.Ids
self.gene_names = np.array(self.X.columns)