saving work
This commit is contained in:
parent
7b378ca6f3
commit
137f19a285
5 changed files with 1289 additions and 1102 deletions
|
@ -29,46 +29,74 @@ score_type_ordermapD = { 'mcc' : 1
|
|||
, 'fit_time' : 16
|
||||
, 'score_time' : 17
|
||||
}
|
||||
|
||||
|
||||
###############################################################################
|
||||
#==================
|
||||
# Baseline models
|
||||
# Specify outdir
|
||||
#==================
|
||||
# cm_di2 = MultModelsCl_dissected(input_df = X
|
||||
# , target = y
|
||||
# , var_type = 'mixed'
|
||||
# , skf_cv = skf_cv
|
||||
# , blind_test_input_df = X_bts
|
||||
# , blind_test_target = y_bts
|
||||
# , add_cm = True
|
||||
# , add_yn = True)
|
||||
|
||||
# baseline_all2 = pd.DataFrame(cm_di2)
|
||||
# baseline_all2T = baseline_all2.T
|
||||
# baseline_CTBT2 = baseline_all2T.filter(regex = 'test_.*|bts_.*|TN|FP|FN|TP|.*_neg|.*_pos' , axis = 1)
|
||||
outdir_ml = outdir + 'ml/uq_v1/fgs/'
|
||||
print('\nOutput directory:', outdir_ml)
|
||||
outFile = outdir_ml + gene.lower() + '_baseline_FG.csv'
|
||||
|
||||
#==================
|
||||
# other vars
|
||||
#==================
|
||||
tts_split_name = 'original'
|
||||
sampling_type_name = 'none'
|
||||
|
||||
###############################################################################
|
||||
#================
|
||||
# Stability cols
|
||||
#================
|
||||
# Evolutionary
|
||||
# X_evolFN
|
||||
#================
|
||||
feature_gp_nameEV = 'evolutionary'
|
||||
n_featuresEV = len(X_evolFN)
|
||||
|
||||
scores_mmEV = MultModelsCl_dissected(input_df = X[X_evolFN]
|
||||
, target = y
|
||||
, var_type = 'mixed'
|
||||
, skf_cv = skf_cv
|
||||
, blind_test_input_df = X_bts[X_evolFN]
|
||||
, blind_test_target = y_bts
|
||||
, add_cm = True
|
||||
, add_yn = True)
|
||||
|
||||
#================
|
||||
# Affinity cols
|
||||
#================
|
||||
baseline_allEV = pd.DataFrame(scores_mmEV)
|
||||
|
||||
baseline_EV = baseline_allEV.filter(regex = 'bts_.*|test_.*|.*_time|TN|FP|FN|TP|.*_neg|.*_pos', axis = 0)
|
||||
baseline_EV = baseline_EV.reset_index()
|
||||
baseline_EV.rename(columns = {'index': 'original_names'}, inplace = True)
|
||||
|
||||
#================
|
||||
# Residue level
|
||||
#================
|
||||
# Indicate whether BT or CT
|
||||
bt_pattern = re.compile(r'bts_.*')
|
||||
baseline_EV['data_source'] = baseline_EV.apply(lambda row: 'BT' if bt_pattern.search(row.original_names) else 'CV' , axis = 1)
|
||||
|
||||
baseline_EV['score_type'] = baseline_EV['original_names'].str.replace('bts_|test_', '', regex = True)
|
||||
|
||||
score_type_uniqueN = set(baseline_EV['score_type'])
|
||||
cL1 = list(score_type_ordermapD.keys())
|
||||
cL2 = list(score_type_uniqueN)
|
||||
|
||||
if set(cL1).issubset(cL2):
|
||||
print('\nPASS: sorting df by score that is mapped onto the order I want')
|
||||
baseline_EV['score_order'] = baseline_EV['score_type'].map(score_type_ordermapD)
|
||||
baseline_EV.sort_values(by = ['data_source', 'score_order'], ascending = [True, True], inplace = True)
|
||||
else:
|
||||
sys.exit('\nFAIL: could not sort df as score mapping for ordering failed')
|
||||
|
||||
baseline_EV['feature_group'] = feature_gp_nameEV
|
||||
baseline_EV['sampling_type'] = sampling_type_name
|
||||
baseline_EV['tts_split'] = tts_split_name
|
||||
baseline_EV['n_features'] = n_featuresEV
|
||||
###############################################################################
|
||||
#================
|
||||
# Genomics
|
||||
# X_genomicFN
|
||||
#================
|
||||
feature_gp_name = 'genomics'
|
||||
feature_gp_nameGN = 'genomics'
|
||||
n_featuresGN = len(X_genomicFN)
|
||||
|
||||
scores_mm_gn = MultModelsCl_dissected(input_df = X[X_genomicFN]
|
||||
scores_mmGN = MultModelsCl_dissected(input_df = X[X_genomicFN]
|
||||
, target = y
|
||||
, var_type = 'mixed'
|
||||
, skf_cv = skf_cv
|
||||
|
@ -77,9 +105,9 @@ scores_mm_gn = MultModelsCl_dissected(input_df = X[X_genomicFN]
|
|||
, add_cm = True
|
||||
, add_yn = True)
|
||||
|
||||
baseline_all_gn = pd.DataFrame(scores_mm_gn)
|
||||
baseline_allGN = pd.DataFrame(scores_mmGN)
|
||||
|
||||
baseline_GN = baseline_all_gn.filter(regex = 'bts_.*|test_.*|.*_time|TN|FP|FN|TP|.*_neg|.*_pos', axis = 0)
|
||||
baseline_GN = baseline_allGN.filter(regex = 'bts_.*|test_.*|.*_time|TN|FP|FN|TP|.*_neg|.*_pos', axis = 0)
|
||||
baseline_GN = baseline_GN.reset_index()
|
||||
baseline_GN.rename(columns = {'index': 'original_names'}, inplace = True)
|
||||
|
||||
|
@ -100,47 +128,340 @@ if set(cL1).issubset(cL2):
|
|||
else:
|
||||
sys.exit('\nFAIL: could not sort df as score mapping for ordering failed')
|
||||
|
||||
baseline_GN['feature_group'] = feature_gp_name
|
||||
|
||||
#-------------
|
||||
# Blind test
|
||||
#-------------
|
||||
baseline_BT = baseline_all_gn.filter(regex = 'bts_', axis = 0)
|
||||
baseline_BT = baseline_BT.reset_index()
|
||||
baseline_BT.rename(columns = {'index': 'original_names'}, inplace = True)
|
||||
baseline_BT['score_type'] = baseline_BT['original_names']
|
||||
baseline_BT['score_type'] = baseline_BT['score_type'].str.replace('bts_*', '', regex = True)
|
||||
baseline_BT['data_source'] = 'BT_score'
|
||||
baseline_GN['feature_group'] = feature_gp_nameGN
|
||||
baseline_GN['sampling_type'] = sampling_type_name
|
||||
baseline_GN['tts_split'] = tts_split_name
|
||||
baseline_GN['n_features'] = n_featuresGN
|
||||
###############################################################################
|
||||
#all_featuresN = X_evolFN + X_structural_FN + X_genomicFN
|
||||
# X_structural_FN = X_stability_FN + X_affinityFN + X_resprop_FN
|
||||
# X_resprop_FN = X_aaindex_Fnum + X_str_Fnum + X_aap_Fcat
|
||||
#================
|
||||
# Structural cols
|
||||
# X_structural_FN
|
||||
#================
|
||||
feature_gp_nameSTR = 'structural'
|
||||
n_featuresSTR = len(X_structural_FN)
|
||||
|
||||
#--------
|
||||
# CV
|
||||
#--------
|
||||
baseline_CT = baseline_all_gn.filter(regex = '.*_time|test_.*|TN|FP|FN|TP|.*_neg|.*_pos', axis = 0)
|
||||
baseline_CT = baseline_CT.reset_index()
|
||||
baseline_CT.rename(columns = {'index': 'original_names'}, inplace = True)
|
||||
baseline_CT['score_type'] = baseline_CT['original_names']
|
||||
baseline_CT['score_type'] = baseline_CT['score_type'].str.replace('test_*', '', regex = True)
|
||||
baseline_CT['data_source'] = 'CT_score'
|
||||
scores_mmSTR = MultModelsCl_dissected(input_df = X[X_structural_FN]
|
||||
, target = y
|
||||
, var_type = 'mixed'
|
||||
, skf_cv = skf_cv
|
||||
, blind_test_input_df = X_bts[X_structural_FN]
|
||||
, blind_test_target = y_bts
|
||||
, add_cm = True
|
||||
, add_yn = True)
|
||||
|
||||
#----------------------
|
||||
# rpow bind: CT and BT
|
||||
#----------------------
|
||||
if all(baseline_BT.columns == baseline_CT.columns):
|
||||
print('\nPASS: Colnames match, proceeding to row bind for data:', feature_gp_name
|
||||
, '\nDim of df1 (BT):', baseline_BT.shape
|
||||
, '\nDim of df2 (CT):', baseline_CT.shape)
|
||||
comb_df_gn = pd.concat([baseline_BT, baseline_CT], axis = 0, ignore_index = True)
|
||||
comb_df_gn['feature_group'] = feature_gp_name
|
||||
print('\nDim of combined df:', comb_df_gn.shape)
|
||||
baseline_allSTR = pd.DataFrame(scores_mmSTR)
|
||||
|
||||
baseline_STR = baseline_allSTR.filter(regex = 'bts_.*|test_.*|.*_time|TN|FP|FN|TP|.*_neg|.*_pos', axis = 0)
|
||||
baseline_STR = baseline_STR.reset_index()
|
||||
baseline_STR.rename(columns = {'index': 'original_names'}, inplace = True)
|
||||
|
||||
# Indicate whether BT or CT
|
||||
bt_pattern = re.compile(r'bts_.*')
|
||||
baseline_STR['data_source'] = baseline_STR.apply(lambda row: 'BT' if bt_pattern.search(row.original_names) else 'CV' , axis = 1)
|
||||
|
||||
baseline_STR['score_type'] = baseline_STR['original_names'].str.replace('bts_|test_', '', regex = True)
|
||||
|
||||
score_type_uniqueN = set(baseline_STR['score_type'])
|
||||
cL1 = list(score_type_ordermapD.keys())
|
||||
cL2 = list(score_type_uniqueN)
|
||||
|
||||
if set(cL1).issubset(cL2):
|
||||
print('\nPASS: sorting df by score that is mapped onto the order I want')
|
||||
baseline_STR['score_order'] = baseline_STR['score_type'].map(score_type_ordermapD)
|
||||
baseline_STR.sort_values(by = ['data_source', 'score_order'], ascending = [True, True], inplace = True)
|
||||
else:
|
||||
print('\nFAIL: colnames mismatch, cannot combine')
|
||||
sys.exit('\nFAIL: could not sort df as score mapping for ordering failed')
|
||||
|
||||
# good way but I don't like to have to rearrange the columns later
|
||||
#frames_tocombine = [baseline_BT, baseline_CT]
|
||||
#common_cols = list(set.intersection(*(set(df.columns) for df in frames_tocombine)))
|
||||
#a = pd.concat([df[common_cols] for df in frames_tocombine], ignore_index=True)
|
||||
baseline_STR['feature_group'] = feature_gp_nameSTR
|
||||
baseline_STR['sampling_type'] = sampling_type_name
|
||||
baseline_STR['tts_split'] = tts_split_name
|
||||
baseline_STR['n_features'] = n_featuresSTR
|
||||
##############################################################################
|
||||
#================
|
||||
# Stability cols
|
||||
# X_stability_FN
|
||||
#================
|
||||
feature_gp_nameSTB = 'stability'
|
||||
n_featuresSTB = len(X_stability_FN)
|
||||
|
||||
scores_mmSTB = MultModelsCl_dissected(input_df = X[X_stability_FN]
|
||||
, target = y
|
||||
, var_type = 'mixed'
|
||||
, skf_cv = skf_cv
|
||||
, blind_test_input_df = X_bts[X_stability_FN]
|
||||
, blind_test_target = y_bts
|
||||
, add_cm = True
|
||||
, add_yn = True)
|
||||
|
||||
baseline_allSTB = pd.DataFrame(scores_mmSTB)
|
||||
|
||||
baseline_STB = baseline_allSTB.filter(regex = 'bts_.*|test_.*|.*_time|TN|FP|FN|TP|.*_neg|.*_pos', axis = 0)
|
||||
baseline_STB = baseline_STB.reset_index()
|
||||
baseline_STB.rename(columns = {'index': 'original_names'}, inplace = True)
|
||||
|
||||
# Indicate whether BT or CT
|
||||
bt_pattern = re.compile(r'bts_.*')
|
||||
baseline_STB['data_source'] = baseline_STB.apply(lambda row: 'BT' if bt_pattern.search(row.original_names) else 'CV' , axis = 1)
|
||||
|
||||
baseline_STB['score_type'] = baseline_STB['original_names'].str.replace('bts_|test_', '', regex = True)
|
||||
|
||||
score_type_uniqueN = set(baseline_STB['score_type'])
|
||||
cL1 = list(score_type_ordermapD.keys())
|
||||
cL2 = list(score_type_uniqueN)
|
||||
|
||||
if set(cL1).issubset(cL2):
|
||||
print('\nPASS: sorting df by score that is mapped onto the order I want')
|
||||
baseline_STB['score_order'] = baseline_STB['score_type'].map(score_type_ordermapD)
|
||||
baseline_STB.sort_values(by = ['data_source', 'score_order'], ascending = [True, True], inplace = True)
|
||||
else:
|
||||
sys.exit('\nFAIL: could not sort df as score mapping for ordering failed')
|
||||
|
||||
baseline_STB['feature_group'] = feature_gp_nameSTB
|
||||
baseline_STB['sampling_type'] = sampling_type_name
|
||||
baseline_STB['tts_split'] = tts_split_name
|
||||
baseline_STB['n_features'] = n_featuresSTB
|
||||
###############################################################################
|
||||
#================
|
||||
# Evolution
|
||||
# Affinity cols
|
||||
# X_affinityFN
|
||||
#================
|
||||
feature_gp_nameAFF = 'affinity'
|
||||
n_featuresAFF = len(X_affinityFN)
|
||||
|
||||
scores_mmAFF = MultModelsCl_dissected(input_df = X[X_affinityFN]
|
||||
, target = y
|
||||
, var_type = 'mixed'
|
||||
, skf_cv = skf_cv
|
||||
, blind_test_input_df = X_bts[X_affinityFN]
|
||||
, blind_test_target = y_bts
|
||||
, add_cm = True
|
||||
, add_yn = True)
|
||||
|
||||
baseline_allAFF = pd.DataFrame(scores_mmAFF)
|
||||
|
||||
baseline_AFF = baseline_allAFF.filter(regex = 'bts_.*|test_.*|.*_time|TN|FP|FN|TP|.*_neg|.*_pos', axis = 0)
|
||||
baseline_AFF = baseline_AFF.reset_index()
|
||||
baseline_AFF.rename(columns = {'index': 'original_names'}, inplace = True)
|
||||
|
||||
# Indicate whether BT or CT
|
||||
bt_pattern = re.compile(r'bts_.*')
|
||||
baseline_AFF['data_source'] = baseline_AFF.apply(lambda row: 'BT' if bt_pattern.search(row.original_names) else 'CV' , axis = 1)
|
||||
|
||||
baseline_AFF['score_type'] = baseline_AFF['original_names'].str.replace('bts_|test_', '', regex = True)
|
||||
|
||||
score_type_uniqueN = set(baseline_AFF['score_type'])
|
||||
cL1 = list(score_type_ordermapD.keys())
|
||||
cL2 = list(score_type_uniqueN)
|
||||
|
||||
if set(cL1).issubset(cL2):
|
||||
print('\nPASS: sorting df by score that is mapped onto the order I want')
|
||||
baseline_AFF['score_order'] = baseline_AFF['score_type'].map(score_type_ordermapD)
|
||||
baseline_AFF.sort_values(by = ['data_source', 'score_order'], ascending = [True, True], inplace = True)
|
||||
else:
|
||||
sys.exit('\nFAIL: could not sort df as score mapping for ordering failed')
|
||||
|
||||
baseline_AFF['feature_group'] = feature_gp_nameAFF
|
||||
baseline_AFF['sampling_type'] = sampling_type_name
|
||||
baseline_AFF['tts_split'] = tts_split_name
|
||||
baseline_AFF['n_features'] = n_featuresAFF
|
||||
###############################################################################
|
||||
#================
|
||||
# Residue level
|
||||
# X_resprop_FN
|
||||
#================
|
||||
feature_gp_nameRES = 'residue_prop'
|
||||
n_featuresRES = len(X_resprop_FN)
|
||||
|
||||
scores_mmRES = MultModelsCl_dissected(input_df = X[X_resprop_FN]
|
||||
, target = y
|
||||
, var_type = 'mixed'
|
||||
, skf_cv = skf_cv
|
||||
, blind_test_input_df = X_bts[X_resprop_FN]
|
||||
, blind_test_target = y_bts
|
||||
, add_cm = True
|
||||
, add_yn = True)
|
||||
|
||||
baseline_allRES = pd.DataFrame(scores_mmRES)
|
||||
|
||||
baseline_RES = baseline_allRES.filter(regex = 'bts_.*|test_.*|.*_time|TN|FP|FN|TP|.*_neg|.*_pos', axis = 0)
|
||||
baseline_RES = baseline_RES.reset_index()
|
||||
baseline_RES.rename(columns = {'index': 'original_names'}, inplace = True)
|
||||
|
||||
# Indicate whether BT or CT
|
||||
bt_pattern = re.compile(r'bts_.*')
|
||||
baseline_RES['data_source'] = baseline_RES.apply(lambda row: 'BT' if bt_pattern.search(row.original_names) else 'CV' , axis = 1)
|
||||
|
||||
baseline_RES['score_type'] = baseline_RES['original_names'].str.replace('bts_|test_', '', regex = True)
|
||||
|
||||
score_type_uniqueN = set(baseline_RES['score_type'])
|
||||
cL1 = list(score_type_ordermapD.keys())
|
||||
cL2 = list(score_type_uniqueN)
|
||||
|
||||
if set(cL1).issubset(cL2):
|
||||
print('\nPASS: sorting df by score that is mapped onto the order I want')
|
||||
baseline_RES['score_order'] = baseline_RES['score_type'].map(score_type_ordermapD)
|
||||
baseline_RES.sort_values(by = ['data_source', 'score_order'], ascending = [True, True], inplace = True)
|
||||
else:
|
||||
sys.exit('\nFAIL: could not sort df as score mapping for ordering failed')
|
||||
|
||||
baseline_RES['feature_group'] = feature_gp_nameRES
|
||||
baseline_RES['sampling_type'] = sampling_type_name
|
||||
baseline_RES['tts_split'] = tts_split_name
|
||||
baseline_RES['n_features'] = n_featuresRES
|
||||
###############################################################################
|
||||
#================
|
||||
# Residue level-AAindex
|
||||
#X_resprop_FN - X_aaindex_Fnum
|
||||
#================
|
||||
X_respropNOaaFN = list(set(X_resprop_FN) - set(X_aaindex_Fnum))
|
||||
|
||||
feature_gp_nameRNAA = 'ResPropNoAA'
|
||||
n_featuresRNAA = len(X_respropNOaaFN)
|
||||
|
||||
scores_mmRNAA = MultModelsCl_dissected(input_df = X[X_respropNOaaFN]
|
||||
, target = y
|
||||
, var_type = 'mixed'
|
||||
, skf_cv = skf_cv
|
||||
, blind_test_input_df = X_bts[X_respropNOaaFN]
|
||||
, blind_test_target = y_bts
|
||||
, add_cm = True
|
||||
, add_yn = True)
|
||||
|
||||
baseline_allRNAA = pd.DataFrame(scores_mmRNAA)
|
||||
|
||||
baseline_RNAA = baseline_allRNAA.filter(regex = 'bts_.*|test_.*|.*_time|TN|FP|FN|TP|.*_neg|.*_pos', axis = 0)
|
||||
baseline_RNAA = baseline_RNAA.reset_index()
|
||||
baseline_RNAA.rename(columns = {'index': 'original_names'}, inplace = True)
|
||||
|
||||
# Indicate whether BT or CT
|
||||
bt_pattern = re.compile(r'bts_.*')
|
||||
baseline_RNAA['data_source'] = baseline_RNAA.apply(lambda row: 'BT' if bt_pattern.search(row.original_names) else 'CV' , axis = 1)
|
||||
|
||||
baseline_RNAA['score_type'] = baseline_RNAA['original_names'].str.replace('bts_|test_', '', regex = True)
|
||||
|
||||
score_type_uniqueN = set(baseline_RNAA['score_type'])
|
||||
cL1 = list(score_type_ordermapD.keys())
|
||||
cL2 = list(score_type_uniqueN)
|
||||
|
||||
if set(cL1).issubset(cL2):
|
||||
print('\nPASS: sorting df by score that is mapped onto the order I want')
|
||||
baseline_RNAA['score_order'] = baseline_RNAA['score_type'].map(score_type_ordermapD)
|
||||
baseline_RNAA.sort_values(by = ['data_source', 'score_order'], ascending = [True, True], inplace = True)
|
||||
else:
|
||||
sys.exit('\nFAIL: could not sort df as score mapping for ordering failed')
|
||||
|
||||
baseline_RNAA['feature_group'] = feature_gp_nameRNAA
|
||||
baseline_RNAA['sampling_type'] = sampling_type_name
|
||||
baseline_RNAA['tts_split'] = tts_split_name
|
||||
baseline_RNAA['n_features'] = n_featuresRNAA
|
||||
###############################################################################
|
||||
#================
|
||||
# Structural cols-AAindex
|
||||
#X_structural_FN - X_aaindex_Fnum
|
||||
#================
|
||||
X_strNOaaFN = list(set(X_structural_FN) - set(X_aaindex_Fnum))
|
||||
|
||||
feature_gp_nameSNAA = 'StrNoAA'
|
||||
n_featuresSNAA = len(X_strNOaaFN)
|
||||
|
||||
scores_mmSNAA = MultModelsCl_dissected(input_df = X[X_strNOaaFN]
|
||||
, target = y
|
||||
, var_type = 'mixed'
|
||||
, skf_cv = skf_cv
|
||||
, blind_test_input_df = X_bts[X_strNOaaFN]
|
||||
, blind_test_target = y_bts
|
||||
, add_cm = True
|
||||
, add_yn = True)
|
||||
|
||||
baseline_allSNAA = pd.DataFrame(scores_mmSNAA)
|
||||
|
||||
baseline_SNAA = baseline_allSNAA.filter(regex = 'bts_.*|test_.*|.*_time|TN|FP|FN|TP|.*_neg|.*_pos', axis = 0)
|
||||
baseline_SNAA = baseline_SNAA.reset_index()
|
||||
baseline_SNAA.rename(columns = {'index': 'original_names'}, inplace = True)
|
||||
|
||||
# Indicate whether BT or CT
|
||||
bt_pattern = re.compile(r'bts_.*')
|
||||
baseline_SNAA['data_source'] = baseline_SNAA.apply(lambda row: 'BT' if bt_pattern.search(row.original_names) else 'CV' , axis = 1)
|
||||
|
||||
baseline_SNAA['score_type'] = baseline_SNAA['original_names'].str.replace('bts_|test_', '', regex = True)
|
||||
|
||||
score_type_uniqueN = set(baseline_SNAA['score_type'])
|
||||
cL1 = list(score_type_ordermapD.keys())
|
||||
cL2 = list(score_type_uniqueN)
|
||||
|
||||
if set(cL1).issubset(cL2):
|
||||
print('\nPASS: sorting df by score that is mapped onto the order I want')
|
||||
baseline_SNAA['score_order'] = baseline_SNAA['score_type'].map(score_type_ordermapD)
|
||||
baseline_SNAA.sort_values(by = ['data_source', 'score_order'], ascending = [True, True], inplace = True)
|
||||
else:
|
||||
sys.exit('\nFAIL: could not sort df as score mapping for ordering failed')
|
||||
|
||||
baseline_SNAA['feature_group'] = feature_gp_nameSNAA
|
||||
baseline_SNAA['sampling_type'] = sampling_type_name
|
||||
baseline_SNAA['tts_split'] = tts_split_name
|
||||
baseline_SNAA['n_features'] = n_featuresSNAA
|
||||
###############################################################################
|
||||
#%% COMBINING all FG dfs
|
||||
#================
|
||||
# Combine all
|
||||
# https://stackoverflow.com/questions/39862654/pandas-concat-of-multiple-data-frames-using-only-common-columns
|
||||
#================
|
||||
dfs_combine = [baseline_EV, baseline_GN, baseline_STR, baseline_STB, baseline_AFF, baseline_RES , baseline_RNAA , baseline_SNAA]
|
||||
|
||||
dfs_nrows = []
|
||||
for df in dfs_combine:
|
||||
dfs_nrows = dfs_nrows + [len(df)]
|
||||
dfs_nrows = max(dfs_nrows)
|
||||
|
||||
dfs_ncols = []
|
||||
for df in dfs_combine:
|
||||
dfs_ncols = dfs_ncols + [len(df.columns)]
|
||||
dfs_ncols = max(dfs_ncols)
|
||||
|
||||
# dfs_ncols = []
|
||||
# dfs_ncols2 = mode(dfs_ncols.append(len(df.columns) for df in dfs_combine)
|
||||
# dfs_ncols2
|
||||
|
||||
expected_nrows = len(dfs_combine) * dfs_nrows
|
||||
expected_ncols = dfs_ncols
|
||||
|
||||
common_cols = list(set.intersection(*(set(df.columns) for df in dfs_combine)))
|
||||
|
||||
if len(common_cols) == dfs_ncols :
|
||||
combined_FG_baseline = pd.concat([df[common_cols] for df in dfs_combine], ignore_index=True)
|
||||
fgs = combined_FG_baseline[['feature_group', 'n_features']]
|
||||
fgs = fgs.drop_duplicates()
|
||||
print('\nConcatenating dfs with feature groups after ML analysis (sampling type):'
|
||||
, '\nNo. of dfs combining:', len(dfs_combine)
|
||||
, '\nSampling type:', sampling_type
|
||||
, '\nThe feature groups are:'
|
||||
, '\n', fgs)
|
||||
if len(combined_FG_baseline) == expected_nrows and len(combined_FG_baseline.columns) == expected_ncols:
|
||||
print('\nPASS:', len(dfs_combine), 'dfs successfully combined'
|
||||
, '\nnrows in combined_df:', len(combined_FG_baseline)
|
||||
, '\nncols in combined_df:', len(combined_FG_baseline.columns))
|
||||
else:
|
||||
print('\nFAIL: concatenating failed'
|
||||
, '\nExpected nrows:', expected_nrows
|
||||
, '\nGot:', len(combined_FG_baseline)
|
||||
, '\nExpected ncols:', expected_ncols
|
||||
, '\nGot:', len(combined_FG_baseline.columns))
|
||||
sys.exit()
|
||||
else:
|
||||
sys.exit('\nConcatenting dfs not possible,check numbers ')
|
||||
|
||||
# # rpow bind
|
||||
# if all(ll((baseline_EV.columns == baseline_GN.columns == baseline_STR.columns)):
|
||||
# print('\nPASS:colnames match, proceeding to rowbind')
|
||||
# comb_df = pd.concat()], axis = 0, ignore_index = True )
|
||||
###############################################################################
|
||||
#====================
|
||||
# Write output file
|
||||
#====================
|
||||
|
||||
combined_FG_baseline.to_csv(outFile)
|
||||
print('\nFile successfully written:', outFile)
|
||||
###############################################################################
|
Loading…
Add table
Add a link
Reference in a new issue