source: orange-bioinformatics/server_update/updateSTRING.py @ 1753:d8bea5b19e25

Revision 1753:d8bea5b19e25, 1.6 KB checked in by markotoplak, 12 months ago (diff)

Update script for STRING: reads current version from the webpage and updates only if the database version on SF server differs.

Line 
1##!interval=7
2##!contact=ales.erjavec@fri.uni-lj.si
3
4from Orange.bio import obiPPI
5import urllib2, gzip
6
7from common import *
8import re
9
10
11def get_version():
12    from urllib2 import build_opener
13    html = build_opener().open('http://www.string-db.org/newstring_cgi/show_download_page.pl').read().decode()
14    ver = re.findall("protein\.links\.(v.*?)\.txt\.gz", html, re.DOTALL)[0]
15    return ver
16
17version = get_version()
18version_id = "#dbversion:%s" % version
19
20force = False # force update
21
22for cl,desc,sfn in [ (obiPPI.STRING, 
23                    "STRING Protein interactions (Creative Commons Attribution 3.0 License)", 
24                    obiPPI.STRING.FILENAME),
25                    (obiPPI.STRINGDetailed, 
26                    "STRING Protein interactions (Creative Commons Attribution-Noncommercial-Share Alike 3.0 License)", 
27                    obiPPI.STRINGDetailed.FILENAME_DETAILED) ]:
28
29    print cl
30    print "current info", sf_server.info("PPI", sfn)
31
32    if force or version_id not in sf_server.info("PPI", sfn)["tags"]:
33
34        filename = sf_local.localpath("PPI",  sfn)
35
36        if os.path.exists(filename):
37            os.remove(filename)
38
39        cl.download_data(version)
40
41        gzfile = gzip.GzipFile(filename + ".gz", "wb")
42        shutil.copyfileobj(open(filename, "rb"), gzfile)
43
44        sf_server.upload("PPI", sfn, filename + ".gz", 
45                       desc,
46                       tags=["protein interaction", "STRING", 
47                             "#compression:gz", "#version:%s" % cl.VERSION, version_id]
48                       )
49        sf_server.unprotect("PPI", sfn)
Note: See TracBrowser for help on using the repository browser.