orange-bioinformatics / server_update / updateSTRING.py

##!interval=7
##!contact=ales.erjavec@fri.uni-lj.si

from Orange.bio import obiPPI
import urllib2, gzip

from common import *
import re


def get_version():
    from urllib2 import build_opener
    html = build_opener().open('http://www.string-db.org/newstring_cgi/show_download_page.pl').read().decode()
    ver = re.findall("protein\.links\.(v.*?)\.txt\.gz", html, re.DOTALL)[0]
    return ver

version = get_version()
version_id = "#dbversion:%s" % version

force = False # force update

for cl,desc,sfn in [ (obiPPI.STRING, 
                    "STRING Protein interactions (Creative Commons Attribution 3.0 License)", 
                    obiPPI.STRING.FILENAME),
                    (obiPPI.STRINGDetailed, 
                    "STRING Protein interactions (Creative Commons Attribution-Noncommercial-Share Alike 3.0 License)", 
                    obiPPI.STRINGDetailed.FILENAME_DETAILED) ]:

    print cl
    print "current info", sf_server.info("PPI", sfn)

    if force or version_id not in sf_server.info("PPI", sfn)["tags"]:

        filename = sf_local.localpath("PPI",  sfn)

        if os.path.exists(filename): #remvoe prebuilt sqlite database
            os.remove(filename)

        cl.download_data(version)

        gzfile = gzip.GzipFile(filename + ".gz", "wb") #gzip the database
        shutil.copyfileobj(open(filename, "rb"), gzfile)

        sf_server.upload("PPI", sfn, filename + ".gz", 
                       desc,
                       tags=["protein interaction", "STRING", 
                             "#compression:gz", "#version:%s" % cl.VERSION, version_id]
                       )
        sf_server.unprotect("PPI", sfn)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.