diff --git a/prody/proteins/cifheader.py b/prody/proteins/cifheader.py index 62bcbdb75..0d667cea2 100644 --- a/prody/proteins/cifheader.py +++ b/prody/proteins/cifheader.py @@ -877,6 +877,7 @@ def _getPolymers(lines, **kwargs): polymers = dict() entities = defaultdict(list) + longSeq = kwargs.get('longSeq', False) # SEQRES block items1 = parseSTARSection(lines, '_entity_poly', report=False) diff --git a/prody/proteins/localpdb.py b/prody/proteins/localpdb.py index a6ac58c41..a2d50a8b5 100644 --- a/prody/proteins/localpdb.py +++ b/prody/proteins/localpdb.py @@ -251,7 +251,7 @@ def fetchPDB(*pdb, **kwargs): 'specify another folder'.format(folder)) if compressed is not None and not compressed: - filedict = findPDBFiles(folder, compressed=True) + filedict = findPDBFiles(folder, compressed=True, format=format_) not_found, decompress = [], not_found for i, pdb in decompress: if pdb in filedict: diff --git a/prody/proteins/wwpdb.py b/prody/proteins/wwpdb.py index 82e608f9d..efd942cc7 100644 --- a/prody/proteins/wwpdb.py +++ b/prody/proteins/wwpdb.py @@ -341,10 +341,14 @@ def fetchPDBviaHTTP(*pdb, **kwargs): try: url = getURL(pdb) if format != 'pdb': - url = url.replace('.pdb', extension) + if url.find('.pdb') != -1: + url = url.replace('.pdb', extension) + elif url.find('.ent') != -1: + url = url.replace('.ent', extension) if url.find('divided/pdb') != -1: url = url.replace('divided/pdb', 'divided/' + long_format) + handle = openURL(url) except Exception as err: if not _isExtendedPDBID(pdb): diff --git a/prody/tests/proteins/test_ciffile.py b/prody/tests/proteins/test_ciffile.py index 384e9e934..f205afcc7 100644 --- a/prody/tests/proteins/test_ciffile.py +++ b/prody/tests/proteins/test_ciffile.py @@ -121,7 +121,14 @@ def testLongChainArgument(self): self.no_pdb['segment_SX0_atoms'], 'parseMMCIF failed to parse correct number of atoms ' 'when segment SX0 is specified') - + + def testSkipPDBs(self): + """Test outcome of valid and invalid *segment* arguments.""" + + pdb = self.altlocs['pdb'] + _ = parsePDB(pdb) + _ = parseMMCIF(pdb) + def testUniteChainsArgument(self): """Test outcome of valid and invalid *segment* arguments.""" @@ -468,6 +475,11 @@ def testAltlocAllMultiModels(self): self.assertEqual(ag.numCoordsets(), self.multi['models'], 'parsePDB failed to parse correct number of coordsets ({0}) with altloc "all"'.format(self.multi['models'])) + def testLongSeqFix(self): + """Test the outcome of parsing 3o21 from id, which failed previously.""" + + _ = parseMMCIF('3o21') + def testStopScipion(self): """Test number of coordinate sets and atoms for PyMOL CIF file with altloc='all'.""" diff --git a/prody/utilities/pathtools.py b/prody/utilities/pathtools.py index a84b1ceaf..c630b904b 100644 --- a/prody/utilities/pathtools.py +++ b/prody/utilities/pathtools.py @@ -216,6 +216,12 @@ def gunzip(filename, outname=None): else: outname = filename + # Quick gzip magic number check + with open(filename, 'rb') as f: + magic = f.read(2) + if magic != b'\x1f\x8b': + raise ValueError(f"File {filename} is not a valid gzip file") + inp = gzip_open(filename, 'rb') data = inp.read() inp.close() @@ -224,6 +230,10 @@ def gunzip(filename, outname=None): out.close() return outname else: + # filename is a buffer, so check directly without opening + if filename[:2] != b'\x1f\x8b': + raise ValueError("Buffer is not gzipped or is invalid content") + result = None try: from StringIO import StringIO