From 2595121bf861c0d5ce9a54f9ac0bb20ebf212841 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Mon, 4 Apr 2011 07:13:56 +0000
Subject: [PATCH] Added SOAP example clients.

git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/branches/refactor-mutalyzer-branch@240 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1
---
 INSTALL                                   |   2 +
 README                                    |   5 ++
 config.example => examples/config         |   0
 examples/soap/getgeneandtranscript.py     |  19 ++++
 examples/soap/gettranscriptinfo.py        |  20 +++++
 examples/soap/gettranscriptsandinfo.py    |  55 ++++++++++++
 examples/soap/gettranscriptsbygenename.py |  21 +++++
 examples/soap/namecheck.py                |  65 ++++++++++++++
 examples/soap/positionconvert.py          |  26 ++++++
 examples/soap/slicechromosomebygene.py    |  22 +++++
 examples/soap/sp.py                       | 103 ++++++++++++++++++++++
 mutalyzer/mutator.py                      |   2 +
 12 files changed, 340 insertions(+)
 rename config.example => examples/config (100%)
 create mode 100755 examples/soap/getgeneandtranscript.py
 create mode 100755 examples/soap/gettranscriptinfo.py
 create mode 100755 examples/soap/gettranscriptsandinfo.py
 create mode 100755 examples/soap/gettranscriptsbygenename.py
 create mode 100755 examples/soap/namecheck.py
 create mode 100755 examples/soap/positionconvert.py
 create mode 100755 examples/soap/slicechromosomebygene.py
 create mode 100755 examples/soap/sp.py

diff --git a/INSTALL b/INSTALL
index da8be35f..0a7ef7c5 100644
--- a/INSTALL
+++ b/INSTALL
@@ -21,6 +21,8 @@ The web and SOAP interfaces depend on the following packages:
 - apache2               >= 2.2.11
 - libapache2-mod-wsgi   >= 2.8
 
+Copy ./examples/config to /etc/mutalyzer/config and edit to your needs.
+
 Add Apache configuration for Mutalyzer. For example, add the following to
 the file /etc/apache2/sites-available/mutalyzer (change the path
 /var/www/mutalyzer2 when appropriate) and run 'a2ensite mutalyzer'.
diff --git a/README b/README
index 88b4944c..587146ab 100644
--- a/README
+++ b/README
@@ -20,6 +20,7 @@ Coding style guide:
 
 Todo:
 
+* https://www.mutalyzer.nl/projects/mutalyzer2/changeset?old_path=%2Ftrunk&old=228&new_path=%2Fbranches%2Fexon-deletions-branch&new=228#file5
 * Accept a --config command line argument for a configuration file location.
 * Document integration, deployment, release management, etc.
 * Use standard logging module, with rotating functionality. Race conditions
@@ -36,6 +37,9 @@ Todo:
   Non-trivial thing here would be the requirement of database contents.
 * Make the batch checker a real system service, using /var/run and a Upstart
   init script.
+  http://wiki.debian.org/LSBInitScripts
+  http://celeryproject.org/docs/cookbook/daemonizing.html
+  http://www.debian-administration.org/articles/28
 * Migrate Javascript to JQuery.
 * I think in the long run, the Output object is not really the way to go. It
   obscures the control flow. The logging part should use the standard logging
@@ -44,6 +48,7 @@ Todo:
 * Migrate from TAL to a more mondern and maintained Python template library.
 * Develop a large test suite.
 * Create a web interface url to watch the progress of a batch job.
+* Use virtualenv?
 
 
 Notes for server setup (Europium VM copy):
diff --git a/config.example b/examples/config
similarity index 100%
rename from config.example
rename to examples/config
diff --git a/examples/soap/getgeneandtranscript.py b/examples/soap/getgeneandtranscript.py
new file mode 100755
index 00000000..2b255798
--- /dev/null
+++ b/examples/soap/getgeneandtranscript.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+import sys
+from suds.client import Client
+
+URL = 'http://www.mutalyzer.nl/2.0/services/?wsdl'
+
+if len(sys.argv) < 3:
+    print 'Please provide a genomic reference and a transcript reference'
+    sys.exit(1)
+
+c = Client(URL, cache=None)
+o = c.service
+
+print 'Getting gene and transcript ' + sys.argv[1] + ' / ' + sys.argv[2] + ' ...'
+
+r = o.getGeneAndTranscript(sys.argv[1], sys.argv[2])
+
+print r
diff --git a/examples/soap/gettranscriptinfo.py b/examples/soap/gettranscriptinfo.py
new file mode 100755
index 00000000..a5bf11e7
--- /dev/null
+++ b/examples/soap/gettranscriptinfo.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+import sys
+from suds.client import Client
+
+URL = 'http://www.mutalyzer.nl/2.0/services/?wsdl'
+
+if len(sys.argv) < 2:
+    print 'Please provide a transcript'
+    sys.exit(1)
+
+c = Client(URL, cache=None)
+o = c.service
+
+print 'Getting transcript info ' + sys.argv[1] + ' ...'
+
+r = o.transcriptInfo(LOVD_ver="123", build="hg19", accNo=sys.argv[1])
+print 'CDS stop: %s' % r.CDS_stop
+print 'Trans start: %s' % r.trans_start
+print 'Trans stop: %s' % r.trans_stop
diff --git a/examples/soap/gettranscriptsandinfo.py b/examples/soap/gettranscriptsandinfo.py
new file mode 100755
index 00000000..025635fe
--- /dev/null
+++ b/examples/soap/gettranscriptsandinfo.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+
+import sys
+from suds.client import Client
+
+URL = 'http://www.mutalyzer.nl/2.0/services/?wsdl'
+
+if len(sys.argv) < 2:
+    print 'Please provide a genomic reference'
+    sys.exit(1)
+
+c = Client(URL, cache=None)
+o = c.service
+
+# Example: AL449423.14
+print 'Getting transcript and info ' + sys.argv[1] + ' ...'
+
+gene = None
+
+if len(sys.argv) > 2:
+    print 'Restricting transcripts to ' + sys.argv[2]
+    gene = sys.argv[2]
+
+r = o.getTranscriptsAndInfo(sys.argv[1], gene)
+
+if r:
+    for t in r.TranscriptInfo:
+        print '%s' % t.name
+        print
+        print 'ID:                 %s' % t.id
+        print 'Product:            %s' % t.product
+        print 'Locus tag:          %s' % t.locusTag
+        print 'Link method:        %s' % t.linkMethod
+        print
+        print 'Translation start:  %s (c), %s (g)' % (t.cTransStart, t.gTransStart)
+        print 'Translation end:    %s (c), %s (g)' % (t.cTransEnd, t.gTransEnd)
+        print 'Sortable end:       %s' % t.sortableTransEnd
+        print
+        print 'Coding start:       %s (c), %s (g)' % (t.cCDSStart, t.gCDSStart)
+        print 'Coding stop:        %s (c), %s (g)' % (t.cCDSStop, t.gCDSStop)
+        print
+        if t.proteinTranscript:
+            print 'Protein name:       %s' % t.proteinTranscript.name
+            print 'Protein ID:         %s' % t.proteinTranscript.id
+            print 'Protein product:    %s' % t.proteinTranscript.product
+        else:
+            print 'No protein transcript'
+        print
+        if t.exons:
+            for e in t.exons.ExonInfo:
+                print 'Exon:               %s - %s (c), %s - %s (g)' % (e.cStart, e.cStop, e.gStart, e.gStop)
+        else:
+            print 'Huh, no exons?!'
+        print
+        print
diff --git a/examples/soap/gettranscriptsbygenename.py b/examples/soap/gettranscriptsbygenename.py
new file mode 100755
index 00000000..a670b2e5
--- /dev/null
+++ b/examples/soap/gettranscriptsbygenename.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+import sys
+from suds.client import Client
+
+URL = 'http://www.mutalyzer.nl/2.0/services/?wsdl'
+
+if len(sys.argv) < 2:
+    print 'Please provide a gene name'
+    sys.exit(1)
+
+c = Client(URL, cache=None)
+o = c.service
+
+print 'Getting transcripts ' + sys.argv[1] + ' ...'
+
+r = o.getTranscriptsByGeneName('hg19', sys.argv[1])
+
+if r:
+    for t in r.string:
+        print t
diff --git a/examples/soap/namecheck.py b/examples/soap/namecheck.py
new file mode 100755
index 00000000..5d51d00b
--- /dev/null
+++ b/examples/soap/namecheck.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+
+# Given a variant in HGVS notation, print raw variants with ASCII-art
+# visualisation and alternative descriptions. If VERBOSE is True, also print
+# original and mutated sequences.
+#
+# See http://www.mutalyzer.nl/2.0/webservices
+#
+# Usage:
+#   python namecheck.py 'AB026906.1:c.274delG'
+#
+# This code is in the public domain; it can be used for whatever purpose
+# with absolutely no restrictions.
+
+import sys
+from suds.client import Client  # https://fedorahosted.org/suds/
+
+VERBOSE = True
+
+URL = 'http://www.mutalyzer.nl/2.0/services/?wsdl'
+
+if len(sys.argv) < 2:
+    print 'Please provide a variant'
+    sys.exit(1)
+
+c = Client(URL)
+o = c.service
+
+print 'Running name checker for variant ' + sys.argv[1] + ' ...\n'
+
+r = o.runMutalyzer(sys.argv[1])
+
+if r.rawVariants:
+    for v in r.rawVariants.RawVariant:
+        print 'Raw variant: %s' % v.description
+        print '%s\n' % v.visualisation
+
+if VERBOSE:
+    print 'Original:\n%s\n' % r.original
+    print 'Mutated:\n%s\n' % r.mutated
+    print 'origMRNA:\n%s\n' % r.origMRNA
+    print 'mutatedMRNA:\n%s\n' % r.mutatedMRNA
+    print 'origCDS:\n%s\n' % r.origCDS
+    print 'newCDS:\n%s\n' % r.newCDS
+    print 'origProtein:\n%s\n' % r.origProtein
+    print 'newProtein:\n%s\n' % r.newProtein
+    print 'altProtein:\n%s\n' % r.altProtein
+
+print 'Errors: %s' % r.errors
+print 'Warnings: %s' % r.warnings
+print 'Summary: %s\n' % r.summary
+
+if r.messages:
+    for m in r.messages.SoapMessage:
+        print 'Error %s: %s\n' % (m.errorcode, m.message)
+
+print 'Chromosomal description: %s' % r.chromDescription
+print 'Genomic description: %s' % r.genomicDescription
+
+if r.transcriptDescriptions:
+    print 'Affected transcripts:'
+    print '\n'.join(r.transcriptDescriptions.string)
+if r.proteinDescriptions:
+    print 'Affected proteins:'
+    print '\n'.join(r.proteinDescriptions.string)
diff --git a/examples/soap/positionconvert.py b/examples/soap/positionconvert.py
new file mode 100755
index 00000000..92f77a98
--- /dev/null
+++ b/examples/soap/positionconvert.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+# Usage:
+#   ./positionconvert.py hg18 'NC_000011.9:g.111959695G>T'
+
+import sys
+from suds.client import Client  # https://fedorahosted.org/suds/
+
+URL = 'http://www.mutalyzer.nl/2.0/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/examples/soap/slicechromosomebygene.py b/examples/soap/slicechromosomebygene.py
new file mode 100755
index 00000000..7df13c1a
--- /dev/null
+++ b/examples/soap/slicechromosomebygene.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+import sys
+from suds.client import Client
+from suds import WebFault
+
+URL = 'http://www.mutalyzer.nl/2.0/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/examples/soap/sp.py b/examples/soap/sp.py
new file mode 100755
index 00000000..b44ba660
--- /dev/null
+++ b/examples/soap/sp.py
@@ -0,0 +1,103 @@
+#!/usr/bin/env python
+
+# Example SOAP client for the Mutalyzer webservice in Python using the
+# SOAPpy library.
+#
+# See http://www.mutalyzer.nl/2.0/webservices
+#
+# Usage:
+#   python sp.py
+#
+# This code is in the public domain; it can be used for whatever purpose
+# with absolutely no restrictions.
+
+import sys
+from SOAPpy import WSDL
+
+o = WSDL.Proxy("http://www.mutalyzer.nl/2.0/service.wsdl")
+
+# Get all transcripts that are hit when we look at position 159272155 on
+# chromosome 1.
+print "hg19", "chr1", 159272155
+r = o.getTranscripts(build="hg19", chrom="chr1", pos=159272155)
+if r:
+    # This seems to be a bug in SOAPpy. Arrays of length 1 are
+    # flattened, so we cannot iterate over them.
+    if not isinstance(r.string, list):
+        r.string = [r.string]
+    for i in r.string:
+        print i, o.getGeneName(build="hg19", accno=i)
+
+# Get all transcripts and genes that have (part of) a transcript in the range
+# 159272155-159372155 on chromosome 1.
+print "\n", "hg19", "chr1", 159272155, 159372155, 1
+r = o.getTranscriptsRange(build="hg19", chrom="chr1", pos1=159272155,
+                          pos2=159372155, method=1)
+if r:
+    # This seems to be a bug in SOAPpy. Arrays of length 1 are
+    # flattened, so we cannot iterate over them.
+    if not isinstance(r.string, list):
+        r.string = [r.string]
+    for i in r.string:
+        print i, o.getGeneName(build="hg19", accno=i)
+
+# Get all transcripts and genes that have the entire transcript in the range
+# 159272155-159372155 on chromosome 1.
+print "\n", "hg19", "chr1", 159272155, 159372155, 0
+r = o.getTranscriptsRange(build="hg19", chrom="chr1", pos1=159272155,
+                          pos2=159372155, method=0)
+if r:
+    # This seems to be a bug in SOAPpy. Arrays of length 1 are
+    # flattened, so we cannot iterate over them.
+    if not isinstance(r.string, list):
+        r.string = [r.string]
+    for i in r.string:
+        print i, o.getGeneName(build="hg19", accno=i)
+
+print "\n", "hg19", "NM_002001.2", "c.2del"
+r = o.mappingInfo(LOVD_ver="123", build="hg19", accNo="NM_002001.2",
+                  variant="c.1del")
+print r.mutationType
+print r.start_g
+print r.end_g
+
+print "\n", "hg19", "NM_002002.2"
+r = o.transcriptInfo(LOVD_ver="123", build="hg19", accNo="NM_002001.2")
+print r.CDS_stop
+print r.trans_start
+print r.trans_stop
+
+print "\n", "hg19", "NM_002001.2:c.1del"
+r = o.numberConversion(build="hg19", variant="NM_002001.2:c.1del")
+if r:
+    # This seems to be a bug in SOAPpy. Arrays of length 1 are
+    # flattened, so we cannot iterate over them.
+    if not isinstance(r.string, list):
+        r.string = [r.string]
+    for i in r.string:
+        print i
+
+print "\n", "hg19", "DMD"
+r = o.getTranscriptsByGeneName(build="hg19", name="DMD")
+if r:
+    # This seems to be a bug in SOAPpy. Arrays of length 1 are
+    # flattened, so we cannot iterate over them.
+    if not isinstance(r.string, list):
+        r.string = [r.string]
+    for i in r.string:
+        print i
+
+print "\n", "NM_002001.2:g.1del"
+r = o.runMutalyzer(variant="NM_002001.2:g.1del")
+print r.original
+print r.mutated
+print r.origMRNA
+print r.mutatedMRNA
+print r.origCDS
+print r.newCDS
+print r.origProtein
+print r.newProtein
+print r.altProtein
+print r.errors
+print r.warnings
+print r.summary
diff --git a/mutalyzer/mutator.py b/mutalyzer/mutator.py
index dced0090..36a543f8 100644
--- a/mutalyzer/mutator.py
+++ b/mutalyzer/mutator.py
@@ -365,6 +365,8 @@ class Mutator() :
         @type sites: list of int
 
         @todo: Resulting list of ignored sites should always be even.
+        @todo: Don't remove CDS start/stop, as happens e.g. with
+               AL449423.14(CDKN2A_v002):c.5_400del.
         """
         for site in sites:
             self.__removed_sites.add(site)
-- 
GitLab