pkl = open(pklname, 'w') pickle.dump(argdict, pkl) pkl.close() # a few things should be keep the same: # the name of the pdb file (without .pdb extension) # first column of the mutation file # first column of the homologous file # there should not be '_' in these # read the input file and create a mutation list pdbs = [] positions = [] with open(args.l) as mutf: for l in mutf: mut = Stability.getMutation(l.strip()) pdb, pos = mut.p, mut.dir if not pdb in pdbs: pdbs.append(pdb) if not pos in positions: positions.append(pos) # run confind for all structures for pdb in pdbs: pdbf = args.i + '/' + pdb + '.pdb' assert os.path.isfile( pdbf), 'the pdb file ' + pdbf + ' does not exist; quit...' confind_out = changeExt(pdbf, 'conf') if os.path.isfile(confind_out): continue else: # run confind
def outputscore(mutlist, output, scan=0, bg=0): if bg: aafreq = np.array(PDB.aaFreq) with open(mutlist) as mutf, open(output, 'w') as ofh: for l in mutf: l = l.strip() mut = Stability.getMutation(l) consf = mut.dir + '/' + mut.dir + '.conlist' cons = [] with open(consf) as cf: for cfl in cf: cinfo = cfl.strip().split() conname, conres, cond = cinfo[2], cinfo[-1], float( cinfo[3]) if not os.path.isfile(mut.dir + '/' + mut.dir + '_' + conname.replace(',', '') + '.pdb'): continue if cond >= 0.02: cons.append([conname, conres, cond]) cons = sorted(cons, key=lambda x: x[0]) matf = mut.dir + '/' + mut.dir + '.' + args.ext + '.mat' if not os.path.isfile(matf): ofh.write(l + '\tNA\n') continue optparams = loadmat(matf)['optParams'] assert (optparams.shape[0] - 20) / 400 == len(cons), mut.dir # if (optparams.shape[0] - 20) / 400 != len(cons): # ofh.write(l + '\tNA\n') # continue selfdiff = optparams[PDB.aaindex[mut.m]] - optparams[PDB.aaindex[ mut.w]] if bg: selfdiff += np.log(aafreq[PDB.aaindex[mut.m]]) - np.log( aafreq[PDB.aaindex[mut.w]]) pairdiff = [] if scan: scanscore = optparams[0:20].T[0] if bg: scanscore += np.log(aafreq) scanscore -= scanscore[PDB.aaindex[mut.w]] for i in range(len(cons)): paramsi = optparams[20 + 400 * i:20 + 400 * (i + 1)].reshape( 20, 20) conind = PDB.aaindex[PDB.t2s(cons[i][1])] pairdiff_i = paramsi[conind, PDB.aaindex[mut.m]] - paramsi[ conind, PDB.aaindex[mut.w]] pairdiff.append(pairdiff_i) # outstr = l + '\t' + cons[i][0] + '\t' + format(float(pairdiff_i), '.3f') # test # ofh.write(outstr + '\n') # test if scan: scancon = np.array([paramsi[conind, x] for x in range(20)]) # use wt aa as the reference state ref = paramsi[conind, PDB.aaindex[mut.w]] scancon -= ref scanscore += scancon if not scan: outstr = '\t'.join([ l, format(float(selfdiff), '.3f'), format(float(sum(pairdiff)), '.3f') ]) else: outstr = '\t'.join([l] + [format(x, '.3f') for x in scanscore]) ofh.write(outstr + '\n') # exit the program exit(0)