tidy kd_df script

This commit is contained in:
Tanushree Tunstall 2020-04-07 17:42:06 +01:00
parent 02488ea23e
commit 811027e34d

View file

@ -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()