From 811027e34d77794ccff34cfa6724cd9f202ada21 Mon Sep 17 00:00:00 2001 From: Tanushree Tunstall Date: Tue, 7 Apr 2020 17:42:06 +0100 Subject: [PATCH] tidy kd_df script --- scripts/kd_df.py | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/scripts/kd_df.py b/scripts/kd_df.py index 904d92f..97184b0 100755 --- a/scripts/kd_df.py +++ b/scripts/kd_df.py @@ -78,7 +78,8 @@ print('Output filename:', out_filename , '\n=============================================================') #%% end of variable assignment for input and output files #======================================================================= -def kd_to_csv(inputfasta, outputkdcsv, windowsize): +#%% kd values from fasta file and output csv +def kd_to_csv(inputfasta, outputkdcsv, windowsize, plot=False): """ Calculate kd (hydropathy values) from input fasta file @@ -181,17 +182,14 @@ def kd_to_csv(inputfasta, outputkdcsv, windowsize): #=============== # writing file #=============== - print('Writing file:', out_filename - , '\nFilename:', out_filename - , '\nPath:', outdir + print('Writing file:' + , '\nFilename:', outputkdcsv +# , '\nPath:', outdir + , '\nExpected no. of rows:', len(kd_df) + , '\nExpected no. of cols:', len(kd_df.columns) , '\n=============================================================') - kd_df.to_csv(outfile, header = True, index = True) - - print('Finished writing:', out_filename - , '\nNo. of rows:', len(kd_df) - , '\nNo. of cols:', len(kd_df.columns) - , '\n=============================================================') + kd_df.to_csv(outputkdcsv, header = True, index = True) #=============== # plot: optional! @@ -201,12 +199,14 @@ def kd_to_csv(inputfasta, outputkdcsv, windowsize): # FIXME: save fig # extract just pdb if from 'id' to pass to title of plot # foo = re.match(r'(^[0-9]{1}\w{3})', id).groups(1) - plot(kd_values, linewidth = 1.0) - #axis(xmin = 1, xmax = num_residues) - xlabel('Residue Number') - ylabel('Hydrophobicity') - title('K&D Hydrophobicity for ' + id) - show() + if plot: + plot(kd_values, linewidth = 1.0) + #axis(xmin = 1, xmax = num_residues) + xlabel('Residue Number') + ylabel('Hydrophobicity') + title('K&D Hydrophobicity for ' + id) + show() + #%% end of function #======================================================================= #%% call function @@ -214,7 +214,13 @@ def kd_to_csv(inputfasta, outputkdcsv, windowsize): #======================================================================= def main(): print('Running hydropathy calcs', in_filename, 'output csv:', out_filename) - kd_to_csv(infile, outfile, windowsize = 3) + kd_to_csv(infile, outfile, 3) + print('Finished writing file:' + , '\nFilename:', outfile + , '\nPath:', outdir +# , '\nNo. of rows:', '' +# , '\nNo. of cols:', '' + , '\n=============================================================') if __name__ == '__main__': main()