46 lines
No EOL
1.8 KiB
Text
46 lines
No EOL
1.8 KiB
Text
from nupack import *
|
||
import subprocess
|
||
import os
|
||
|
||
def huatu(Complex,result):#Complex是你想查看的复合物,eg: '(StrandA+StrandB)' 引号和括号都要有;
|
||
#result是nupack计算(tube_analysis)的结果,eg: nupack指南里用过my_result、my_results和tube_results等, 或者你自己有其他命名
|
||
def jiegou(Complex,result):
|
||
m=str(result[Complex].mfe[0].structure)
|
||
mm=""
|
||
for i in m:
|
||
if i != "+":
|
||
mm=mm+i
|
||
if i=="":
|
||
continue
|
||
return mm
|
||
def xulie(Complex):
|
||
inp=''
|
||
for i in Complex:
|
||
if i != '(' and i != ')':
|
||
inp=inp+i
|
||
else:
|
||
continue
|
||
l=inp.split('+',-1)
|
||
xulie=''
|
||
for i in l:
|
||
xulie=xulie+str(eval(i))
|
||
return xulie
|
||
sequence=xulie(Complex)
|
||
best_structure=jiegou(Complex,result)
|
||
seq_name =Complex
|
||
output_folder="/home/liusiye/桌面/nupack-4.1.0.1"#指定图片保存在哪个文件夹,需自己更改
|
||
temp_file_path = os.path.join(output_folder, f"{seq_name}.seq")
|
||
with open(temp_file_path, "w", newline='\n') as f:
|
||
f.write(f">{seq_name}\n")
|
||
f.write(f"{sequence}\n")
|
||
f.write(f"{best_structure}\n")
|
||
try:
|
||
input_filename = f"{seq_name}.seq"
|
||
process = subprocess.run(["RNAplot", "--o", "svg", input_filename], cwd=output_folder, capture_output=True, text=True)
|
||
if process.returncode == 0:
|
||
print(f"🎉 绘图成功!请前往 {output_folder} 文件夹查看 {seq_name}_ss.svg")
|
||
os.remove(temp_file_path)
|
||
else:
|
||
print("❌ RNAplot 运行失败,报错信息:\n", process.stderr)
|
||
except FileNotFoundError:
|
||
print("❌ 找不到 RNAplot 命令,请确认环境变量。") |