From c14640896bfc23daceca322e35bb2f6ec34a1fd0 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Wed, 7 Sep 2011 10:56:48 +0000
Subject: [PATCH] Some cleanup in SOAP tools.

git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/branches/refactor-mutalyzer-branch@351 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1
---
 bin/mutalyzer                                 |  1 -
 bin/mutalyzer-batchd                          |  1 -
 bin/mutalyzer-cache-sync                      |  1 -
 bin/mutalyzer-mapping-update                  |  1 -
 bin/mutalyzer-webservice.wsgi                 |  1 -
 bin/mutalyzer-website.wsgi                    |  1 -
 .../001-db-gbinfo-add-created.migration       |  1 -
 .../002-db-map-to-mapping.migration           |  1 -
 extras/soap-tools/getCache.py                 | 48 +++++++++++++++++++
 extras/soap-tools/getcache.py                 | 43 -----------------
 extras/soap-tools/getdbSNPDescriptions.py     | 42 ++++++++++++++++
 extras/soap-tools/getdbsnpdescription.py      | 24 ----------
 extras/soap-tools/numberConversion.py         | 45 +++++++++++++++++
 extras/soap-tools/positionconvert.py          | 28 -----------
 extras/soap-tools/sliceChromosomeByGene.py    | 44 +++++++++++++++++
 extras/soap-tools/slicechromosomebygene.py    | 24 ----------
 mutalyzer/__init__.py                         |  4 +-
 17 files changed, 182 insertions(+), 128 deletions(-)
 create mode 100755 extras/soap-tools/getCache.py
 delete mode 100755 extras/soap-tools/getcache.py
 create mode 100755 extras/soap-tools/getdbSNPDescriptions.py
 delete mode 100755 extras/soap-tools/getdbsnpdescription.py
 create mode 100755 extras/soap-tools/numberConversion.py
 delete mode 100755 extras/soap-tools/positionconvert.py
 create mode 100755 extras/soap-tools/sliceChromosomeByGene.py
 delete mode 100755 extras/soap-tools/slicechromosomebygene.py

diff --git a/bin/mutalyzer b/bin/mutalyzer
index 36af8af7..e61d6a6e 100755
--- a/bin/mutalyzer
+++ b/bin/mutalyzer
@@ -1,5 +1,4 @@
 #!/usr/bin/env python
-
 """
 Command-line interface to the nomenclature checker.
 
diff --git a/bin/mutalyzer-batchd b/bin/mutalyzer-batchd
index c6351f92..868eafa9 100755
--- a/bin/mutalyzer-batchd
+++ b/bin/mutalyzer-batchd
@@ -1,5 +1,4 @@
 #!/usr/bin/env python
-
 """
 Daemon for processing scheduled batch jobs.
 
diff --git a/bin/mutalyzer-cache-sync b/bin/mutalyzer-cache-sync
index bca5c1d7..405084ea 100755
--- a/bin/mutalyzer-cache-sync
+++ b/bin/mutalyzer-cache-sync
@@ -1,5 +1,4 @@
 #!/usr/bin/env python
-
 """
 Synchronize the database cache with other Mutalyzer instances.
 
diff --git a/bin/mutalyzer-mapping-update b/bin/mutalyzer-mapping-update
index e46a89c4..cbc88ef2 100755
--- a/bin/mutalyzer-mapping-update
+++ b/bin/mutalyzer-mapping-update
@@ -1,5 +1,4 @@
 #!/usr/bin/env python
-
 """
 Update the database with mapping information from the NCBI.
 
diff --git a/bin/mutalyzer-webservice.wsgi b/bin/mutalyzer-webservice.wsgi
index e9e1a822..bc624da3 100755
--- a/bin/mutalyzer-webservice.wsgi
+++ b/bin/mutalyzer-webservice.wsgi
@@ -1,5 +1,4 @@
 #!/usr/bin/env python
-
 """
 WSGI interface to the Mutalyzer SOAP webservice.
 
diff --git a/bin/mutalyzer-website.wsgi b/bin/mutalyzer-website.wsgi
index e6077d2a..be05dbb3 100755
--- a/bin/mutalyzer-website.wsgi
+++ b/bin/mutalyzer-website.wsgi
@@ -1,5 +1,4 @@
 #!/usr/bin/env python
-
 """
 WSGI interface to the Mutalyzer website.
 
diff --git a/extras/migrations/001-db-gbinfo-add-created.migration b/extras/migrations/001-db-gbinfo-add-created.migration
index 309422e5..26fd668a 100755
--- a/extras/migrations/001-db-gbinfo-add-created.migration
+++ b/extras/migrations/001-db-gbinfo-add-created.migration
@@ -1,5 +1,4 @@
 #!/usr/bin/env python
-
 """
 Add a column and index 'created' to the 'GBInfo' table.
 
diff --git a/extras/migrations/002-db-map-to-mapping.migration b/extras/migrations/002-db-map-to-mapping.migration
index 8ee6bfb2..be33512b 100755
--- a/extras/migrations/002-db-map-to-mapping.migration
+++ b/extras/migrations/002-db-map-to-mapping.migration
@@ -1,5 +1,4 @@
 #!/usr/bin/env python
-
 """
 Convert the old 'map' tables to the new 'Mapping' tables.
 
diff --git a/extras/soap-tools/getCache.py b/extras/soap-tools/getCache.py
new file mode 100755
index 00000000..cc8ecc18
--- /dev/null
+++ b/extras/soap-tools/getCache.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+"""
+Get cache entries from a Mutalyzer installation.
+
+Usage:
+  {command} days
+
+  days: Retrieve entries of at most this number of days old.
+
+The cache entries are retrieved from the Mutalyzer SOAP webservice and printed
+to standard output.
+"""
+
+
+from mutalyzer.util import monkey_patch_suds; monkey_patch_suds()
+
+import sys
+from datetime import datetime, timedelta
+from suds.client import Client
+
+from mutalyzer.util import format_usage
+
+
+WSDL_LOCATION = 'http://localhost/mutalyzer/services/?wsdl'
+
+
+def main(days):
+    """
+    Get cache entries and print them to standard output.
+    """
+    created_since = datetime.today() - timedelta(days=days)
+    service = Client(WSDL_LOCATION, cache=None).service
+    result = service.getCache(created_since)
+
+    if result:
+        for entry in result.CacheEntry:
+            print 'Entry %s created at %s' % (entry.name, entry.created)
+
+
+if __name__ == '__main__':
+    if len(sys.argv) != 2:
+        print format_usage()
+        sys.exit(1)
+    try:
+        main(int(sys.argv[1]))
+    except ValueError:
+        print 'First argument must be an integer'
+        sys.exit(1)
diff --git a/extras/soap-tools/getcache.py b/extras/soap-tools/getcache.py
deleted file mode 100755
index f40bc9ab..00000000
--- a/extras/soap-tools/getcache.py
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/env python
-
-from mutalyzer.util import monkey_patch_suds; monkey_patch_suds()
-
-import sys
-from datetime import datetime, timedelta
-from suds.client import Client
-
-URL = 'http://localhost/mutalyzer/services/?wsdl'
-
-c = Client(URL, cache=None)
-o = c.service
-
-days = 1
-if len(sys.argv) > 1:
-    days = int(sys.argv[1])
-
-created_since = datetime.today() - timedelta(days=days)
-
-print 'Getting cache...'
-
-cache = o.getCache(created_since)
-
-if cache:
-    for r in cache.CacheEntry:
-        print r.name
-        if 'gi' in r:
-            print 'GI: %s' % r.gi
-        print 'Hash: %s' % 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 'Created: %s' % r.created
-        if 'cached' in r:
-            print 'Cached as %s' % r.cached
-        print
diff --git a/extras/soap-tools/getdbSNPDescriptions.py b/extras/soap-tools/getdbSNPDescriptions.py
new file mode 100755
index 00000000..11cc54a8
--- /dev/null
+++ b/extras/soap-tools/getdbSNPDescriptions.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+"""
+Get HGVS descriptions for a dbSNP rs number.
+
+Usage:
+  {command} rs_number
+
+  rs_number: A valid dbSNP rs number, e.g. 'rs9919552'.
+
+The HGVS descriptions are retrieved from the Mutalyzer SOAP webservice and
+printed to standard output.
+"""
+
+
+from mutalyzer.util import monkey_patch_suds; monkey_patch_suds()
+
+import sys
+from suds.client import Client
+
+from mutalyzer.util import format_usage
+
+
+WSDL_LOCATION = 'http://localhost/mutalyzer/services/?wsdl'
+
+
+def main(rs_number):
+    """
+    Get HGVS descriptions and print them to standard output.
+    """
+    service = Client(WSDL_LOCATION, cache=None).service
+    result = service.getdbSNPDescriptions(rs_number)
+
+    if result:
+        for description in result.string:
+            print description
+
+
+if __name__ == '__main__':
+    if len(sys.argv) != 2:
+        print format_usage()
+        sys.exit(1)
+    main(sys.argv[1])
diff --git a/extras/soap-tools/getdbsnpdescription.py b/extras/soap-tools/getdbsnpdescription.py
deleted file mode 100755
index 81e999a5..00000000
--- a/extras/soap-tools/getdbsnpdescription.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-
-from mutalyzer.util import monkey_patch_suds; monkey_patch_suds()
-
-import sys
-from suds.client import Client
-
-URL = 'http://localhost/mutalyzer/services/?wsdl'
-
-if len(sys.argv) < 2:
-    print 'Please provide a dbSNP rs number'
-    sys.exit(1)
-
-c = Client(URL, cache=None)
-o = c.service
-
-# Example: rs9919552
-print 'Getting HGVS descriptions for ' + sys.argv[1] + ' ...'
-
-r = o.getdbSNPDescriptions(sys.argv[1])
-
-if r:
-    for description in r.string:
-        print description
diff --git a/extras/soap-tools/numberConversion.py b/extras/soap-tools/numberConversion.py
new file mode 100755
index 00000000..f72fb532
--- /dev/null
+++ b/extras/soap-tools/numberConversion.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+"""
+Convert a variant description from c. to g. notation or vice versa.
+
+Usage:
+  {command} build description
+
+  build: Human genome reference build to use, i.e. 'hg18' or 'hg19'.
+  description: Variant description to convert.
+
+The converted HGVS description(s) is (are) retrieved from the Mutalyzer SOAP
+webservice and printed to standard output.
+"""
+
+
+from mutalyzer.util import monkey_patch_suds; monkey_patch_suds()
+
+import sys
+from suds.client import Client
+
+from mutalyzer.util import format_usage
+
+
+WSDL_LOCATION = 'http://localhost/mutalyzer/services/?wsdl'
+
+
+def main(build, description):
+    """
+    Convert variant description from c. to g. notation or vice versa.
+    """
+    service = Client(WSDL_LOCATION, cache=None).service
+    result = service.numberConversion(build, description)
+
+    if result:
+        for description in result.string:
+            print description
+    else:
+        print 'No descriptions returned.'
+
+
+if __name__ == '__main__':
+    if len(sys.argv) != 3:
+        print format_usage()
+        sys.exit(1)
+    main(*sys.argv[1:])
diff --git a/extras/soap-tools/positionconvert.py b/extras/soap-tools/positionconvert.py
deleted file mode 100755
index 2bbea9e9..00000000
--- a/extras/soap-tools/positionconvert.py
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/usr/bin/env python
-
-# Usage:
-#   ./positionconvert.py hg18 'NC_000011.9:g.111959695G>T'
-
-from mutalyzer.util import monkey_patch_suds; monkey_patch_suds()
-
-import sys
-from suds.client import Client  # https://fedorahosted.org/suds/
-
-URL = 'http://localhost/mutalyzer/services/?wsdl'
-
-if len(sys.argv) < 3:
-    print 'Please provide a human genome build and a variant'
-    sys.exit(1)
-
-c = Client(URL)
-o = c.service
-
-print 'Running position converter for variant ' + sys.argv[1] + ' ...\n'
-
-r = o.numberConversion(sys.argv[1], sys.argv[2])
-
-if r:
-    for v in r.string:
-        print v
-else:
-    print 'No variants returned.'
diff --git a/extras/soap-tools/sliceChromosomeByGene.py b/extras/soap-tools/sliceChromosomeByGene.py
new file mode 100755
index 00000000..698a927c
--- /dev/null
+++ b/extras/soap-tools/sliceChromosomeByGene.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+"""
+Create a slice of a chromosome by gene.
+
+Usage:
+  {command} gene
+
+  gene: Gene symbol of the gene to slice.
+
+A slice containing the gene with 5000 upstream bases and 2000 downstream bases
+is created with the Mutalyzer SOAP webservice. The resulting UD number is
+printed to standard output.
+"""
+
+
+from mutalyzer.util import monkey_patch_suds; monkey_patch_suds()
+
+import sys
+from suds.client import Client
+from suds import WebFault
+
+from mutalyzer.util import format_usage
+
+
+WSDL_LOCATION = 'http://localhost/mutalyzer/services/?wsdl'
+
+
+def main(gene):
+    """
+    Slice chromosome by gene and print UD number to standard output.
+    """
+    service = Client(WSDL_LOCATION, cache=None).service
+
+    try:
+        print service.sliceChromosomeByGene(gene, 'Human', 5000, 2000)
+    except WebFault as message:
+        print message
+
+
+if __name__ == '__main__':
+    if len(sys.argv) != 2:
+        print format_usage()
+        sys.exit(1)
+    main(sys.argv[1])
diff --git a/extras/soap-tools/slicechromosomebygene.py b/extras/soap-tools/slicechromosomebygene.py
deleted file mode 100755
index dacbb134..00000000
--- a/extras/soap-tools/slicechromosomebygene.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-
-from mutalyzer.util import monkey_patch_suds; monkey_patch_suds()
-
-import sys
-from suds.client import Client
-from suds import WebFault
-
-URL = 'http://localhost/mutalyzer/services/?wsdl'
-
-if len(sys.argv) < 2:
-    print 'Please provide a gene symbol'
-    sys.exit(1)
-
-c = Client(URL, cache=None)
-o = c.service
-
-print 'Slicing chromosome for gene ' + sys.argv[1] + ' (Human, 5000 upstream, 2000 downstream) ...'
-
-try:
-    r = o.sliceChromosomeByGene(sys.argv[1], 'Human', 5000, 2000)
-    print r
-except WebFault as message:
-    print message
diff --git a/mutalyzer/__init__.py b/mutalyzer/__init__.py
index 8728f32f..07ce5698 100644
--- a/mutalyzer/__init__.py
+++ b/mutalyzer/__init__.py
@@ -1,4 +1,6 @@
-"""HGVS variant nomenclature checker."""
+"""
+HGVS variant nomenclature checker.
+"""
 
 
 import os
-- 
GitLab