0
$\begingroup$

I want to use a script to evaluate a protein structure with QMEAN scoring.

I can't understand why the script suggested by SWISS-MODEL (access to QMEAN by json object) runs only if I put the commands on the shell. If I build a module, the result of the second request (request.get), return a QUEUEING status, not COMPLETE status.

Here is the code that I have been using:

import json
import requests

def qmean_page(structure):
""" return the Qmean4 score from SWISSMODEL QMEAN tool"""

    url = "https://swissmodel.expasy.org/qmean/submit/"

    # Request the resource
    response = requests.post(url=url, data={"email": "XXX@XXX.XX"} ,files={"structure": open(structure,'r'),},timeout=3,verify=True)

    json.dumps(response.json(), indent=4, sort_keys=True)
    download_json = str(response.json()['download_url'])

    return download_json

def qmean_score(download_url):
# Request the resource
    r = requests.get(download_url, verify=True)

    scores = json.dumps(r.json(), indent=4, sort_keys=True)
    print scores
    jdata = json.loads(scores)
    zscore = jdata['input_data']['models'][0]['global_scores']['qmean4']['zscore']
    return zscore


s = 'P02489.B99990005.pdb'
url_d = qmean_page(s)
print url_d
score  = qmean_score(url_d)
print score

CASE A: If I comment the last 5 line, I can import qmean.py (the function file) in python terminal.

>>> import qmean
>>> s = 'P02489.B99990005.pdb'
>>> url_d = qmean.qmean_page(s)
>>> print url_d
https://swissmodel.expasy.org/qmean/project/TgEjha.json
>>> score  = qmean.qmean_score(url_d)
{
"input_data": {
    "info": {
        "model_001": {
            "chain_mapping": {
                " ": "A"
            }
        }
    }, 
    "meta": {
        "created": "2018-01-18T10:04:29.978", 
        "email": "XXX@XXX.XX", 
        "project_name": "Project", 
        "seqres_uploaded": false
    }, 
    "method": "QMEANDisCo", 
    "models": [
        {
            "error_status": null, 
            "global_scores": {
                "acc_agreement": {
                    "norm": 0.5606936416184971, 
                    "zscore": -1.0459143647477258
                }, 
                "all_atom": {
                    "norm": -0.012626634534455788, 
                    "zscore": -2.1825427852787604
                }, 
                "cbeta": {
                    "norm": -0.004260555683274807, 
                    "zscore": -1.9157144117276892
                }, 
                "qmean4": {
                    "norm": 0.6275190794418422, 
                    "zscore": -3.5006904416158258
                }, 
                "qmean6": {
                    "norm": 0.6339071011931049, 
                    "zscore": -3.0507104571131918
                }, 
                "solvation": {
                    "norm": -0.609099435253941, 
                    "zscore": -1.2499924754236265
                }, 
                "ss_agreement": {
                    "norm": 0.6706229586994028, 
                    "zscore": 0.05371252044245716
                }, 
                "torsion": {
                    "norm": 0.0033300496230023145, 
                    "zscore": -2.7188811736675764
                }
            }, 
            "model_pdb": "https://swissmodel.expasy.org/qmean/project/TgEjha/model_001.pdb", 
            "modelid": "model_001", 
            "name": "P02489.B99990005.pdb", 
            "seqres": [
                {
                    "atomseq": "MDVTIQHPWFKRTLGPFYPSRLFDQFFGEGLFEYDLLPFLSSTISPYYRQSLFRTVLDSGISEVRSDRDKFVIFLDVKHFSPEDLTVKVQDDFVEIHGKHNERQDDHGYISREFHRRYRLPSNVDQSALSCSLSADGMLTFCGPKIQTGLDATHAERAIPVSREEKPTSAPSS", 
                    "chain_name": " ", 
                    "name": "seq_chain_0", 
                    "sequence": "MDVTIQHPWFKRTLGPFYPSRLFDQFFGEGLFEYDLLPFLSSTISPYYRQSLFRTVLDSGISEVRSDRDKFVIFLDVKHFSPEDLTVKVQDDFVEIHGKHNERQDDHGYISREFHRRYRLPSNVDQSALSCSLSADGMLTFCGPKIQTGLDATHAERAIPVSREEKPTSAPSS"
                }
            ]
        }
    ], 
    "options": {
        "qmeanbrane": false, 
        "qmeandisco": true
    }, 
    "project_type": "default", 
    "sequences": []
}, 
"status": "COMPLETED"
}
>>> 

CASE B: If I uncomment the last 5 lines and run 'python qmean.py', it doesn't work.

  andrea$ python qmean.py
  https://swissmodel.expasy.org/qmean/project/zrcLCK.json
  {
  "status": "QUEUEING"
  }
  Traceback (most recent call last):
  File "qmean.py", line 31, in <module>
  score  = qmean_score(url_d)
  File "qmean.py", line 24, in qmean_score
  zscore = jdata['input_data']['models'][0]['global_scores']['qmean4']['zscore']
  KeyError: 'input_data'

If I print 'r' variable of 'qmean_score' function, It returns:

  <Response [200]>
  {
  "status": "QUEUEING"
  }
$\endgroup$
  • 1
    $\begingroup$ You need to use if __main__: if you want to use that file as a module and in command line. But what is your question? You seem to have solved your problems. $\endgroup$ – llrs Jan 18 '18 at 9:23
  • $\begingroup$ No, it is not solved because I could have a result like case A also when I call my function as case B $\endgroup$ – Andrea Spinelli Jan 18 '18 at 13:34
  • $\begingroup$ I resolve the problem by using a while loop. $\endgroup$ – Andrea Spinelli Jan 22 '18 at 16:14
  • $\begingroup$ maybe you could post your answer and accept it, for people trying to figure out what was the issue, or delete your question if you think that it won't be useful for other people. $\endgroup$ – aechchiki Feb 19 '18 at 10:41
2
$\begingroup$

So this is connected to how QMEAN is implemented as a server. It also could be true to many bioinformatics resources so I think this is important.

Posting to QMEAN "submit" triggers the job that is processed on our HPC cluster. That takes time and in the meantime JSON response just tells you that the job is QUEUEING/RUNNING or when it is ready it tells you COMPLETED. The answer suggested by you is the correct assuming you wish to wait for the job completion (which might take quite a lot).

So just check in while loop when the status is COMPLETED and fetch the result eg.

import time
import json
import requests
def qmean_score(download_url):
    # Request the resource
    zscore = None
    while True:
        r = requests.get(download_url, verify=True)

        scores = json.dumps(r.json(), indent=4, sort_keys=True)
        jdata = json.loads(scores)
        if jdata["status"] == "COMPLETED":
            zscore = jdata['input_data']['models'][0]['global_scores']['qmean4']['zscore']
            break
        else:
            time.sleep(1000)
    return zscore
$\endgroup$
  • $\begingroup$ But this doesn’t differ between interactive and batch usage. OP just got lucky when running the code from an interactive session. $\endgroup$ – Konrad Rudolph Jun 28 '18 at 15:55
  • $\begingroup$ It does in a sense that one can submit many targets, save them in eg. file and after a while, one can return to them and retrieve all the date with JSON. It is just a convenience API for people that would like to do it in the command line and not doing this by hand. It is also used in CASP and CAMEO. $\endgroup$ – guma44 Jul 11 '18 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.