Repository navigation
Expand file tree
/
Copy pathcli.py
More file actions
150 lines (129 loc) · 4.51 KB
/
Copy pathcli.py
File metadata and controls
150 lines (129 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# cli.py
import click
import sys
import requests
from utils.fetcher import fetch_pdb
from utils.parser import parse_pdb
from utils.llm import generate_summary
from analysis import metadata, amino_acids
from analysis.secondary_structure import (
parse_secondary_structure,
structure_to_ascii,
format_structure_output
)
from analysis.visualizer import animate_structure
@click.group()
def cli():
"""🔬 PDB Insight - Terminal Tool for Structure Analysis and quick reference"""
pass
# --- 📥 GESTIÓN DE ARCHIVOS ---
@cli.command()
@click.argument("pdb_id")
def fetch(pdb_id):
"""Download a PDB file by ID"""
fetch_pdb(pdb_id)
@cli.command()
@click.argument("filename")
def stats(filename):
"""Show structure statistics (atoms, residues, etc.)"""
parse_pdb(filename)
@cli.command()
@click.argument("pdb_id")
def meta(pdb_id):
"""Show basic metadata for a PDB ID"""
pdb_data = fetch_pdb(pdb_id)
if pdb_data:
meta_data = metadata.extract_metadata(pdb_data)
metadata.print_metadata(meta_data, pdb_id)
# --- 🧬 ANÁLISIS DE SECUENCIA ---
@cli.command("count-amino-acids")
@click.argument("pdb_id")
@click.option("--plot", is_flag=True, help="Show bar chart of amino acid counts")
def count_amino_acids(pdb_id, plot):
"""Count amino acids for a PDB ID (chain A)"""
pdb_data = fetch_pdb(pdb_id)
if pdb_data:
sequence = amino_acids.parse_chain_sequence(pdb_data)
counts = amino_acids.count_amino_acids(sequence)
click.echo(f"\nAmino acid counts for {pdb_id}:\n")
for aa, count in sorted(counts.items()):
click.echo(f"{aa}: {count}")
if plot:
amino_acids.plot_amino_acid_counts(counts, f"Amino Acid Counts for {pdb_id}")
@cli.command()
@click.argument("pdb_id")
def sequence(pdb_id):
"""Show amino acid sequences for all chains of a PDB ID"""
pdb_data = fetch_pdb(pdb_id)
if not pdb_data:
return
try:
chains = amino_acids.parse_chain_sequences(pdb_data)
amino_acids.print_sequences(chains)
except Exception as e:
click.echo(f"❌ Error extracting sequence: {e}")
# --- 📊 VISUALIZACIÓN ---
@cli.command()
@click.argument('pdb_id')
def ssvis(pdb_id):
"""Visualize secondary structure (1D ASCII) for a given PDB ID."""
pdb_data = fetch_pdb(pdb_id)
if not pdb_data:
click.secho(f"❌ Failed to fetch data for {pdb_id}", fg='red')
return
pdb_lines = pdb_data.splitlines()
structure_map = parse_secondary_structure(pdb_lines)
# Usa la función unificada de amino_acids.py
sequences = amino_acids.extract_sequences(pdb_lines)
for chain_id, (seq, residue_ids) in sequences.items():
click.echo(f"\n===== Chain {chain_id} =====")
struct_line = structure_to_ascii(residue_ids, structure_map.get(chain_id, {}))
output = format_structure_output(seq, struct_line)
click.echo(output)
click.echo("\nLegend: H = Helix, E = Beta sheet, - = Loop/Other")
@cli.command()
@click.argument("pdb_id")
@click.option("--chain", default=None, help="Filter by chain (e.g., A)")
@click.option("--steps", default=100, help="Number of animation frames")
def view3d(pdb_id, chain, steps):
"""3D ASCII Animation of the protein backbone (CA-trace)"""
pdb_data = fetch_pdb(pdb_id)
if not pdb_data:
return
# Limpiar pantalla y ocultar cursor
sys.stdout.write("\033[2J\033[?25l")
try:
animate_structure(pdb_data.splitlines(), steps=steps, chain_filter=chain)
finally:
# Asegurar que el cursor vuelva a aparecer siempre
sys.stdout.write("\033[?25h\n")
# --- 💡 INTELIGENCIA ARTIFICIAL ---
@cli.command()
@click.argument("filename")
@click.option("--model", default="llama3.2", help="Ollama model to use")
def summary(filename, model):
"""Generate LLM-based summary of the protein structure"""
generate_summary(filename, model)
if __name__ == "__main__":
cli()
##LLM and visualization blocks
'''
# 💡 LLM summary of the structure
@cli.command()
@click.argument("filename")
def summary(filename):
"""Generate LLM-based summary"""
generate_summary(filename)
# 🔎 Open structure viewer
@cli.command()
@click.argument("filename")
def visualize(filename):
"""Visualize the PDB structure in the browser"""
launch_viewer(filename)
@cli.command()
@click.argument("filename")
@click.option("--model", default="llama3.2", help="Ollama model to use")
def summarize(filename, model):
"""Summarize a local PDB file with LLM help"""
generate_summary(filename, model)
'''