minor edits to format mcsm data like sorting df
This commit is contained in:
parent
8931441fa5
commit
6961a9cdb3
4 changed files with 127 additions and 85 deletions
|
@ -264,19 +264,29 @@ def format_mcsm_output(mcsm_outputcsv):
|
|||
, '\nScaled affinity scores:\n', mcsm_data['affinity_scaled'])
|
||||
#=============================================================================
|
||||
# Adding colname: wild_pos: sometimes useful for plotting and db
|
||||
print('Creating column: wild_position')
|
||||
mcsm_data['wild_position'] = mcsm_data['wild_type'] + mcsm_data['position'].astype(str)
|
||||
print(mcsm_data['wild_position'].head())
|
||||
print('Creating column: wild_pos')
|
||||
mcsm_data['wild_pos'] = mcsm_data['wild_type'] + mcsm_data['position'].astype(str)
|
||||
print(mcsm_data['wild_pos'].head())
|
||||
# Remove spaces b/w pasted columns
|
||||
print('removing white space within column: wild_position')
|
||||
mcsm_data['wild_position'] = mcsm_data['wild_position'].str.replace(' ', '')
|
||||
print('Correctly formatted column: wild_position\n', mcsm_data['wild_position'].head()
|
||||
print('removing white space within column: wild_pos')
|
||||
mcsm_data['wild_pos'] = mcsm_data['wild_pos'].str.replace(' ', '')
|
||||
print('Correctly formatted column: wild_pos\n', mcsm_data['wild_pos'].head()
|
||||
, '\n===================================================================')
|
||||
#=============================================================================
|
||||
# Adding colname: wild_chain_pos: sometimes useful for plotting and db and is explicit
|
||||
print('Creating column: wild_chain_pos')
|
||||
mcsm_data['wild_chain_pos'] = mcsm_data['wild_type'] + mcsm_data['chain'] + mcsm_data['position'].astype(str)
|
||||
print(mcsm_data['wild_chain_pos'].head())
|
||||
# Remove spaces b/w pasted columns
|
||||
print('removing white space within column: wild_chain_pos')
|
||||
mcsm_data['wild_chain_pos'] = mcsm_data['wild_chain_pos'].str.replace(' ', '')
|
||||
print('Correctly formatted column: wild_chain_pos\n', mcsm_data['wild_chain_pos'].head()
|
||||
, '\n===================================================================')
|
||||
#=============================================================================
|
||||
#%% ensuring dtypes are string for the non-numeric cols
|
||||
#) char cols
|
||||
char_cols = ['PredAffLog', 'mutation_information', 'wild_type', 'mutant_type', 'chain'
|
||||
, 'ligand_id', 'duet_outcome', 'ligand_outcome', 'wild_position']
|
||||
, 'ligand_id', 'duet_outcome', 'ligand_outcome', 'wild_pos', 'wild_chain_pos']
|
||||
|
||||
#mcsm_data[char_cols] = mcsm_data[char_cols].astype(str)
|
||||
cols_check_char = mcsm_data.select_dtypes(include='object').columns.isin(char_cols)
|
||||
|
@ -292,7 +302,12 @@ def format_mcsm_output(mcsm_outputcsv):
|
|||
#=============================================================================
|
||||
# Removing PredAff log column as it is not needed?
|
||||
print('Removing col: PredAffLog since relevant info has been extracted from it')
|
||||
mcsm_dataf = mcsm_data.drop(columns = ['PredAffLog'])
|
||||
mcsm_data_f = mcsm_data.drop(columns = ['PredAffLog'])
|
||||
#=============================================================================
|
||||
#sort df by position for convenience
|
||||
print('Sorting df by position')
|
||||
mcsm_data_fs = mcsm_data_f.sort_values(by = ['position'])
|
||||
print('sorted df:\n', mcsm_data_fs.head())
|
||||
#%%===========================================================================
|
||||
#############
|
||||
# sanity check before writing file
|
||||
|
@ -300,29 +315,28 @@ def format_mcsm_output(mcsm_outputcsv):
|
|||
expected_ncols_toadd = 5 # beware of hardcoded numbers
|
||||
dforig_len = dforig_shape[1]
|
||||
expected_cols = dforig_len + expected_ncols_toadd
|
||||
if len(mcsm_dataf.columns) == expected_cols:
|
||||
if len(mcsm_data_fs.columns) == expected_cols:
|
||||
print('PASS: formatting successful'
|
||||
, '\nformatted df has expected no. of cols:', expected_cols
|
||||
, '\ncolnames:', mcsm_dataf.columns
|
||||
, '\ncolnames:', mcsm_data_fs.columns
|
||||
, '\n----------------------------------------------------------------'
|
||||
, '\ndtypes in cols:', mcsm_dataf.dtypes
|
||||
, '\ndtypes in cols:', mcsm_data_fs.dtypes
|
||||
, '\n----------------------------------------------------------------'
|
||||
, '\norig data shape:', dforig_shape
|
||||
, '\nformatted df shape:', mcsm_dataf.shape
|
||||
, '\nformatted df shape:', mcsm_data_fs.shape
|
||||
, '\n===============================================================')
|
||||
else:
|
||||
print('FAIL: something went wrong in formatting df'
|
||||
, '\nLen of orig df:', dforig_len
|
||||
, '\nExpected number of cols to add:', expected_ncols_toadd
|
||||
, '\nExpected no. of cols:', expected_cols, '(', dforig_len, '+', expected_ncols_toadd, ')'
|
||||
, '\nGot no. of cols:', len(mcsm_dataf.columns)
|
||||
, '\nGot no. of cols:', len(mcsm_data_fs.columns)
|
||||
, '\nCheck formatting:'
|
||||
, '\ncheck hardcoded value:', expected_ncols_toadd
|
||||
, '\nis', expected_ncols_toadd, 'the no. of expected cols to add?'
|
||||
, '\n===============================================================')
|
||||
|
||||
|
||||
return mcsm_dataf
|
||||
return mcsm_data_fs
|
||||
#=======================================================================
|
||||
# call function
|
||||
mcsm_df_formatted = format_mcsm_output(infile)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue