| import os |
| import subprocess |
| import argparse |
| from evcouplings.couplings import CouplingsModel |
| from Bio import AlignIO |
| from Bio.Align import MultipleSeqAlignment |
| from Bio.SeqRecord import SeqRecord |
| from Bio.Seq import Seq |
| import numpy as np |
| import pandas as pd |
|
|
|
|
| if __name__ == "__main__": |
| parser = argparse.ArgumentParser(description="Run Jackhmmer and EVcouplings on a query sequence") |
| parser.add_argument("--query_file", default=None, help="Query sequence file") |
| parser.add_argument("--database", default=None, help="Database file") |
| parser.add_argument("--bitscores", default=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], type=float, nargs="+", help="Bitscore thresholds") |
| parser.add_argument("--iterations", default=5, type=int, help="Number of Jackhmmer iterations") |
| parser.add_argument("--output_dir", default=None, help="Output directory") |
| args = parser.parse_args() |
|
|
| |
| |
| |
| |
| |
| |
|
|
| |
| os.makedirs(args.output_dir, exist_ok=True) |
|
|
| |
| best_msa_file = None |
| max_significant_ecs = -1 |
|
|
| |
| for bit_score in args.bitscores: |
| print(f"\n运行Jackhmmer,比特得分阈值:{bit_score}") |
| output_prefix = f"bitscore_{bit_score}" |
| alignment_sto_file = os.path.join(args.output_dir, f"{output_prefix}.sto") |
| alignment_a2m_file = os.path.join(args.output_dir, f"{output_prefix}.a2m") |
| tblout_file = os.path.join(args.output_dir, f"{output_prefix}_tblout.txt") |
| jackhmmer_output = os.path.join(args.output_dir, f"{output_prefix}_jackhmmer.txt") |
| |
| |
| jackhmmer_cmd = [ |
| "jackhmmer", |
| "-N", str(args.iterations), |
| "--incT", str(bit_score), |
| "--cpu", "4", |
| "--tblout", tblout_file, |
| "-A", alignment_sto_file, |
| args.query_file, |
| args.database |
| ] |
| |
| |
| with open(jackhmmer_output, "w") as out_f: |
| subprocess.run(jackhmmer_cmd, stdout=out_f) |
| |
| |
| if not os.path.isfile(alignment_sto_file): |
| print(f"比特得分 {bit_score} 下未生成对齐文件。") |
| continue |
| |
| |
| with open(alignment_sto_file, "r") as input_handle: |
| alignments = AlignIO.read(input_handle, "stockholm") |
| |
| |
| a2m_alignment = MultipleSeqAlignment( |
| [SeqRecord(Seq(str(record.seq).replace('-', '.')), id=record.id, description="") for record in alignments] |
| ) |
| |
| with open(alignment_a2m_file, "w") as output_handle: |
| AlignIO.write(a2m_alignment, output_handle, "fasta") |
| |
| print(f"已将对齐文件转换为A2M格式:{alignment_a2m_file}") |
| |
| |