Skip to content

Commit

Permalink
Merge pull request #110 from rigdenlab/update-stats
Browse files Browse the repository at this point in the history
Update stats
  • Loading branch information
hlasimpk committed Jul 22, 2019
2 parents 8919b6b + e1b3499 commit bd17e0c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Sequence Independent Molecular Replacement Based on Available Database
:target: https://landscape.io/github/rigdenlab/SIMBAD/master
:alt: Code Health

.. image:: https://img.shields.io/badge/solution%20count-6-blue.svg?style=flat
.. image:: https://img.shields.io/badge/solution%20count-8-blue.svg?style=flat
:alt: Solution count

.. image:: https://img.shields.io/badge/DOI-10.1107/S2059798318005752-blue.svg
Expand Down
58 changes: 35 additions & 23 deletions scripts/stats.py
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)
11 changes: 7 additions & 4 deletions simbad/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def find_simbad_dat_files(directory):
A list of paths to the files
"""
return [
os.path.join(root, filename) for root, _, files in os.walk(directory) for filename in files
if filename.endswith('.dat')
os.path.join(root, filename)
for root, _, files in os.walk(directory)
for filename in files
if filename.endswith(".dat")
]


Expand All @@ -48,7 +50,7 @@ def convert_dat_to_pdb(infile, outfile):
Path to the output pdb file
"""
with open(infile, 'rb') as f_in, open(outfile, 'w') as f_out:
with open(infile, "rb") as f_in, open(outfile, "w") as f_out:
f_out.write(_from_dat(f_in))


Expand Down Expand Up @@ -83,9 +85,10 @@ def is_valid_dat(infile):
with open(infile, "rb") as f_in:
try:
_from_dat(f_in)
is_valid = True
except:
is_valid = False
else:
is_valid = True
return is_valid


Expand Down

0 comments on commit bd17e0c

Please sign in to comment.