用Python改写以下代码for i in $(ls ${contact_dir});do #temp: 1acb_E-by #temp1: 1acb_E temp=$(echo ${i%-*}) temp1=$(echo ${temp%-*}) awk '{if(!a[$6]++) print $6}' ${contact_dir}/${i} >${contact_dir}/${temp}-res.txt for j in $(cat ${contact_dir}/${temp}-res.txt);do cat ${contact_dir}/${temp}-res.vor | awk '$6=='$j'{print $0}' >${patch_dir}/${temp}_patch_${j}.txt value=0 for l in $(awk '{print $2}' ${patch_dir}/${temp}_patch_${j}.txt);do #echo $l res=$(awk '{print $2}' ${surface_dir}/${temp1}_surface.txt) #echo $res if ( echo ${res} | grep -q $l);then value=1 fi done #patch_abs for k in $(awk '{print $2}' ${patch_dir}/${temp}_patch_${j}.txt);do cat ${rsa_dir}/${temp1}_abs.txt | awk '$3=='$k'{print $0}' >>${patch_abs_dir}/${temp1}_patch_${j}.txt done for m in $(awk '{print $2}' ${patch_dir}/${temp}_patch_${j}.txt);do for n in $(awk '{print $2}' ${patch_dir}/${temp}_patch_${j}.txt);do if [ $n -ne $m ];then cat ${contact_dir}/${temp}-res.vor | awk '$2=='$m' && $6=='$n' {print $0}' >>${patch_contact_dir}/${temp1}_patch_${j}.txt fi done done #### abs=$(awk '{sum += $4};END {print sum}' ${patch_abs_dir}/${temp1}_patch_${j}.txt) con=$(awk '{sum += $9};END {print sum}' ${patch_contact_dir}/${temp1}_patch_${j}.txt) psaia=$(echo "$abs*$con" | bc) echo $j $abs $con $psaia >>${patch_psaia_dir}/${temp1}.txt #echo $j $con >>${patch_psaia_dir}/${temp1}_con.txt #### #echo $value if [ $value = 0 ];then #echo ${patch_dir}/${temp}_patch_${j} rm ${patch_dir}/${temp}_patch_${j}.txt fi done done
时间: 2023-06-23 15:09:00 浏览: 90
以下是用 Python 重写的代码:
```python
import os
contact_dir = './contact_dir'
patch_dir = './patch_dir'
surface_dir = './surface_dir'
rsa_dir = './rsa_dir'
patch_abs_dir = './patch_abs_dir'
patch_contact_dir = './patch_contact_dir'
patch_psaia_dir = './patch_psaia_dir'
for i in os.listdir(contact_dir):
# temp: 1acb_E-by
# temp1: 1acb_E
temp = i.split('-')[0]
temp1 = temp.split('-')[0]
with open(f'{contact_dir}/{i}') as f:
contacts = f.read().splitlines()
unique_contacts = list(set([c.split()[5] for c in contacts]))
with open(f'{contact_dir}/{temp}-res.txt', 'w') as f:
f.write('\n'.join(unique_contacts))
for j in unique_contacts:
with open(f'{contact_dir}/{temp}-res.vor') as f:
patch_j = [line for line in f if line.split()[5] == j]
value = 0
for l in patch_j:
res = open(f'{surface_dir}/{temp1}_surface.txt').read()
if l.split()[1] in res:
value = 1
# patch_abs
with open(f'{patch_abs_dir}/{temp1}_patch_{j}.txt', 'w') as f:
for k in patch_j:
with open(f'{rsa_dir}/{temp1}_abs.txt') as f2:
patch_abs = [line for line in f2 if line.split()[2] == k.split()[1]]
f.write('\n'.join(patch_abs))
# patch_contact
with open(f'{patch_contact_dir}/{temp1}_patch_{j}.txt', 'w') as f:
for m in patch_j:
for n in patch_j:
if n.split()[1] != m.split()[1]:
with open(f'{contact_dir}/{temp}-res.vor') as f2:
patch_contact = [line for line in f2 if line.split()[1] == m.split()[1] and line.split()[5] == n.split()[5]]
f.write('\n'.join(patch_contact))
# psaia
abs_sum = sum(float(line.split()[3]) for line in open(f'{patch_abs_dir}/{temp1}_patch_{j}.txt'))
con_sum = sum(float(line.split()[8]) for line in open(f'{patch_contact_dir}/{temp1}_patch_{j}.txt'))
psaia = abs_sum * con_sum
with open(f'{patch_psaia_dir}/{temp1}.txt', 'a') as f:
f.write(f'{j} {abs_sum} {con_sum} {psaia}\n')
if value == 0:
os.remove(f'{patch_dir}/{temp}_patch_{j}.txt')
```
注意,这里只是根据原始代码的语法和意思进行的重写,可能还需要根据实际情况进行调整。
阅读全文