ran struc param analysis

This commit is contained in:
Tanushree Tunstall 2020-06-17 19:36:02 +01:00
parent e21635fe02
commit 8d1daabff4
5 changed files with 373 additions and 382 deletions

View file

@ -46,10 +46,8 @@ os.getcwd()
#======================================================================= #=======================================================================
#%% command line args #%% command line args
arg_parser = argparse.ArgumentParser() arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('-d', '--drug', help='drug name', default = 'pyrazinamide') arg_parser.add_argument('-d', '--drug', help='drug name', default = None)
arg_parser.add_argument('-g', '--gene', help='gene name', default = 'pncA') # case sensitive arg_parser.add_argument('-g', '--gene', help='gene name', default = None) # 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
args = arg_parser.parse_args() args = arg_parser.parse_args()
#======================================================================= #=======================================================================
#%% variable assignment: input and output #%% variable assignment: input and output
@ -288,8 +286,7 @@ def main():
, 'output csv:', out_filename) , 'output csv:', out_filename)
combine_dfs(infile1, infile2, infile3, infile4, outfile) combine_dfs(infile1, infile2, infile3, infile4, outfile)
print('Finished Writing file:' print('Finished Writing file:'
, '\nFilename:', out_filename , '\nFilename:', outfile
, '\nPath:', outdir
## , '\nNo. of rows:', '' ## , '\nNo. of rows:', ''
## , '\nNo. of cols:', '' ## , '\nNo. of cols:', ''
, '\n===========================================================') , '\n===========================================================')

View file

@ -57,8 +57,8 @@ args = arg_parser.parse_args()
drug = args.drug drug = args.drug
gene = args.gene gene = args.gene
gene_match = gene + '_p.' gene_match = gene + '_p.'
# building cols to extract # building cols to extract
dr_muts_col = 'dr_mutations_' + drug dr_muts_col = 'dr_mutations_' + drug
other_muts_col = 'other_mutations_' + drug other_muts_col = 'other_mutations_' + drug
@ -80,8 +80,8 @@ datadir = homedir + '/' + 'git/Data'
#======= #=======
# input # input
#======= #=======
#in_filename = 'original_tanushree_data_v2.csv' in_filename = 'original_tanushree_data_v2.csv'
in_filename = 'mtb_gwas_v3.csv' #in_filename = 'mtb_gwas_v3.csv'
infile = datadir + '/' + in_filename infile = datadir + '/' + in_filename
print('Input file: ', infile print('Input file: ', infile
, '\n============================================================') , '\n============================================================')
@ -1028,25 +1028,25 @@ del(k, v, wt, mut, lookup_dict)
######## ########
# combine the wild_type+poistion+mutant_type columns to generate # combine the wild_type+poistion+mutant_type columns to generate
# Mutationinformation (matches mCSM output field) # mutationinformation (matches mCSM output field)
# Remember to use .map(str) for int col types to allow string concatenation # Remember to use .map(str) for int col types to allow string concatenation
######### #########
gene_LF1['Mutationinformation'] = gene_LF1['wild_type'] + gene_LF1.position.map(str) + gene_LF1['mutant_type'] gene_LF1['mutationinformation'] = gene_LF1['wild_type'] + gene_LF1.position.map(str) + gene_LF1['mutant_type']
print('Created column: Mutationinformation' print('Created column: mutationinformation'
, '\n=====================================================================' , '\n====================================================================='
, gene_LF1.Mutationinformation.head(10)) , gene_LF1.mutationinformation.head(10))
#%% Write file: mCSM muts #%% Write file: mCSM muts
snps_only = pd.DataFrame(gene_LF1['Mutationinformation'].unique()) snps_only = pd.DataFrame(gene_LF1['mutationinformation'].unique())
snps_only.head() snps_only.head()
# assign column name # assign column name
snps_only.columns = ['Mutationinformation'] snps_only.columns = ['mutationinformation']
# count how many positions this corresponds to # count how many positions this corresponds to
pos_only = pd.DataFrame(gene_LF1['position'].unique()) pos_only = pd.DataFrame(gene_LF1['position'].unique())
print('Checking NA in snps...')# should be 0 print('Checking NA in snps...')# should be 0
if snps_only.Mutationinformation.isna().sum() == 0: if snps_only.mutationinformation.isna().sum() == 0:
print ('PASS: NO NAs/missing entries for SNPs' print ('PASS: NO NAs/missing entries for SNPs'
, '\n===============================================================') , '\n===============================================================')
else: else:
@ -1090,27 +1090,27 @@ print('Finished writing:', out_filename3
del(out_filename3) del(out_filename3)
#%% write file: mCSM style but with repitions for MSA and logo plots #%% write file: mCSM style but with repitions for MSA and logo plots
all_muts_msa = pd.DataFrame(gene_LF1['Mutationinformation']) all_muts_msa = pd.DataFrame(gene_LF1['mutationinformation'])
all_muts_msa.head() all_muts_msa.head()
# assign column name # assign column name
all_muts_msa.columns = ['Mutationinformation'] all_muts_msa.columns = ['mutationinformation']
# make sure it is string # make sure it is string
all_muts_msa.columns.dtype all_muts_msa.columns.dtype
# sort the column # sort the column
all_muts_msa_sorted = all_muts_msa.sort_values(by = 'Mutationinformation') all_muts_msa_sorted = all_muts_msa.sort_values(by = 'mutationinformation')
# create an extra column with protein name # create an extra column with protein name
all_muts_msa_sorted = all_muts_msa_sorted.assign(fasta_name = '3PL1') all_muts_msa_sorted = all_muts_msa_sorted.assign(fasta_name = '3PL1')
all_muts_msa_sorted.head() all_muts_msa_sorted.head()
# rearrange columns so the fasta name is the first column (required for mutate.script) # rearrange columns so the fasta name is the first column (required for mutate.script)
all_muts_msa_sorted = all_muts_msa_sorted[['fasta_name', 'Mutationinformation']] all_muts_msa_sorted = all_muts_msa_sorted[['fasta_name', 'mutationinformation']]
all_muts_msa_sorted.head() all_muts_msa_sorted.head()
print('Checking NA in snps...')# should be 0 print('Checking NA in snps...')# should be 0
if all_muts_msa.Mutationinformation.isna().sum() == 0: if all_muts_msa.mutationinformation.isna().sum() == 0:
print ('PASS: NO NAs/missing entries for SNPs' print ('PASS: NO NAs/missing entries for SNPs'
, '\n===============================================================') , '\n===============================================================')
else: else:

View file

@ -30,10 +30,8 @@ os.getcwd()
#======================================================================= #=======================================================================
#%% command line args #%% command line args
arg_parser = argparse.ArgumentParser() arg_parser = argparse.ArgumentParser()
#arg_parser.add_argument('-d', '--drug', help='drug name', default = 'pyrazinamide') arg_parser.add_argument('-d', '--drug', help='drug name', default = None)
#arg_parser.add_argument('-g', '--gene', help='gene name', default = 'pncA') # case sensitive arg_parser.add_argument('-g', '--gene', help='gene name (case sensitive)', default = None) # 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
args = arg_parser.parse_args() args = arg_parser.parse_args()
#======================================================================= #=======================================================================
#%% variable assignment: input and output #%% variable assignment: input and output
@ -49,6 +47,8 @@ args = arg_parser.parse_args()
drug = args.drug drug = args.drug
gene = args.gene gene = args.gene
gene_match = gene + '_p.'
#========== #==========
# data dir # data dir
#========== #==========
@ -147,7 +147,7 @@ def extract_chain_dssp(inputpdbfile):
return pdbchainlist return pdbchainlist
#======================================================================= #=======================================================================
#%% write csv of processed dssp output #%% write csv of processed dssp output
def dssp_to_csv(inputdsspfile, outfile, pdbchainlist): def dssp_to_csv(inputdsspfile, outfile, pdbchainlist = ['A']):
""" """
Create a df from a dssp file containing ASA, RSA, SS for all chains Create a df from a dssp file containing ASA, RSA, SS for all chains

View file

@ -39,10 +39,8 @@ os.getcwd()
#======================================================================= #=======================================================================
#%% command line args #%% command line args
arg_parser = argparse.ArgumentParser() arg_parser = argparse.ArgumentParser()
#arg_parser.add_argument('-d', '--drug', help='drug name', default = 'pyrazinamide') arg_parser.add_argument('-d', '--drug', help='drug name', default = None)
#arg_parser.add_argument('-g', '--gene', help='gene name', default = 'pncA') # case sensitive arg_parser.add_argument('-g', '--gene', help='gene name', default = None)
arg_parser.add_argument('-d', '--drug', help='drug name', default = 'DRUGNAME')
arg_parser.add_argument('-g', '--gene', help='gene name', default = 'geneName')
#arg_parser.add_argument('-p', '--plot', help='show plot', action='store_true') #arg_parser.add_argument('-p', '--plot', help='show plot', action='store_true')
args = arg_parser.parse_args() args = arg_parser.parse_args()
#======================================================================= #=======================================================================
@ -81,7 +79,7 @@ print('Output filename:', out_filename
#%% end of variable assignment for input and output files #%% end of variable assignment for input and output files
#======================================================================= #=======================================================================
#%% kd values from fasta file and output csv #%% kd values from fasta file and output csv
def kd_to_csv(inputfasta, outputkdcsv, windowsize): def kd_to_csv(inputfasta, outputkdcsv, windowsize = 3):
""" """
Calculate kd (hydropathy values) from input fasta file Calculate kd (hydropathy values) from input fasta file
@ -223,8 +221,7 @@ def main():
, '\noutfile:', out_filename) , '\noutfile:', out_filename)
kd_to_csv(infile, outfile, 3) kd_to_csv(infile, outfile, 3)
print('Finished writing file:' print('Finished writing file:'
, '\nFilename:', out_filename , '\nFilename:', outfile
, '\nPath:', outdir
, '\n=============================================================') , '\n=============================================================')
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -31,10 +31,8 @@ os.getcwd()
#======================================================================= #=======================================================================
#%% command line args #%% command line args
arg_parser = argparse.ArgumentParser() arg_parser = argparse.ArgumentParser()
#arg_parser.add_argument('-d', '--drug', help='drug name', default = 'pyrazinamide') arg_parser.add_argument('-d', '--drug', help='drug name', default = None)
#arg_parser.add_argument('-g', '--gene', help='gene name', default = 'pncA') # case sensitive arg_parser.add_argument('-g', '--gene', help='gene name', default = None) # 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
args = arg_parser.parse_args() args = arg_parser.parse_args()
#======================================================================= #=======================================================================
#%% variable assignment: input and output #%% variable assignment: input and output
@ -165,8 +163,7 @@ def main():
, '\noutfile:', out_filename) , '\noutfile:', out_filename)
rd_to_csv(infile, outfile) rd_to_csv(infile, outfile)
print('Finished Writing file:' print('Finished Writing file:'
, '\nFilename:', out_filename , '\nFilename:', outfile
, '\nPath:', outdir
, '\n=============================================================') , '\n=============================================================')
if __name__ == '__main__': if __name__ == '__main__':