ran struc param analysis
This commit is contained in:
parent
96da4d8ed5
commit
2cebd338ba
5 changed files with 373 additions and 382 deletions
147
scripts/rd_df.py
147
scripts/rd_df.py
|
@ -31,10 +31,8 @@ os.getcwd()
|
|||
#=======================================================================
|
||||
#%% command line args
|
||||
arg_parser = argparse.ArgumentParser()
|
||||
#arg_parser.add_argument('-d', '--drug', help='drug name', default = 'pyrazinamide')
|
||||
#arg_parser.add_argument('-g', '--gene', help='gene name', default = 'pncA') # case sensitive
|
||||
arg_parser.add_argument('-d', '--drug', help='drug name', default = 'TESTDRUG')
|
||||
arg_parser.add_argument('-g', '--gene', help='gene name (case sensitive)', default = 'testGene') # case sensitive
|
||||
arg_parser.add_argument('-d', '--drug', help='drug name', default = None)
|
||||
arg_parser.add_argument('-g', '--gene', help='gene name', default = None) # case sensitive
|
||||
args = arg_parser.parse_args()
|
||||
#=======================================================================
|
||||
#%% variable assignment: input and output
|
||||
|
@ -72,7 +70,7 @@ print('Output filename:', out_filename
|
|||
#=======================================================================
|
||||
#%% rd values from <gene>_rd.tsv values
|
||||
def rd_to_csv(inputtsv, outputrdcsv):
|
||||
"""
|
||||
"""
|
||||
Calculate kd (hydropathy values) from input fasta file
|
||||
|
||||
@param inputtsv: tsv file downloaded from {INSERT LINK}
|
||||
|
@ -83,76 +81,76 @@ def rd_to_csv(inputtsv, outputrdcsv):
|
|||
|
||||
@return: none, writes rd values df as csv
|
||||
"""
|
||||
#========================
|
||||
# read downloaded tsv file
|
||||
#========================
|
||||
#%% Read input file
|
||||
rd_data = pd.read_csv(inputtsv, sep = '\t')
|
||||
print('Reading input file:', inputtsv
|
||||
, '\nNo. of rows:', len(rd_data)
|
||||
, '\nNo. of cols:', len(rd_data.columns))
|
||||
#========================
|
||||
# read downloaded tsv file
|
||||
#========================
|
||||
#%% Read input file
|
||||
rd_data = pd.read_csv(inputtsv, sep = '\t')
|
||||
print('Reading input file:', inputtsv
|
||||
, '\nNo. of rows:', len(rd_data)
|
||||
, '\nNo. of cols:', len(rd_data.columns))
|
||||
|
||||
print('Column names:', rd_data.columns
|
||||
, '\n===============================================================')
|
||||
#========================
|
||||
# creating position col
|
||||
#========================
|
||||
# Extracting residue number from index and assigning
|
||||
# the values to a column [position]. Then convert the position col to numeric.
|
||||
rd_data['position'] = rd_data.index.str.extract('([0-9]+)').values
|
||||
print('Column names:', rd_data.columns
|
||||
, '\n===============================================================')
|
||||
#========================
|
||||
# creating position col
|
||||
#========================
|
||||
# Extracting residue number from index and assigning
|
||||
# the values to a column [position]. Then convert the position col to numeric.
|
||||
rd_data['position'] = rd_data.index.str.extract('([0-9]+)').values
|
||||
|
||||
# converting position to numeric
|
||||
rd_data['position'] = pd.to_numeric(rd_data['position'])
|
||||
rd_data['position'].dtype
|
||||
# converting position to numeric
|
||||
rd_data['position'] = pd.to_numeric(rd_data['position'])
|
||||
rd_data['position'].dtype
|
||||
|
||||
print('Extracted residue num from index and assigned as a column:'
|
||||
, '\ncolumn name: position'
|
||||
, '\ntotal no. of cols now:', len(rd_data.columns)
|
||||
, '\n=============================================================')
|
||||
print('Extracted residue num from index and assigned as a column:'
|
||||
, '\ncolumn name: position'
|
||||
, '\ntotal no. of cols now:', len(rd_data.columns)
|
||||
, '\n=============================================================')
|
||||
|
||||
#========================
|
||||
# Renaming amino-acid
|
||||
# and all-atom cols
|
||||
#========================
|
||||
print('Renaming columns:'
|
||||
, '\ncolname==> # chain:residue: wt_3letter_caps'
|
||||
, '\nYES... the column name *actually* contains a # ..!'
|
||||
, '\ncolname==> all-atom: rd_values'
|
||||
, '\n=============================================================')
|
||||
#========================
|
||||
# Renaming amino-acid
|
||||
# and all-atom cols
|
||||
#========================
|
||||
print('Renaming columns:'
|
||||
, '\ncolname==> # chain:residue: wt_3letter_caps'
|
||||
, '\nYES... the column name *actually* contains a # ..!'
|
||||
, '\ncolname==> all-atom: rd_values'
|
||||
, '\n=============================================================')
|
||||
|
||||
rd_data.rename(columns = {'# chain:residue':'wt_3letter_caps', 'all-atom':'rd_values'}, inplace = True)
|
||||
print('Column names:', rd_data.columns)
|
||||
rd_data.rename(columns = {'# chain:residue':'wt_3letter_caps', 'all-atom':'rd_values'}, inplace = True)
|
||||
print('Column names:', rd_data.columns)
|
||||
|
||||
#========================
|
||||
# extracting df with the
|
||||
# desired columns
|
||||
#========================
|
||||
print('Extracting relevant columns for writing df as csv')
|
||||
#========================
|
||||
# extracting df with the
|
||||
# desired columns
|
||||
#========================
|
||||
print('Extracting relevant columns for writing df as csv')
|
||||
|
||||
rd_df = rd_data[['position','rd_values','wt_3letter_caps']]
|
||||
rd_df = rd_data[['position','rd_values','wt_3letter_caps']]
|
||||
|
||||
if len(rd_df) == len(rd_data):
|
||||
print('PASS: extracted df has expected no. of rows'
|
||||
,'\nExtracted df dim:'
|
||||
,'\nNo. of rows:', len(rd_df)
|
||||
,'\nNo. of cols:', len(rd_df.columns))
|
||||
else:
|
||||
print('FAIL: no. of rows mimatch'
|
||||
, '\nExpected no. of rows:', len(rd_data)
|
||||
, '\nGot no. of rows:', len(rd_df)
|
||||
, '\n=====================================================')
|
||||
if len(rd_df) == len(rd_data):
|
||||
print('PASS: extracted df has expected no. of rows'
|
||||
,'\nExtracted df dim:'
|
||||
,'\nNo. of rows:', len(rd_df)
|
||||
,'\nNo. of cols:', len(rd_df.columns))
|
||||
else:
|
||||
print('FAIL: no. of rows mimatch'
|
||||
, '\nExpected no. of rows:', len(rd_data)
|
||||
, '\nGot no. of rows:', len(rd_df)
|
||||
, '\n=====================================================')
|
||||
|
||||
#===============
|
||||
# writing file
|
||||
#===============
|
||||
print('Writing file:'
|
||||
, '\nFilename:', outputrdcsv
|
||||
# , '\nPath:', outdir
|
||||
# , '\nExpected no. of rows:', len(rd_df)
|
||||
# , '\nExpected no. of cols:', len(rd_df.columns)
|
||||
, '\n=========================================================')
|
||||
#===============
|
||||
# writing file
|
||||
#===============
|
||||
print('Writing file:'
|
||||
, '\nFilename:', outputrdcsv
|
||||
# , '\nPath:', outdir
|
||||
# , '\nExpected no. of rows:', len(rd_df)
|
||||
# , '\nExpected no. of cols:', len(rd_df.columns)
|
||||
, '\n=========================================================')
|
||||
|
||||
rd_df.to_csv(outputrdcsv, header = True, index = False)
|
||||
rd_df.to_csv(outputrdcsv, header = True, index = False)
|
||||
|
||||
#%% end of function
|
||||
#=======================================================================
|
||||
|
@ -160,16 +158,15 @@ def rd_to_csv(inputtsv, outputrdcsv):
|
|||
#rd_to_csv(infile, outfile)
|
||||
#=======================================================================
|
||||
def main():
|
||||
print('residue depth using the following params\n'
|
||||
, in_filename
|
||||
, '\noutfile:', out_filename)
|
||||
rd_to_csv(infile, outfile)
|
||||
print('Finished Writing file:'
|
||||
, '\nFilename:', out_filename
|
||||
, '\nPath:', outdir
|
||||
, '\n=============================================================')
|
||||
print('residue depth using the following params\n'
|
||||
, in_filename
|
||||
, '\noutfile:', out_filename)
|
||||
rd_to_csv(infile, outfile)
|
||||
print('Finished Writing file:'
|
||||
, '\nFilename:', outfile
|
||||
, '\n=============================================================')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
#%% end of script
|
||||
main()
|
||||
#%% end of script
|
||||
#=======================================================================
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue