Repository navigation
Bio.PDB.PDBList update - #943
Conversation
1. Possibility to download structures in PDBx/mmCif, PDB, PDBML/XML and mmtf formats 2. Possibility to download large structures in PDB-like formatted bundles 3. New function: download specified set of structures 4. Code python 3.x comatible 5. Unit tests added. Note. The default download format changed from (deprecated) PDB to (recommended by RCSB) PDBx/mmCIf.
Update Bio.PDB.PDBList module
|
The PEP8 issues reported by TravisCI should be easy to fix: (This just runs the command line tool |
|
Does this look like an intermittent network failure on TravisCI? As an aside, can you add this to |
|
Can this also handle the RSSB's new binary Macromolecular Transmission Format (MMTF, see http://mmtf.rcsb.org)? CC @abradle |
|
Are you happy to dual license your contribution(s) under both the Biopython Licence Agreement and the 3-Clause BSD licence? See #898 |
|
Seems to be a different behavior of urlretrieve function under python 2 and python 3. It fails on python 2 when I try to download second time the same file. Don't know (yet) how to resolve this. |
| return obsolete | ||
|
|
||
| def retrieve_pdb_file(self, pdb_code, obsolete=False, pdir=None): | ||
| def retrieve_pdb_file(self, pdb_code, file_format='mmCif', overwrite=False, obsolete=False, pdir=None): |
There was a problem hiding this comment.
By changing the argument order your have broken backward compatibility, calls written as .retrieve_pdb_file(a, b, c) should still be interpreted as obsolete=b and pdir=c.
Add the new arguments to the end, i.e.
def retrieve_pdb_file(self, pdb_code, obsolete=False, pdir=None, file_format='mmCif', overwrite=False):| # This test downloads several large files from external database so it may run a while. | ||
|
|
||
| # Create temporary directory for files downloaded while testing. | ||
| basedir = os.path.join(os.getcwd(), "pdb-test") |
There was a problem hiding this comment.
Using tempfile.mkdtemp(...) here instead might be better - less chance of leaving temporary files in the source code tree?
Rewritten retrieve_pdb_file tests to be more explicit.
Codecov Report
@@ Coverage Diff @@
## master #943 +/- ##
==========================================
+ Coverage 80.12% 80.75% +0.63%
==========================================
Files 316 322 +6
Lines 48492 49415 +923
==========================================
+ Hits 38854 39906 +1052
+ Misses 9638 9509 -129
Continue to review full report at Codecov.
|
|
There's a typo in the last commit, |
| # choice of the "Biopython License Agreement" or the "BSD 3-Clause License". | ||
| # Please see the LICENSE file that should have been included as part of this | ||
| # package. | ||
| # It may be distributed freely with respect to the original authors. |
There was a problem hiding this comment.
We've not actually started dual licensing yet (see #898) as I'm still hoping to get a lawyer to look at the proposed wording for the header.
| pdb = line.strip() | ||
| assert len(pdb) == 4 | ||
| answer.append(pdb) | ||
| answer.append(pdb.decode()) |
There was a problem hiding this comment.
Does this work nicely on both Python 2 and 3? Would it be simpler to use from Bio._py3k import _as_string here?
There was a problem hiding this comment.
Yes, this work on both python versions.
| for pdb_code in pdb_codes: | ||
| self.retrieve_pdb_file(pdb_code, obsolete=obsolete, pdir=pdir, file_format=file_format, overwrite=overwrite) | ||
|
|
||
| def download_entire_pdb(self, file_format='mmCif', listfile=None): |
There was a problem hiding this comment.
Original API was:
def download_entire_pdb(self, listfile=None):To preserve the order, I suggest:
def download_entire_pdb(self, listfile=None, file_format='mmCif'):
The docstring should comment on the change in default file format, which I assume was PDB format?
| outfile.writelines((x + '\n' for x in entries)) | ||
|
|
||
| def download_obsolete_entries(self, listfile=None): | ||
| def download_obsolete_entries(self, file_format='mmCif', listfile=None): |
There was a problem hiding this comment.
As noted elsewhere, add the new argument to the end to preserve the old API.
| class TestPBDListGetList(unittest.TestCase): | ||
| """ | ||
| Test methods responsible for getting lists of entries. | ||
| """ |
There was a problem hiding this comment.
Can you write this as one line please, as per PEP257 https://www.python.org/dev/peps/pep-0257/#one-line-docstrings
i.e.
"""Test methods responsible for getting lists of entries."""
(As the same for the rest of the file)
| finally: | ||
| shutil.rmtree(temp_dir) | ||
|
|
||
| def test_retrieve_pdb_file_small_pdb(self): |
There was a problem hiding this comment.
These tests look very repetitive, how about something like this?:
def check(structure, filename, format):
with self.make_temp_directory(os.getcwd()) as tmp:
pdblist = PDBList(pdb=tmp, obsolete_pdb=os.path.join(tmp, "obsolete"))
path = os.path.join(tmp, structure[1:3], filename)
pdblist.retrieve_pdb_file(structure, file_format="pdb")
self.assertTrue(os.path.isfile(path))
os.remove(path)
def test_retrieve_pdb_file_small_pdb(self):
self.check("127d", os.path.join(tmp, structure[1:3], "pdb127d.ent", "pdb")
def test_retrieve_pdb_file_large_pdb(self):
self.check("3k1q", os.path.join(tmp, structure[1:3], "3k1q-pdb-bundle.tar", "bundle")
...…fferent directories. Due to the urlretrieve implementation in python 2.7, two consecutive calls for the same structure to be downloaded into different directories failed. This fix correct it.
The error occured while trying to download all entries or all obsolete entries in python 3.x
The file_format parameter was missing in some functions.
|
Are you happy to dual licence your contributions under both the Biopython License Agreement AND the BSD 3-Clause License? See #898. Also, are you happy to be thanked by name in the |
|
@etal, @JoaoRodrigues, @lennax, @abradle etc - I've not kept up to date the the PDB website changes, could you look over this work on downloading structure files from Biopython please? |
| """Test methods responsible for getting structures.""" | ||
|
|
||
| @contextlib.contextmanager | ||
| def make_temp_directory(self, dir): |
There was a problem hiding this comment.
Even within function scope, I prefer not to overwrite built-ins. directory is an alternative.
| file_format = "mmCif" | ||
| overwrite = False | ||
|
|
||
| if len(sys.argv) > 2: |
There was a problem hiding this comment.
Reworking this module could be a good time to switch to argparse; this would reduce the complexity of the control flow.
There was a problem hiding this comment.
Very true.
@dadoskawina don't worry about that for this pull request.
| "pdb" (format PDB), | ||
| "xml" (PMDML/XML format), | ||
|
|
||
| NOTE. The default download format has changed from PDB to PDBx/mmCif |
There was a problem hiding this comment.
I think it would be worth adding a temporary warning (similar to a deprecation warning) that files are being downloaded in mmCIF. Aside from the legacy grep/awk scripts, I use dozens of executables that only accept PDB format.
There was a problem hiding this comment.
Fair point, something like this where the function signature is changed to file_format=None to allow us to spot if the user passed in a value or not?:
if file_format is None:
file_format = "mmCif"
sys.stderr.write("WARNING: The default download format has changed from PDB to PDBx/mmCif\n")There was a problem hiding this comment.
Yes, that would be a great place to put it.
|
@dadoskawina are you happy to make the small improvements suggested by @lennax yesterday? |
|
Are you happy to dual licence your contributions under both the _Biopython License Agreement_ AND the _BSD 3-Clause License_? See #898.
Also, are you happy to be thanked by name in the ``NEWS`` and ``CONTRIB`` files?
Yes, of course.
|
1. change `dir` variable to `directory` 2. add "deprecation warning"
|
I've tightened up the PEP8/PEP257 style checking since you started work on this, which is why TravisCI failed. You should be able to reproduce this locally and remove the unwanted blank line 195 in |
|
CodeCov is warning about the test coverage, but other than that the automatic checks are happy. Thank you. @lennax does this look ready to merge now? Note I would do a squash-merge given the number of small commits and merges which complicate the history. |
|
@peterjc Looks good to me! |
See previous commit from pull request #943.
|
Thank you all. |
Squashed commit of pull request biopython#943 to update Bio.PDB.PDBList module: 1. Possibility to download structures in PDBx/mmCif, PDB, PDBML/XML and mmtf formats 2. Possibility to download large structures in PDB-like formatted bundles 3. New function: download specified set of structures 4. Code python 3.x comatible 5. Unit tests added. Note. The default download format changed from (deprecated) PDB to (recommended by RCSB) PDBx/mmCIf.
See previous commit from pull request biopython#943.
See pull request biopython#943, merged as a squashed commit 765bb51
|
@dadoskawina : I'm trying to dual license |
Changes to module:
mmtf formats (both from function and command line)
Note. The default download format changed from (deprecated) PDB to
(recommended by RCSB) PDBx/mmCIf.