# Path: inmembrane/helpers.py
# def log_stderr(s, width=76, comment=True):
#     """
#     Wrapper for all stderr out. Allows future customization.
#     """
#     if LOG_SILENT:
#         return
#     if s and s[-1] != "\n":
#         s += "\n"
#     if not s.startswith("#"):
#         s = "# " + s
#     sys.stderr.write(s)
# 
# def print_proteins(proteins):
#     """
#     Prints out the proteins dictionary in a formatted
#     manner that is also Python-eval compatible.
#     """
#     print "{"
#     for seqid in proteins:
#         print "  '%s': {" % seqid
#         for key, value in proteins[seqid].items():
#             print "    '%s': %s, " % (key, repr(value))
#         print "  },"
#     print "}"
#     # Standard Library alternative
#     # import pprint
#     # pp = pprint.PrettyPrinter(indent=4)
#     # print pp.pformat(proteins)


import sys, os, time, json, re
import logging
from suds.client import Client
from suds.bindings import binding
from inmembrane.helpers import log_stderr, print_proteins
        sys.stderr.write("\n")

        # pollQueue
        job = client.factory.create('pollQueue.job')
        job.jobid = response.jobid
        response = client.service.pollQueue(job)
        retries = 0
        sys.stderr.write("# Waiting for TMHMM(web) results ")
        while response.status != "FINISHED" and retries < 100:
            response = client.service.pollQueue(job)
            time.sleep(10 + (retries * 2))
            retries += 1
            sys.stderr.write(".")

            # if something goes wrong, note it and skip TMHMM
            # by returning
            if response.status == "REJECTED" or \
                    response.status == "UNKNOWN JOBID" or \
                    response.status == "QUEUE DOWN" or \
                    response.status == "FAILED":
                log_stderr("TMHMM(web) failed: '%s'" % (response.status))
                return proteins

        sys.stderr.write(" done !\n")

        # fetchResults
        done_job = client.factory.create('fetchResult.job')
        done_job.jobid = response.jobid
        result = client.service.fetchResult(done_job)


# Path: inmembrane/helpers.py
# def log_stderr(s, width=76, comment=True):
#     """
#     Wrapper for all stderr out. Allows future customization.
#     """
#     if LOG_SILENT:
#         return
#     if s and s[-1] != "\n":
#         s += "\n"
#     if not s.startswith("#"):
#         s = "# " + s
#     sys.stderr.write(s)
# 
# def print_proteins(proteins):
#     """
#     Prints out the proteins dictionary in a formatted
#     manner that is also Python-eval compatible.
#     """
#     print "{"
#     for seqid in proteins:
#         print "  '%s': {" % seqid
#         for key, value in proteins[seqid].items():
#             print "    '%s': %s, " % (key, repr(value))
#         print "  },"
#     print "}"
#     # Standard Library alternative
#     # import pprint
#     # pp = pprint.PrettyPrinter(indent=4)
#     # print pp.pformat(proteins)


# Path: inmembrane/plugins/tmhmm_web.py
import sys, os, time, json, re
import logging
from suds.client import Client
from suds.bindings import binding
from inmembrane.helpers import log_stderr, print_proteins

        sys.stderr.write("\n")

        # pollQueue
        job = client.factory.create('pollQueue.job')
        job.jobid = response.jobid
        response = client.service.pollQueue(job)
        retries = 0
        sys.stderr.write("# Waiting for TMHMM(web) results ")
        while response.status != "FINISHED" and retries < 100:
            response = client.service.pollQueue(job)
            time.sleep(10 + (retries * 2))
            retries += 1
            sys.stderr.write(".")

            # if something goes wrong, note it and skip TMHMM
            # by returning
            if response.status == "REJECTED" or \
                    response.status == "UNKNOWN JOBID" or \
                    response.status == "QUEUE DOWN" or \
                    response.status == "FAILED":
                log_stderr("TMHMM(web) failed: '%s'" % (response.status))
                return proteins

        sys.stderr.write(" done !\n")

        # fetchResults
        done_job = client.factory.create('fetchResult.job')
        done_job.jobid = response.jobid
        result = client.service.fetchResult(done_job)


        if __DEBUG__: log_stderr(str(result))