-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from rigdenlab/update-stats
Update stats
- Loading branch information
Showing
3 changed files
with
43 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,51 @@ | ||
#!/usr/bin/env ccp4-python | ||
#!/usr/bin/env python | ||
|
||
"""Script to compute some SIMBAD statistics --- work in progress""" | ||
|
||
from __future__ import print_function | ||
|
||
__author__ = "Felix Simkovic" | ||
__date__ = "30 Mar 2018" | ||
__version__ = "1.0" | ||
__date__ = "21 Jul 2019" | ||
__version__ = "2.0" | ||
|
||
import logging | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
import os | ||
import re | ||
import requests | ||
import urllib2 | ||
|
||
url = 'http://www.rcsb.org/pdb/rest/search' | ||
data = """ | ||
LOG = logging.getLogger(__name__) | ||
BASE_URL = "http://www.rcsb.org/pdb/rest/" | ||
PAYLOAD = """ | ||
<orgPdbQuery> | ||
<queryType>org.pdb.query.simple.AdvancedKeywordQuery</queryType> | ||
<description>Text Search for: simbad</description> | ||
<keywords>simbad</keywords> | ||
</orgPdbQuery> | ||
""" | ||
header = {'Content-Type': 'application/x-www-form-urlencoded'} | ||
|
||
req = urllib2.Request(url, data, header) | ||
response = urllib2.urlopen(req) | ||
|
||
if response.getcode() == 200: | ||
entries = response.readlines() | ||
count = len(entries) | ||
print("SIMBAD solved {} structures".format(count)) | ||
else: | ||
raise Exception("Could not retrieve data") | ||
readme = os.path.join(os.path.dirname(__file__), "..", "README.rst") | ||
with open(readme, "r") as f_in: | ||
data = f_in.read() | ||
data = re.sub(r"solution\%20count-\d+-blue", "solution%20count-{}-blue".format(count), data) | ||
with open(readme, "w") as f_out: | ||
f_out.write(data) | ||
|
||
|
||
def update_readme(n_sols): | ||
readme = os.path.join(os.path.dirname(__file__), "..", "README.rst") | ||
with open(readme, "r") as fh: | ||
text = fh.read() | ||
text = re.sub( | ||
r"solution\%20count-\d+-blue", "solution%20count-{}-blue".format(n_sols), text | ||
) | ||
with open(readme, "w") as fh: | ||
fh.write(text) | ||
|
||
|
||
if __name__ == "__main__": | ||
header = {"Content-Type": "application/x-www-form-urlencoded"} | ||
url = requests.compat.urljoin(BASE_URL, "search") | ||
|
||
response = requests.post(url, data=PAYLOAD, headers=header) | ||
response.raise_for_status() | ||
|
||
entries = response.content.splitlines() | ||
|
||
n_solutions = len(entries) | ||
LOG.info("Found %s solutions", n_solutions) | ||
update_readme(n_solutions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters