Skip to content

Commit

Permalink
Merge pull request prody#1988 from jamesmkrieger/pdb_ftp
Browse files Browse the repository at this point in the history
PDB FTP hot fixes
  • Loading branch information
jamesmkrieger authored Nov 14, 2024
2 parents 94bc3e9 + 0d85824 commit 2b65775
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
7 changes: 5 additions & 2 deletions prody/proteins/cifheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,11 @@ def _getReference(lines):
except:
continue
if what == 'AUTH':
surname, initials = value.split(',')
author = initials+surname
try:
surname, initials = value.split(',')
author = initials+surname
except ValueError:
author = value
authors.append(author.strip().upper())

ref['authors'] = authors
Expand Down
7 changes: 5 additions & 2 deletions prody/proteins/localpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,15 @@ def fetchPDB(*pdb, **kwargs):
if len(pdb) == 1 and isinstance(pdb[0], list):
pdb = pdb[0]

identifiers = checkIdentifiers(*pdb)

folder = kwargs.get('folder', '.')
compressed = kwargs.get('compressed')
format_ = kwargs.get('format', 'pdb')

if format_ != 'emd':
identifiers = checkIdentifiers(*pdb)
else:
identifiers = pdb

# check *folder* specified by the user, usually pwd ('.')
filedict = findPDBFiles(folder, compressed=compressed,
format=format_)
Expand Down
6 changes: 4 additions & 2 deletions prody/proteins/pdbfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,15 @@ def _parsePDB(pdb, **kwargs):
if filename is None:
try:
LOGGER.warn("Trying to parse mmCIF file instead")
chain = kwargs.pop('chain', chain)
return parseMMCIF(pdb+chain, **kwargs)
except:
except OSError:
try:
LOGGER.warn("Trying to parse EMD file instead")
chain = kwargs.pop('chain', chain)
return parseEMD(pdb+chain, **kwargs)
except:
raise IOError('PDB file for {0} could not be downloaded.'
raise IOError('PDB file for {0} could not be parsed.'
.format(pdb))
pdb = filename
if title is None:
Expand Down
22 changes: 20 additions & 2 deletions prody/proteins/wwpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,22 @@ def fetchPDBviaHTTP(*pdb, **kwargs):
output_folder = kwargs.pop('folder', None)
compressed = bool(kwargs.pop('compressed', True))

extension = '.pdb'
format = kwargs.get('format', 'pdb')
noatom = bool(kwargs.pop('noatom', False))
if format == 'pdb':
extension = '.pdb'
elif format == 'xml':
if noatom:
extension = '-noatom.xml'
else:
extension = '.xml'
elif format == 'cif':
extension = '.cif'
elif format == 'emd' or format == 'map':
extension = '.map'
else:
raise ValueError(repr(format) + ' is not valid format')

local_folder = pathPDBFolder()
if local_folder:
local_folder, is_divided = local_folder
Expand Down Expand Up @@ -294,7 +309,10 @@ def fetchPDBviaHTTP(*pdb, **kwargs):
filenames.append(None)
continue
try:
handle = openURL(getURL(pdb))
url = getURL(pdb)
if kwargs.get('format', 'pdb') != 'pdb':
url = url.replace('.pdb', extension)
handle = openURL(url)
except Exception as err:
LOGGER.warn('{0} download failed ({1}).'.format(pdb, str(err)))
failure += 1
Expand Down
15 changes: 3 additions & 12 deletions prody/tests/proteins/test_wwpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
LOGGER.verbosity = 'none'


class TestFTP(unittest.TestCase):
class TestHTTP(unittest.TestCase):

def setUp(self):

self.pdb = ['1ubi', '1aar', 'arg', 1234]
self.fns = []
self.len = [683, 1218, None, None]
self.fetch = fetchPDBviaFTP
self.protocol = 'FTP'
self.fetch = fetchPDBviaHTTP
self.protocol = 'HTTP'


@dec.slow
Expand Down Expand Up @@ -69,12 +69,3 @@ def tearDown(self):
pass
except:
pass

class TestHTTP(TestFTP):

def setUp(self):

TestFTP.setUp(self)
self.fetch = fetchPDBviaHTTP
self.protocol = 'HTTP'

0 comments on commit 2b65775

Please sign in to comment.