Skip to content

Commit

Permalink
rna_tools/rna_tools_lib.py: add fetch-cif
Browse files Browse the repository at this point in the history
  • Loading branch information
mmagnus committed Oct 11, 2024
1 parent f1c0032 commit 47ffa8e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
11 changes: 10 additions & 1 deletion rna_tools/rna_pdb_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import glob
import os
from rna_tools.rna_tools_lib import edit_pdb, add_header, get_version, \
collapsed_view, fetch, fetch_ba, replace_chain, RNAStructure, \
collapsed_view, fetch, fetch_ba, fetch_cif, replace_chain, RNAStructure, \
select_pdb_fragment, sort_strings, set_chain_for_struc
from rna_tools.tools.rna_x3dna.rna_x3dna import x3DNA

Expand Down Expand Up @@ -122,6 +122,8 @@ def get_parser():
parser.add_argument('--fetch', action='store_true', help='fetch file from the PDB db, e.g., 1xjr,\nuse \'rp\' to fetch, fetch a given join, 4w90:C or 4w90_C' +
'the RNA-Puzzles standardized_dataset [around 100 MB]')

parser.add_argument('--fetch-cif', action='store_true', help='')

parser.add_argument('--fetch-ba', action='store_true',
help='fetch biological assembly from the PDB db')

Expand Down Expand Up @@ -894,6 +896,13 @@ def get_parser():
if args.fetch_ba:
fetch_ba(args.file)

if args.fetch_cif:
if list != type(args.file):
args.file = [args.file]
##################################
for f in args.file:
fetch_cif(f)

if args.collapsed_view or args.cv:
collapsed_view(args)

Expand Down
17 changes: 17 additions & 0 deletions rna_tools/rna_tools_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,23 @@ def fetch_cif_ba(cif_id, path="."):
print('ok')
return cif_id + '_ba.cif'

def fetch_cif(cif_id, path="."):
"""fetch biological assembly cif file from RCSB.org"""
import urllib3
http = urllib3.PoolManager()
# try:
ic(cif_id)
response = http.request('GET', url='https://files.rcsb.org/download/' +
cif_id.lower() + '.cif')
if not response.status == 200:
raise PDBFetchError()
txt = response.data

npath = path + os.sep + cif_id + '.cif'
#print('downloading... ' + npath)
with open(npath, 'wb') as f:
f.write(txt)
return cif_id + '.cif'

def replace_chain(struc_fn, insert_fn, chain_id):
"""Replace chain of the main file (struc_fn) with some new chain (insert_fn) of given chain id.
Expand Down

0 comments on commit 47ffa8e

Please sign in to comment.