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
56
mcsm/mcsm.py
56
mcsm/mcsm.py
|
@ -376,23 +376,34 @@ def format_mcsm_output(mcsm_outputcsv):
|
|||
# adding column: wild_position
|
||||
# useful for plots 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 created 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 column: wild_chain_pos
|
||||
# useful for plots and db and its 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 created 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 corrrect dtype in non-numeric cols
|
||||
#############
|
||||
|
||||
#############
|
||||
#) char cols
|
||||
char_cols = ['PredAffLog', 'mutationinformation', 'wild_type', 'mutant_type', 'chain', 'ligand_id', 'duet_outcome', 'ligand_outcome', 'wild_position']
|
||||
char_cols = ['PredAffLog', 'mutationinformation', 'wild_type', 'mutant_type', 'chain', '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)
|
||||
|
@ -408,36 +419,41 @@ 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
|
||||
#############
|
||||
expected_ncols_toadd = 5
|
||||
expected_ncols_toadd = 6 # beware hardcoding!
|
||||
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
|
||||
, '\n---------------------------------------------------'
|
||||
, '\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:
|
||||
sys.exit('FAIL: something went wrong in formatting df'
|
||||
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===================================================')
|
||||
sys.exit()
|
||||
|
||||
|
||||
return mcsm_dataf
|
||||
return mcsm_data_fs
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue