Skip to content

Commit df32796

Browse files
committed
update the code to resolve warning msgs
1 parent 87803fa commit df32796

File tree

5 files changed

+158
-252
lines changed

5 files changed

+158
-252
lines changed

sciRED/ensembleFCA.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_binary_covariate(covariate_vec, covariate_level) -> np.array:
3030
covariate_list = np.zeros((len(covariate_vec)))
3131
for i in range(len(covariate_vec)):
3232
### select the ith element of
33-
if covariate_vec[i] == covariate_level:
33+
if covariate_vec.iloc[i] == covariate_level:
3434
covariate_list[i] = 1
3535
return covariate_list
3636

@@ -96,7 +96,7 @@ def get_importance_df(factor_scores, a_binary_cov, time_eff=True) -> pd.DataFram
9696
force_all: if True, include KNeighbors_permute which often has lower performance
9797
'''
9898

99-
models = {'LogisticRegression': LogisticRegression(),
99+
models = {'LogisticRegression': LogisticRegression(solver='lbfgs', max_iter=500),
100100
'DecisionTree': DecisionTreeClassifier(),
101101
'RandomForest': RandomForestClassifier(),
102102
'XGB': XGBClassifier(),
@@ -206,13 +206,13 @@ def FCAT(covariate_vec, factor_scores,
206206
mean_importance_df = pd.DataFrame(columns=['F'+str(i) for i in range(1, factor_scores.shape[1]+1)])
207207

208208
for covariate_level in np.unique(covariate_vec):
209-
print('covariate_level: ', covariate_level)
209+
#print('covariate_level: ', covariate_level)
210210

211211
a_binary_cov = get_binary_covariate(covariate_vec, covariate_level)
212212
importance_df_a_level = get_importance_df(factor_scores, a_binary_cov, time_eff=time_eff)
213213
mean_importance_a_level = get_mean_importance_level(importance_df_a_level, scale, mean)
214214

215-
print('mean_importance_a_level:', mean_importance_a_level)
215+
#print('mean_importance_a_level:', mean_importance_a_level)
216216
mean_importance_df.loc[covariate_level] = mean_importance_a_level
217217

218218
return mean_importance_df

sciRED/examples/ex_visualize.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def get_legend_patch(y_sample, sample_color):
1212
'''
1313

1414
### make a dictionary of colors annd samples
15-
my_color = {y_sample[i]: sample_color[i] for i in range(len(y_sample))}
15+
my_color = {y_sample.iloc[i]: sample_color[i] for i in range(len(y_sample))}
1616

1717
### make a legend patch based on my_color
1818
legend_patch = [mpatches.Patch(color=my_color[i], label=i) for i in np.unique(y_sample)]
@@ -52,14 +52,14 @@ def get_colors_dict_ratLiver(y_sample, y_strain,y_cell_type):
5252

5353
### make a dictionary of colors for each strain in y_strain
5454
my_color = {'DA': 'red', 'LEW': 'blue'}
55-
strain_color = [my_color[y_strain[i]] for i in range(len(y_strain))]
55+
strain_color = [my_color[y_strain.iloc[i]] for i in range(len(y_strain))]
5656

5757

5858
### make a dictionary of colors for each 16 cluster in y_cluster. use np.unique(y_cell_type)
5959
### generate 16 colors using the following code:
6060
my_color = {i: "#"+''.join([random.choice('0123456789ABCDEF') for j in range(6)])
6161
for i in np.unique(y_cell_type)}
62-
cell_type_color = [my_color[y_cell_type[i]] for i in range(len(y_cell_type))]
62+
cell_type_color = [my_color[y_cell_type.iloc[i]] for i in range(len(y_cell_type))]
6363

6464
return {'sample': sample_color, 'strain': strain_color, 'cell_type':cell_type_color}
6565

@@ -75,13 +75,13 @@ def get_colors_dict_humanLiver(y_sample, y_cell_type):
7575

7676
### make a dictionary of colors for each sample in y_sample
7777
my_color = {'P1TLH': 'red','P3TLH': 'orange', 'P2TLH': 'blue', 'P5TLH': 'purple','P4TLH': 'green'}
78-
sample_color = [my_color[y_sample[i]] for i in range(len(y_sample))]
78+
sample_color = [my_color[y_sample.iloc[i]] for i in range(len(y_sample))]
7979

8080
### make a dictionary of colors for each 16 cluster in y_cluster. use np.unique(y_cluster)
8181
### generate 16 colors using the following code:
8282
my_color = {i: "#"+''.join([random.choice('0123456789ABCDEF') for j in range(6)])
8383
for i in np.unique(y_cell_type)}
84-
cell_type_color = [my_color[y_cell_type[i]] for i in range(len(y_cell_type))]
84+
cell_type_color = [my_color[y_cell_type.iloc[i]] for i in range(len(y_cell_type))]
8585

8686
return {'sample': sample_color, 'cell_type':cell_type_color}
8787

@@ -98,17 +98,17 @@ def get_colors_dict_humanKidney(y_sample, y_sex, y_cell_type):
9898
### make a dictionary of colors for each sample in y_sample
9999
my_color = {i: "#"+''.join([random.choice('0123456789ABCDEF') for j in range(6)])
100100
for i in np.unique(y_sample)}
101-
sample_color = [my_color[y_sample[i]] for i in range(len(y_sample))]
101+
sample_color = [my_color[y_sample.iloc[i]] for i in range(len(y_sample))]
102102

103103
### make a dictionary of colors for each strain in y_strain
104104
my_color = {'Male': 'forestgreen', 'Female': 'hotpink'}
105-
sex_color = [my_color[y_sex[i]] for i in range(len(y_sex))]
105+
sex_color = [my_color[y_sex.iloc[i]] for i in range(len(y_sex))]
106106

107107
### make a dictionary of colors for each 16 cluster in y_cluster. use np.unique(y_cluster)
108108
### generate 16 colors using the following code:
109109
my_color = {i: "#"+''.join([random.choice('0123456789ABCDEF') for j in range(6)])
110110
for i in np.unique(y_cell_type)}
111-
cell_type_color = [my_color[y_cell_type[i]] for i in range(len(y_cell_type))]
111+
cell_type_color = [my_color[y_cell_type.iloc[i]] for i in range(len(y_cell_type))]
112112

113113
return {'sample': sample_color, 'sex':sex_color, 'cell_type':cell_type_color}
114114

@@ -124,17 +124,17 @@ def get_colors_dict_humanPBMC(y_sample, y_stim, y_cell_type):
124124
### make a dictionary of colors for each sample in y_sample
125125
my_color = {i: "#"+''.join([random.choice('0123456789ABCDEF') for j in range(6)])
126126
for i in np.unique(y_sample)}
127-
sample_color = [my_color[y_sample[i]] for i in range(len(y_sample))]
127+
sample_color = [my_color[y_sample.iloc[i]] for i in range(len(y_sample))]
128128

129129
### make a dictionary of colors for each strain in y_strain
130130
my_color = {'stim': 'red', 'ctrl': 'blue'}
131-
stim_color = [my_color[y_stim[i]] for i in range(len(y_stim))]
131+
stim_color = [my_color[y_stim.iloc[i]] for i in range(len(y_stim))]
132132

133133
### make a dictionary of colors for each 16 cluster in y_cluster. use np.unique(y_cluster)
134134
### generate 16 colors using the following code:
135135
my_color = {i: "#"+''.join([random.choice('0123456789ABCDEF') for j in range(6)])
136136
for i in np.unique(y_cell_type)}
137-
cell_type_color = [my_color[y_cell_type[i]] for i in range(len(y_cell_type))]
137+
cell_type_color = [my_color[y_cell_type.iloc[i]] for i in range(len(y_cell_type))]
138138

139139
return {'sample': sample_color, 'stim':stim_color, 'cell_type':cell_type_color}
140140

sciRED/utils/preprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ def get_binary_covariate(covariate_vec, covariate_level) -> np.array:
9191
covariate_level: one level of the covariate
9292
'''
9393
covariate_list = np.zeros((len(covariate_vec)))
94+
9495
for i in range(len(covariate_vec)):
9596
### select the ith element of
96-
if covariate_vec[i] == covariate_level:
97+
if covariate_vec.iloc[i] == covariate_level:
9798
covariate_list[i] = 1
9899
return covariate_list
99100

@@ -107,7 +108,6 @@ def get_design_mat(metadata_col, data) -> np.array:
107108
column_levels = data.obs[metadata_col].unique()
108109
dict_covariate = {}
109110
for column_level in column_levels:
110-
print(column_level)
111111
dict_covariate[column_level] = get_binary_covariate(data.obs[[metadata_col]].squeeze(), column_level)
112112

113113
#### stack colummns of dict_covariate

0 commit comments

Comments
 (0)