lkjjj26 commited on
Commit
8edecbd
ยท
1 Parent(s): 12f8076

update id_to_seq process

Browse files
Files changed (1) hide show
  1. app.py +28 -23
app.py CHANGED
@@ -1,5 +1,5 @@
1
  from transformers import pipeline
2
- from rcsbsearchapi import TextQuery, AttributeQuery, Query
3
  from rcsbsearchapi.search import Sort, SequenceQuery
4
  import os
5
  from dotenv import load_dotenv
@@ -375,10 +375,34 @@ class PDBSearchAssistant:
375
  pdir=self.pdb_dir,
376
  file_format="pdb"
377
  )
378
-
379
  if not pdb_path or not os.path.exists(pdb_path):
380
  print(f"Failed to download PDB file for {pdb_id}")
381
- return []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
382
 
383
  # Parse structure
384
  parser = PDB.PDBParser(QUIET=True)
@@ -455,6 +479,7 @@ class PDBSearchAssistant:
455
 
456
  if is_sequence_query and pdb_id:
457
  # Get sequences for the PDB ID
 
458
  sequences = self.get_sequences_by_pdb_id(pdb_id)
459
  return {
460
  "type": "sequence",
@@ -471,26 +496,6 @@ class PDBSearchAssistant:
471
  print(f"Error processing query: {str(e)}")
472
  return {"type": "structure", "results": []}
473
 
474
- def pdbsummary(name):
475
-
476
- search_engine = ProteinSearchEngine()
477
-
478
- query = ProteinQuery(
479
- name,
480
- max_resolution= 5.0
481
- )
482
-
483
- results = search_engine.search(query)
484
-
485
- answer = ""
486
- for i, structure in enumerate(results, 1):
487
- answer += f"\n{i}. PDB ID : {structure.pdb_id}\n"
488
- answer += f"\nResolution : {structure.resolution:.2f} A \n"
489
- answer += f"Method : {structure.method}\n Title : {structure.title}\n"
490
- answer += f"Release Date : {structure.release_date}\n Sequence length: {len(structure.sequence)} aa\n"
491
- answer += f" Sequence:\n {structure.sequence}\n"
492
-
493
- return answer
494
 
495
  def render_html(pdb_id):
496
  if pdb_id is None:
 
1
  from transformers import pipeline
2
+ from rcsbsearchapi import TextQuery, AttributeQuery
3
  from rcsbsearchapi.search import Sort, SequenceQuery
4
  import os
5
  from dotenv import load_dotenv
 
375
  pdir=self.pdb_dir,
376
  file_format="pdb"
377
  )
378
+ print(pdb_path)
379
  if not pdb_path or not os.path.exists(pdb_path):
380
  print(f"Failed to download PDB file for {pdb_id}")
381
+
382
+ structure_url = f"https://data.rcsb.org/rest/v1/core/entry/{pdb_id}"
383
+ response = requests.get(structure_url)
384
+ structure_data = response.json() if response.status_code == 200 else {}
385
+
386
+
387
+ sequence_url = f"https://data.rcsb.org/rest/v1/core/polymer_entity/{pdb_id}/1"
388
+ seq_response = requests.get(sequence_url)
389
+ seq_data = seq_response.json() if response.status_code == 200 else {}
390
+ sequence = seq_data.get('entity_poly', {}).get('pdbx_seq_one_letter_code', 'N/A')
391
+
392
+ sequences = []
393
+
394
+ chain_info = {
395
+ 'chain_id': "A", # chain.id, ์ž„์˜ ์„ค์ • api 3๊ฐœ์จ์„œ ๊ฐ€์ ธ์˜ค๊ธฐ๋Š” ๊ฐ€๋Šฅ
396
+ 'entity_id': '1', # Default entity ID
397
+ 'description': structure_data.get('struct', {}).get('title', 'N/A'),
398
+ 'sequence': sequence,
399
+ 'length': len(sequence),
400
+ 'resolution': structure_data.get('rcsb_entry_info', {}).get('resolution_combined', [0.0])[0],
401
+ 'method': structure_data.get('exptl', [{}])[0].get('method', 'Unknown'),
402
+ 'release_date': structure_data.get('rcsb_accession_info', {}).get('initial_release_date', 'N/A')
403
+ }
404
+ sequences.append(chain_info)
405
+ return sequences
406
 
407
  # Parse structure
408
  parser = PDB.PDBParser(QUIET=True)
 
479
 
480
  if is_sequence_query and pdb_id:
481
  # Get sequences for the PDB ID
482
+
483
  sequences = self.get_sequences_by_pdb_id(pdb_id)
484
  return {
485
  "type": "sequence",
 
496
  print(f"Error processing query: {str(e)}")
497
  return {"type": "structure", "results": []}
498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
499
 
500
  def render_html(pdb_id):
501
  if pdb_id is None: