fixed white space prob with mcsm input with merge
This commit is contained in:
parent
46b1505fdf
commit
7d36e0e36b
6 changed files with 108 additions and 98 deletions
|
@ -74,7 +74,11 @@ def format_mcsm_output(mcsm_outputcsv):
|
|||
#############
|
||||
# Read file
|
||||
#############
|
||||
mcsm_data = pd.read_csv(mcsm_outputcsv, sep = ',')
|
||||
mcsm_data_raw = pd.read_csv(mcsm_outputcsv, sep = ',')
|
||||
|
||||
# strip white space from both ends in all columns
|
||||
mcsm_data = mcsm_data_raw.apply(lambda x: x.str.strip() if x.dtype == 'object' else x)
|
||||
|
||||
dforig_shape = mcsm_data.shape
|
||||
print('dimensions of input file:', dforig_shape)
|
||||
|
||||
|
@ -85,7 +89,7 @@ def format_mcsm_output(mcsm_outputcsv):
|
|||
print('Assigning meaningful colnames i.e without spaces and hyphen and reflecting units'
|
||||
, '\n===================================================================')
|
||||
my_colnames_dict = {'Predicted Affinity Change': 'PredAffLog' # relevant info from this col will be extracted and the column discarded
|
||||
, 'Mutation information': 'mutation_information' # {wild_type}<position>{mutant_type}
|
||||
, 'Mutation information': 'mutationinformation' # {wild_type}<position>{mutant_type}
|
||||
, 'Wild-type': 'wild_type' # one letter amino acid code
|
||||
, 'Position': 'position' # number
|
||||
, 'Mutant-type': 'mutant_type' # one letter amino acid code
|
||||
|
@ -97,19 +101,19 @@ def format_mcsm_output(mcsm_outputcsv):
|
|||
mcsm_data.rename(columns = my_colnames_dict, inplace = True)
|
||||
#%%===========================================================================
|
||||
#################################
|
||||
# populate mutation_information
|
||||
# populate mutationinformation
|
||||
# col which is currently blank
|
||||
#################################
|
||||
# populate mutation_information column:mcsm style muts {WT}<POS>{MUT}
|
||||
print('Populating column : mutation_information which is currently empty\n', mcsm_data['mutation_information'])
|
||||
mcsm_data['mutation_information'] = mcsm_data['wild_type'] + mcsm_data['position'].astype(str) + mcsm_data['mutant_type']
|
||||
print('checking after populating:\n', mcsm_data['mutation_information']
|
||||
# populate mutationinformation column:mcsm style muts {WT}<POS>{MUT}
|
||||
print('Populating column : mutationinformation which is currently empty\n', mcsm_data['mutationinformation'])
|
||||
mcsm_data['mutationinformation'] = mcsm_data['wild_type'] + mcsm_data['position'].astype(str) + mcsm_data['mutant_type']
|
||||
print('checking after populating:\n', mcsm_data['mutationinformation']
|
||||
, '\n===================================================================')
|
||||
|
||||
# Remove spaces b/w pasted columns
|
||||
print('removing white space within column: \mutation_information')
|
||||
mcsm_data['mutation_information'] = mcsm_data['mutation_information'].str.replace(' ', '')
|
||||
print('Correctly formatted column: mutation_information\n', mcsm_data['mutation_information']
|
||||
print('removing white space within column: \mutationinformation')
|
||||
mcsm_data['mutationinformation'] = mcsm_data['mutationinformation'].str.replace(' ', '')
|
||||
print('Correctly formatted column: mutationinformation\n', mcsm_data['mutationinformation']
|
||||
, '\n===================================================================')
|
||||
#%%===========================================================================
|
||||
#############
|
||||
|
@ -118,7 +122,7 @@ def format_mcsm_output(mcsm_outputcsv):
|
|||
# shouldn't exist as this should be eliminated at the time of running mcsm
|
||||
print('Sanity check:'
|
||||
, '\nChecking duplicate mutations')
|
||||
if mcsm_data['mutation_information'].duplicated().sum() == 0:
|
||||
if mcsm_data['mutationinformation'].duplicated().sum() == 0:
|
||||
print('PASS: No duplicate mutations detected (as expected)'
|
||||
, '\nDim of data:', mcsm_data.shape
|
||||
, '\n===============================================================')
|
||||
|
@ -126,7 +130,7 @@ def format_mcsm_output(mcsm_outputcsv):
|
|||
print('FAIL (but not fatal): Duplicate mutations detected'
|
||||
, '\nDim of df with duplicates:', mcsm_data.shape
|
||||
, 'Removing duplicate entries')
|
||||
mcsm_data = mcsm_data.drop_duplicates(['mutation_information'])
|
||||
mcsm_data = mcsm_data.drop_duplicates(['mutationinformation'])
|
||||
print('Dim of data after removing duplicate muts:', mcsm_data.shape
|
||||
, '\n===============================================================')
|
||||
#%%===========================================================================
|
||||
|
@ -285,7 +289,7 @@ def format_mcsm_output(mcsm_outputcsv):
|
|||
#=============================================================================
|
||||
#%% ensuring dtypes are string for the non-numeric cols
|
||||
#) char cols
|
||||
char_cols = ['PredAffLog', 'mutation_information', 'wild_type', 'mutant_type', 'chain'
|
||||
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)
|
||||
|
@ -309,8 +313,8 @@ def format_mcsm_output(mcsm_outputcsv):
|
|||
mcsm_data_fs = mcsm_data_f.sort_values(by = ['position'])
|
||||
print('sorted df:\n', mcsm_data_fs.head())
|
||||
|
||||
# Remove white space everywhere before output: bit me when merging!?
|
||||
mcsm_data_fs.columns = mcsm_data_fs.columns.str.replace(' ', '')
|
||||
# Ensuring column names are lowercase before output
|
||||
mcsm_data_fs.columns = mcsm_data_fs.columns.str.lower()
|
||||
#%%===========================================================================
|
||||
#############
|
||||
# sanity check before writing file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue