Skip to content
Snippets Groups Projects
Commit d5ebf0f8 authored by Vermaat's avatar Vermaat
Browse files

Webservice for getting cache listing.

git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/branches/gbinfo-sync-branch@312 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1
parent 5dec8b43
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
"""
Synchronize the database cache with other Mutalyzer instances.
This program is intended to be run daily from cron. Example:
25 5 * * * mutalyzer-cache-sync
"""
from mutalyzer.config import Config
from mutalyzer.output import Output
def main():
"""
Synchronize the database cache with other Mutalyzer instances.
"""
config = Config()
output = Output(__file__, config.Output)
output.addMessage(__file__, -1, 'INFO',
'Starting cache sync')
# Todo: Actually do something.
output.addMessage(__file__, -1, 'INFO', 'Cache sync end')
if __name__ == '__main__':
main()
#!/usr/bin/env python
# Monkey patch suds, because for some weird reason the location
# http://www.w3.org/2001/xml.xsd is used for the XML namespace, but the W3C
# seems to respond too slow on that url. We use therefore use
# http://www.w3.org/2009/01/xml.xsd which fixes this.
from suds.xsd.sxbasic import Import
_import_open = Import.open
def _import_open_patched(self, *args, **kwargs):
if self.location == 'http://www.w3.org/2001/xml.xsd':
self.location = 'http://www.w3.org/2009/01/xml.xsd'
return _import_open(self, *args, **kwargs)
Import.open = _import_open_patched
import sys
from suds.client import Client
URL = 'http://localhost/mutalyzer/services/?wsdl'
c = Client(URL, cache=None)
o = c.service
print 'Getting cache...'
cache = o.getCache()
if cache:
for r in cache.CacheEntry:
print r.name
if 'gi' in r:
print r.gi
print r.hash
if 'chromosomeName' in r:
print r.chromosomeName
if 'chromosomeStart' in r:
print r.chromosomeStart
if 'chromosomeStop' in r:
print r.chromosomeStop
if 'chromosomeOrientation' in r:
print r.chromosomeOrientation
if 'url' in r:
print r.url
print
......@@ -1033,6 +1033,24 @@ class Cache(Db) :
return None
#getGBFromGI
def getGB(self):
"""
Get all accession numbers from the cache.
SQL tables from internalDb:
- GBInfo ; Information about cached and uploaded GenBank files.
@return: The accession number
@rtype: string
"""
statement = """
SELECT *
FROM GBInfo;
""", None
return self.query(statement)
#getGB
def getLoc(self, accNo) :
"""
Get the slicing information of an accession number, typically this
......@@ -1523,10 +1541,3 @@ class Batch(Db) :
return inputl, flags
#getFromQueue
#Batch
#
# Unit test.
#
if __name__ == "__main__" :
pass
#if
......@@ -28,6 +28,7 @@ class Config():
class Batch(): pass
class File(): pass
class GenRecord(): pass
class Sync(): pass
def __init__(self, filename=None):
"""
......
......@@ -214,4 +214,21 @@ class InfoOutput(ClassModel):
nomenclatureVersionParts = Array(String)
serverName = String
contactEmail = String
#MutalyzerOutput
#InfoOutput
class CacheEntry(ClassModel):
"""
Used in getCache SOAP method.
"""
__namespace__ = SOAP_NAMESPACE
name = Mandatory.String
gi = String
hash = Mandatory.String
chromosomeName = String
chromosomeStart = Integer
chromosomeStop = Integer
chromosomeOrientation = Integer
url = String
#CacheEntry
"""
Module for synchronizing the database with other Mutalyzer instances.
"""
class CacheSync(object):
"""
Todo.
"""
def __init__(self, config, database):
"""
Todo.
"""
self._config = config
self._database = database
def local_cache(self):
"""
Todo.
"""
return self._database.getGB()
......@@ -35,6 +35,7 @@ import mutalyzer
from mutalyzer.config import Config
from mutalyzer.output import Output
from mutalyzer.grammar import Grammar
from mutalyzer.sync import CacheSync
from mutalyzer import variantchecker
from mutalyzer import Db
from mutalyzer import Mapper
......@@ -880,6 +881,39 @@ class MutalyzerService(DefinitionBase):
output.addMessage(__file__, -1, 'INFO', 'Finished processing info')
return result
#info
@soap(_returns = Array(CacheEntry))
def getCache(self):
"""
Todo: documentation.
"""
output = Output(__file__, self._config.Output)
output.addMessage(__file__, -1, 'INFO',
'Received request getCache')
database = Db.Cache(self._config.Db)
sync = CacheSync(self._config.Sync, database)
cache = sync.local_cache()
def soap_cache_entry(entry):
e = CacheEntry()
e.name = entry[0]
e.gi = entry[1]
e.hash = entry[2]
e.chromosomeName = entry[3]
e.chromosomeStart = entry[4]
e.chromosomeStop = entry[5]
e.chromosomeOrientation = entry[6]
e.url = entry[7]
return e
output.addMessage(__file__, -1, 'INFO',
'Finished processing getCache')
return map(soap_cache_entry, cache)
#getCache
#MutalyzerService
......
......@@ -17,8 +17,11 @@ setup(
platforms=['any'],
packages=find_packages(exclude=['doc', 'extras', 'tests']),
include_package_data=True,
scripts=['bin/mutalyzer', 'bin/mutalyzer-batchd',
'bin/mutalyzer-ucsc-update', 'bin/mutalyzer-website.wsgi',
scripts=['bin/mutalyzer',
'bin/mutalyzer-cache-sync',
'bin/mutalyzer-batchd',
'bin/mutalyzer-ucsc-update',
'bin/mutalyzer-website.wsgi',
'bin/mutalyzer-webservice.wsgi'],
zip_safe=False
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment