Spaces:
Sleeping
Sleeping
Commit ·
576419d
1
Parent(s): 9d68891
fix docker
Browse files- codes/process_features.py +11 -11
- codes/utils.py +5 -5
codes/process_features.py
CHANGED
|
@@ -17,7 +17,7 @@ from absl import app, flags
|
|
| 17 |
import utils
|
| 18 |
|
| 19 |
FLAGS = flags.FLAGS
|
| 20 |
-
_FILEPATH = '.
|
| 21 |
flags.DEFINE_string('config', None, 'Cancer centers to incorporate for feature processing (genie, profile_dfci, or both)')
|
| 22 |
flags.DEFINE_string('filename_suffix', None, 'Filename suffix for processed files.')
|
| 23 |
|
|
@@ -179,7 +179,7 @@ def main(argv):
|
|
| 179 |
df_cup_samples_dfci = df_samples_dfci.loc[df_samples_dfci.PRIMARY_CANCER_DIAGNOSIS.isin(cup_subtypes)].copy()
|
| 180 |
df_cup_samples_dfci.CANCER_TYPE = 'Cancer of Unknown Primary'
|
| 181 |
# Get OncoTree-based cancer types to include.
|
| 182 |
-
with open('.
|
| 183 |
cancers_to_include_dic = pickle.load(handle)
|
| 184 |
if config in ['genie', 'both']:
|
| 185 |
# Process patient data based on cancer types to include.
|
|
@@ -218,7 +218,7 @@ def main(argv):
|
|
| 218 |
cup_samples_ids=df_cup_samples_dfci.UNIQUE_SAMPLE_ID.values)
|
| 219 |
print('Exporting features and labels of interest...')
|
| 220 |
# Load features onconpc pickle file
|
| 221 |
-
with open('.
|
| 222 |
features_onconpc = pickle.load(fp)
|
| 223 |
if config == 'both':
|
| 224 |
# Combine features and labels across centers.
|
|
@@ -228,20 +228,20 @@ def main(argv):
|
|
| 228 |
df_features_cup = df_features_cup[features_onconpc]
|
| 229 |
df_features_cup.columns = utils.standardize_feat_names(df_features_cup.columns)
|
| 230 |
# Export combined (Profile & GENIE) features and labels.
|
| 231 |
-
df_features_combined.to_csv(f'.
|
| 232 |
-
df_labels_combined.to_csv(f'.
|
| 233 |
-
df_features_cup.to_csv(f'.
|
| 234 |
elif config == 'genie':
|
| 235 |
df_features_genie = utils.zero_pad_missing_features(df_features_genie, features_onconpc)
|
| 236 |
df_features_genie.columns = utils.standardize_feat_names(df_features_genie.columns)
|
| 237 |
-
df_features_genie.to_csv(f'.
|
| 238 |
-
df_labels_genie.to_csv(f'.
|
| 239 |
elif config == 'profile_dfci':
|
| 240 |
df_features_dfci.columns = utils.standardize_feat_names(df_features_dfci.columns)
|
| 241 |
df_features_cup.columns = utils.standardize_feat_names(df_features_cup.columns)
|
| 242 |
-
df_features_dfci.to_csv(f'.
|
| 243 |
-
df_labels_dfci.to_csv(f'.
|
| 244 |
-
df_features_cup.to_csv(f'.
|
| 245 |
return
|
| 246 |
|
| 247 |
if __name__ == '__main__':
|
|
|
|
| 17 |
import utils
|
| 18 |
|
| 19 |
FLAGS = flags.FLAGS
|
| 20 |
+
_FILEPATH = './data/seq_panel_data'
|
| 21 |
flags.DEFINE_string('config', None, 'Cancer centers to incorporate for feature processing (genie, profile_dfci, or both)')
|
| 22 |
flags.DEFINE_string('filename_suffix', None, 'Filename suffix for processed files.')
|
| 23 |
|
|
|
|
| 179 |
df_cup_samples_dfci = df_samples_dfci.loc[df_samples_dfci.PRIMARY_CANCER_DIAGNOSIS.isin(cup_subtypes)].copy()
|
| 180 |
df_cup_samples_dfci.CANCER_TYPE = 'Cancer of Unknown Primary'
|
| 181 |
# Get OncoTree-based cancer types to include.
|
| 182 |
+
with open('./data/cancer_type_to_oncotree_subtypes_dict.pkl', 'rb') as handle:
|
| 183 |
cancers_to_include_dic = pickle.load(handle)
|
| 184 |
if config in ['genie', 'both']:
|
| 185 |
# Process patient data based on cancer types to include.
|
|
|
|
| 218 |
cup_samples_ids=df_cup_samples_dfci.UNIQUE_SAMPLE_ID.values)
|
| 219 |
print('Exporting features and labels of interest...')
|
| 220 |
# Load features onconpc pickle file
|
| 221 |
+
with open('./data/features_onconpc.pkl', "rb") as fp:
|
| 222 |
features_onconpc = pickle.load(fp)
|
| 223 |
if config == 'both':
|
| 224 |
# Combine features and labels across centers.
|
|
|
|
| 228 |
df_features_cup = df_features_cup[features_onconpc]
|
| 229 |
df_features_cup.columns = utils.standardize_feat_names(df_features_cup.columns)
|
| 230 |
# Export combined (Profile & GENIE) features and labels.
|
| 231 |
+
df_features_combined.to_csv(f'./data/features_combined_{filename_suffix}', sep='\t', index=True)
|
| 232 |
+
df_labels_combined.to_csv(f'./data/labels_combined_{filename_suffix}', sep='\t', index=True)
|
| 233 |
+
df_features_cup.to_csv(f'./data/features_combined_cup_{filename_suffix}', sep='\t', index=True)
|
| 234 |
elif config == 'genie':
|
| 235 |
df_features_genie = utils.zero_pad_missing_features(df_features_genie, features_onconpc)
|
| 236 |
df_features_genie.columns = utils.standardize_feat_names(df_features_genie.columns)
|
| 237 |
+
df_features_genie.to_csv(f'./data/features_genie_{filename_suffix}', sep='\t', index=True)
|
| 238 |
+
df_labels_genie.to_csv(f'./data/labels_genie_{filename_suffix}', sep='\t', index=True)
|
| 239 |
elif config == 'profile_dfci':
|
| 240 |
df_features_dfci.columns = utils.standardize_feat_names(df_features_dfci.columns)
|
| 241 |
df_features_cup.columns = utils.standardize_feat_names(df_features_cup.columns)
|
| 242 |
+
df_features_dfci.to_csv(f'./data/features_dfci_{filename_suffix}', sep='\t', index=True)
|
| 243 |
+
df_labels_dfci.to_csv(f'./data/labels_dfci_{filename_suffix}', sep='\t', index=True)
|
| 244 |
+
df_features_cup.to_csv(f'./data/features_dfci_cup_{filename_suffix}', sep='\t', index=True)
|
| 245 |
return
|
| 246 |
|
| 247 |
if __name__ == '__main__':
|
codes/utils.py
CHANGED
|
@@ -154,8 +154,8 @@ def get_individual_pred_interpretation(shap_pred_sample_df: pd.DataFrame,
|
|
| 154 |
feature_to_feature_group_dict: dict,
|
| 155 |
sample_info: str = None,
|
| 156 |
filename: str = None,
|
| 157 |
-
filepath: str = '.
|
| 158 |
-
cohort_age_stats_path: str = '.
|
| 159 |
top_feature_num: int = 10,
|
| 160 |
save_plot: bool = False):
|
| 161 |
"""
|
|
@@ -273,8 +273,8 @@ def get_onconpc_prediction_explanations(query_ids: List[str],
|
|
| 273 |
shaps: np.array,
|
| 274 |
df_features_genie: pd.DataFrame,
|
| 275 |
cancer_types_to_consider: List[str],
|
| 276 |
-
filepath: str='.
|
| 277 |
-
cohort_age_stats_path: str='.
|
| 278 |
save_plot: bool=False,
|
| 279 |
) -> List[Mapping[str, Any]]:
|
| 280 |
"""
|
|
@@ -451,7 +451,7 @@ def get_snv_in_trinuc_context(df_mutations: pd.DataFrame,
|
|
| 451 |
return df_trinuc_feats
|
| 452 |
|
| 453 |
def obtain_mutation_signatures(df_trinuc_feats: pd.DataFrame,
|
| 454 |
-
weights_filepath: str='.
|
| 455 |
) -> pd.DataFrame:
|
| 456 |
"""Transforms tri-nucleotide features into mutation signature based features.
|
| 457 |
|
|
|
|
| 154 |
feature_to_feature_group_dict: dict,
|
| 155 |
sample_info: str = None,
|
| 156 |
filename: str = None,
|
| 157 |
+
filepath: str = './others_prediction_explanation',
|
| 158 |
+
cohort_age_stats_path: str = './data/combined_cohort_age_stats.pkl',
|
| 159 |
top_feature_num: int = 10,
|
| 160 |
save_plot: bool = False):
|
| 161 |
"""
|
|
|
|
| 273 |
shaps: np.array,
|
| 274 |
df_features_genie: pd.DataFrame,
|
| 275 |
cancer_types_to_consider: List[str],
|
| 276 |
+
filepath: str='./others_prediction_explanation',
|
| 277 |
+
cohort_age_stats_path: str='./data/combined_cohort_age_stats.pkl',
|
| 278 |
save_plot: bool=False,
|
| 279 |
) -> List[Mapping[str, Any]]:
|
| 280 |
"""
|
|
|
|
| 451 |
return df_trinuc_feats
|
| 452 |
|
| 453 |
def obtain_mutation_signatures(df_trinuc_feats: pd.DataFrame,
|
| 454 |
+
weights_filepath: str='./data/mutation_signatures/sigProfiler*.csv'
|
| 455 |
) -> pd.DataFrame:
|
| 456 |
"""Transforms tri-nucleotide features into mutation signature based features.
|
| 457 |
|