Example #1
0
    def weblogo(self, fname, format="PNG", **kwds):
        """
        uses the Berkeley weblogo service to download and save a weblogo of itself
        
        requires an internet connection.
        The parameters from **kwds are passed directly to the weblogo server.
        """
        from Bio._py3k import urlopen, urlencode, Request

        al = self._to_fasta()
        url = 'http://weblogo.berkeley.edu/logo.cgi'
        values = {
            'sequence': al,
            'format': format,
            'logowidth': '18',
            'logoheight': '5',
            'logounits': 'cm',
            'kind': 'AUTO',
            'firstnum': "1",
            'command': 'Create Logo',
            'smallsamplecorrection': "on",
            'symbolsperline': 32,
            'res': '96',
            'res_units': 'ppi',
            'antialias': 'on',
            'title': '',
            'barbits': '',
            'xaxis': 'on',
            'xaxis_label': '',
            'yaxis': 'on',
            'yaxis_label': '',
            'showends': 'on',
            'shrink': '0.5',
            'fineprint': 'on',
            'ticbits': '1',
            'colorscheme': 'DEFAULT',
            'color1': 'green',
            'color2': 'blue',
            'color3': 'red',
            'color4': 'black',
            'color5': 'purple',
            'color6': 'orange',
            'color1': 'black',
        }
        for k, v in kwds.items():
            values[k] = str(v)

        data = urlencode(values)
        req = Request(url, data)
        response = urlopen(req)
        f = open(fname, "w")
        im = response.read()

        f.write(im)
        f.close()
Example #2
0
def _open(cgi, params={}, get=1):
    """_open(cgi, params={}, get=1) -> UndoHandle

    Open a handle to SCOP.  cgi is the URL for the cgi script to access.
    params is a dictionary with the options to pass to it.  get is a boolean
    that describes whether a GET should be used.  Does some
    simple error checking, and will raise an IOError if it encounters one.

    """
    from Bio._py3k import urlopen, urlencode

    # Open a handle to SCOP.
    options = urlencode(params)
    if get:  # do a GET
        if options:
            cgi += "?" + options
        handle = urlopen(cgi)
    else:    # do a POST
        handle = urlopen(cgi, data=options)
    return handle
Example #3
0
def _open(cgi, params={}, get=1):
    """_open(cgi, params={}, get=1) -> UndoHandle

    Open a handle to SCOP.  cgi is the URL for the cgi script to access.
    params is a dictionary with the options to pass to it.  get is a boolean
    that describes whether a GET should be used.  Does some
    simple error checking, and will raise an IOError if it encounters one.

    """
    from Bio._py3k import urlopen, urlencode

    # Open a handle to SCOP.
    options = urlencode(params)
    if get:  # do a GET
        if options:
            cgi += "?" + options
        handle = urlopen(cgi)
    else:    # do a POST
        handle = urlopen(cgi, data=options)
    return handle
Example #4
0
    def weblogo(self,fname,format="PNG",**kwds):
        """
        uses the Berkeley weblogo service to download and save a weblogo of itself
        
        requires an internet connection.
        The parameters from **kwds are passed directly to the weblogo server.
        """
        from Bio._py3k import urlopen, urlencode, Request

        al= self._to_fasta()
        url = 'http://weblogo.berkeley.edu/logo.cgi'
        values = {'sequence': al,
                  'format': format,
                  'logowidth': '18',
                  'logoheight': '5',
                  'logounits': 'cm',
                  'kind': 'AUTO',
                  'firstnum': "1",
                  'command': 'Create Logo',
                  'smallsamplecorrection': "on",
                  'symbolsperline': 32,
                  'res': '96',
                  'res_units': 'ppi',
                  'antialias': 'on',
                  'title': '',
                  'barbits': '',
                  'xaxis': 'on',
                  'xaxis_label': '',
                  'yaxis': 'on',
                  'yaxis_label': '',
                  'showends': 'on',
                  'shrink': '0.5',
                  'fineprint': 'on',
                  'ticbits': '1',
                  'colorscheme': 'DEFAULT',
                  'color1': 'green',
                  'color2': 'blue',
                  'color3': 'red',
                  'color4': 'black',
                  'color5': 'purple',
                  'color6': 'orange',
                  'color1': 'black',
                  }
        for k, v in kwds.items():
            values[k]=str(v)
            
        data = urlencode(values)
        req = Request(url, data)
        response = urlopen(req)
        f=open(fname,"w")
        im=response.read()
        
        f.write(im)
        f.close()
Example #5
0
def _open(cgi, params=None, get=1):
    """Open a handle to SCOP and return it (PRIVATE).

    Open a handle to SCOP.  cgi is the URL for the cgi script to access.
    params is a dictionary with the options to pass to it.  get is a boolean
    that describes whether a GET should be used.

    """
    from Bio._py3k import urlopen, urlencode

    # Open a handle to SCOP.
    if params is None:
        params = {}
    options = urlencode(params)
    if get:  # do a GET
        if options:
            cgi += "?" + options
        handle = urlopen(cgi)
    else:  # do a POST
        handle = urlopen(cgi, data=options)
    return handle
Example #6
0
    def setUp(self):
        # We are using the files of the Drosophila Gateway Vector Collection
        # (<https://emb.carnegiescience.edu/drosophila-gateway-vector-collection>)
        # as sample Gck files. We cannot redistribute those files along with
        # Biopython, so we need to download them now for the tests to run.
        if not os.path.exists("Gck/DGVC_GCK.zip"):
            try:
                requires_internet.check()
            except MissingExternalDependencyError:
                self.skipTest("Sample files missing and no Internet access")
                return

            try:
                src = urlopen("https://emb.carnegiescience.edu/sites/default/files/DGVC_GCK.zip")
                with open("Gck/DGVC_GCK.zip", "wb") as dst:
                    shutil.copyfileobj(src, dst)
                src.close()
            except HTTPError:
                self.skipTest("Cannot download the sample files")
                return

        self.zipdata = ZipFile("Gck/DGVC_GCK.zip")
Example #7
0
    def weblogo(self, fname, format="PNG", version="2.8.2", **kwds):
        """Download and save a weblogo using the Berkeley weblogo service.

        Requires an internet connection.

        The parameters from ``**kwds`` are passed directly to the weblogo server.

        Currently, this method uses WebLogo version 3.3.
        These are the arguments and their default values passed to
        WebLogo 3.3; see their website at http://weblogo.threeplusone.com
        for more information::

            'stack_width' : 'medium',
            'stacks_per_line' : '40',
            'alphabet' : 'alphabet_dna',
            'ignore_lower_case' : True,
            'unit_name' : "bits",
            'first_index' : '1',
            'logo_start' : '1',
            'logo_end': str(self.length),
            'composition' : "comp_auto",
            'percentCG' : '',
            'scale_width' : True,
            'show_errorbars' : True,
            'logo_title' : '',
            'logo_label' : '',
            'show_xaxis': True,
            'xaxis_label': '',
            'show_yaxis': True,
            'yaxis_label': '',
            'yaxis_scale': 'auto',
            'yaxis_tic_interval' : '1.0',
            'show_ends' : True,
            'show_fineprint' : True,
            'color_scheme': 'color_auto',
            'symbols0': '',
            'symbols1': '',
            'symbols2': '',
            'symbols3': '',
            'symbols4': '',
            'color0': '',
            'color1': '',
            'color2': '',
            'color3': '',
            'color4': '',

        """
        from Bio._py3k import urlopen, urlencode, Request
        from Bio import Alphabet

        if isinstance(self.alphabet, Alphabet.ProteinAlphabet):
            alpha = "alphabet_protein"
        elif isinstance(self.alphabet, Alphabet.RNAAlphabet):
            alpha = "alphabet_rna"
        elif isinstance(self.alphabet, Alphabet.DNAAlphabet):
            alpha = "alphabet_dna"
        else:
            alpha = "auto"

        frequencies = self.format('transfac')
        url = 'http://weblogo.threeplusone.com/create.cgi'
        values = {
            'sequences': frequencies,
            'format': format.lower(),
            'stack_width': 'medium',
            'stacks_per_line': '40',
            'alphabet': alpha,
            'ignore_lower_case': True,
            'unit_name': "bits",
            'first_index': '1',
            'logo_start': '1',
            'logo_end': str(self.length),
            'composition': "comp_auto",
            'percentCG': '',
            'scale_width': True,
            'show_errorbars': True,
            'logo_title': '',
            'logo_label': '',
            'show_xaxis': True,
            'xaxis_label': '',
            'show_yaxis': True,
            'yaxis_label': '',
            'yaxis_scale': 'auto',
            'yaxis_tic_interval': '1.0',
            'show_ends': True,
            'show_fineprint': True,
            'color_scheme': 'color_auto',
            'symbols0': '',
            'symbols1': '',
            'symbols2': '',
            'symbols3': '',
            'symbols4': '',
            'color0': '',
            'color1': '',
            'color2': '',
            'color3': '',
            'color4': '',
        }

        values.update(
            dict((k, "" if v is False else str(v)) for k, v in kwds.items()))
        data = urlencode(values).encode("utf-8")
        req = Request(url, data)
        response = urlopen(req)
        with open(fname, "wb") as f:
            im = response.read()
            f.write(im)
Example #8
0
    def weblogo(self,fname,format="PNG",version="2.8.2", **kwds):
        """
        uses the Berkeley weblogo service to download and save a weblogo of
        itself

        requires an internet connection.
        The parameters from **kwds are passed directly to the weblogo server.

        Currently, this method uses WebLogo version 3.3.
        These are the arguments and their default values passed to
        WebLogo 3.3; see their website at http://weblogo.threeplusone.com
        for more information:

            'stack_width' : 'medium',
            'stack_per_line' : '40',
            'alphabet' : 'alphabet_dna',
            'ignore_lower_case' : True,
            'unit_name' : "bits",
            'first_index' : '1',
            'logo_start' : '1',
            'logo_end': str(self.length),
            'composition' : "comp_auto",
            'percentCG' : '',
            'scale_width' : True,
            'show_errorbars' : True,
            'logo_title' : '',
            'logo_label' : '',
            'show_xaxis': True,
            'xaxis_label': '',
            'show_yaxis': True,
            'yaxis_label': '',
            'yaxis_scale': 'auto',
            'yaxis_tic_interval' : '1.0',
            'show_ends' : True,
            'show_fineprint' : True,
            'color_scheme': 'color_auto',
            'symbols0': '',
            'symbols1': '',
            'symbols2': '',
            'symbols3': '',
            'symbols4': '',
            'color0': '',
            'color1': '',
            'color2': '',
            'color3': '',
            'color4': '',

        """
        from Bio._py3k import urlopen, urlencode, Request

        frequencies = self.format('transfac')
        url = 'http://weblogo.threeplusone.com/create.cgi'
        values = {'sequences': frequencies,
                  'format': format.lower(),
                  'stack_width': 'medium',
                  'stack_per_line': '40',
                  'alphabet': 'alphabet_dna',
                  'ignore_lower_case': True,
                  'unit_name': "bits",
                  'first_index': '1',
                  'logo_start': '1',
                  'logo_end': str(self.length),
                  'composition': "comp_auto",
                  'percentCG': '',
                  'scale_width': True,
                  'show_errorbars': True,
                  'logo_title': '',
                  'logo_label': '',
                  'show_xaxis': True,
                  'xaxis_label': '',
                  'show_yaxis': True,
                  'yaxis_label': '',
                  'yaxis_scale': 'auto',
                  'yaxis_tic_interval': '1.0',
                  'show_ends': True,
                  'show_fineprint': True,
                  'color_scheme': 'color_auto',
                  'symbols0': '',
                  'symbols1': '',
                  'symbols2': '',
                  'symbols3': '',
                  'symbols4': '',
                  'color0': '',
                  'color1': '',
                  'color2': '',
                  'color3': '',
                  'color4': '',
                  }
        for k, v in kwds.items():
            if isinstance(values[k], bool):
                if not v:
                    v = ""
            values[k]=str(v)

        data = urlencode(values)
        req = Request(url, data)
        response = urlopen(req)
        with open(fname,"w") as f:
            im = response.read()
            f.write(im)
Example #9
0
    def weblogo(self, fname, format="PNG", version="2.8.2", **kwds):
        """Download and save a weblogo using the Berkeley weblogo service.

        Requires an internet connection.

        The parameters from ``**kwds`` are passed directly to the weblogo server.

        Currently, this method uses WebLogo version 3.3.
        These are the arguments and their default values passed to
        WebLogo 3.3; see their website at http://weblogo.threeplusone.com
        for more information::

            'stack_width' : 'medium',
            'stacks_per_line' : '40',
            'alphabet' : 'alphabet_dna',
            'ignore_lower_case' : True,
            'unit_name' : "bits",
            'first_index' : '1',
            'logo_start' : '1',
            'logo_end': str(self.length),
            'composition' : "comp_auto",
            'percentCG' : '',
            'scale_width' : True,
            'show_errorbars' : True,
            'logo_title' : '',
            'logo_label' : '',
            'show_xaxis': True,
            'xaxis_label': '',
            'show_yaxis': True,
            'yaxis_label': '',
            'yaxis_scale': 'auto',
            'yaxis_tic_interval' : '1.0',
            'show_ends' : True,
            'show_fineprint' : True,
            'color_scheme': 'color_auto',
            'symbols0': '',
            'symbols1': '',
            'symbols2': '',
            'symbols3': '',
            'symbols4': '',
            'color0': '',
            'color1': '',
            'color2': '',
            'color3': '',
            'color4': '',

        """
        from Bio._py3k import urlopen, urlencode, Request

        if self.alphabet == "ACDEFGHIKLMNPQRSTVWY":
            alpha = "alphabet_protein"
        elif self.alphabet == "ACGU":
            alpha = "alphabet_rna"
        elif self.alphabet == "ACGT":
            alpha = "alphabet_dna"
        else:
            alpha = "auto"

        frequencies = self.format("transfac")
        url = "http://weblogo.threeplusone.com/create.cgi"
        values = {
            "sequences": frequencies,
            "format": format.lower(),
            "stack_width": "medium",
            "stacks_per_line": "40",
            "alphabet": alpha,
            "ignore_lower_case": True,
            "unit_name": "bits",
            "first_index": "1",
            "logo_start": "1",
            "logo_end": str(self.length),
            "composition": "comp_auto",
            "percentCG": "",
            "scale_width": True,
            "show_errorbars": True,
            "logo_title": "",
            "logo_label": "",
            "show_xaxis": True,
            "xaxis_label": "",
            "show_yaxis": True,
            "yaxis_label": "",
            "yaxis_scale": "auto",
            "yaxis_tic_interval": "1.0",
            "show_ends": True,
            "show_fineprint": True,
            "color_scheme": "color_auto",
            "symbols0": "",
            "symbols1": "",
            "symbols2": "",
            "symbols3": "",
            "symbols4": "",
            "color0": "",
            "color1": "",
            "color2": "",
            "color3": "",
            "color4": "",
        }

        values.update(
            {k: "" if v is False else str(v)
             for k, v in kwds.items()})
        data = urlencode(values).encode("utf-8")
        req = Request(url, data)
        response = urlopen(req)
        with open(fname, "wb") as f:
            im = response.read()
            f.write(im)
Example #10
0
import gzip
import inspect
import os
import warnings

from Bio._py3k import urlopen

url = "ftp://ftp.wwpdb.org/pub/pdb/data/monomers/components.cif.gz"

# extract name of gzip file
gzname = os.path.basename(url)
# extract name of cif file (split by sep, remove last, rejoin)
cifname = os.extsep.join(gzname.split(os.extsep)[:-1])

url_handle = urlopen(url)

with open(gzname, 'wb') as gzh:
    print("Downloading file... (approx. 29 MB)")
    while True:
        data = url_handle.read(1024)
        if len(data) == 0:
            break
        gzh.write(data)

# size as of 13 April 2012
if os.path.getsize(gzname) < 29944258:
    warnings.warn("ERROR: Downloaded file is too small", RuntimeWarning)

fh = gzip.open(gzname, 'rb')
Example #11
0
    def weblogo(self, fname, format="PNG", version="2.8.2", **kwds):
        """Download and save a weblogo using the Berkeley weblogo service.

        Requires an internet connection.

        The parameters from ``**kwds`` are passed directly to the weblogo server.

        Currently, this method uses WebLogo version 3.3.
        These are the arguments and their default values passed to
        WebLogo 3.3; see their website at http://weblogo.threeplusone.com
        for more information::

            'stack_width' : 'medium',
            'stacks_per_line' : '40',
            'alphabet' : 'alphabet_dna',
            'ignore_lower_case' : True,
            'unit_name' : "bits",
            'first_index' : '1',
            'logo_start' : '1',
            'logo_end': str(self.length),
            'composition' : "comp_auto",
            'percentCG' : '',
            'scale_width' : True,
            'show_errorbars' : True,
            'logo_title' : '',
            'logo_label' : '',
            'show_xaxis': True,
            'xaxis_label': '',
            'show_yaxis': True,
            'yaxis_label': '',
            'yaxis_scale': 'auto',
            'yaxis_tic_interval' : '1.0',
            'show_ends' : True,
            'show_fineprint' : True,
            'color_scheme': 'color_auto',
            'symbols0': '',
            'symbols1': '',
            'symbols2': '',
            'symbols3': '',
            'symbols4': '',
            'color0': '',
            'color1': '',
            'color2': '',
            'color3': '',
            'color4': '',

        """
        from Bio._py3k import urlopen, urlencode, Request

        if self.alphabet == 'ACDEFGHIKLMNPQRSTVWY':
            alpha = "alphabet_protein"
        elif self.alphabet == 'ACGU':
            alpha = "alphabet_rna"
        elif self.alphabet == 'ACGT':
            alpha = "alphabet_dna"
        else:
            alpha = "auto"

        frequencies = self.format('transfac')
        url = 'http://weblogo.threeplusone.com/create.cgi'
        values = {'sequences': frequencies,
                  'format': format.lower(),
                  'stack_width': 'medium',
                  'stacks_per_line': '40',
                  'alphabet': alpha,
                  'ignore_lower_case': True,
                  'unit_name': "bits",
                  'first_index': '1',
                  'logo_start': '1',
                  'logo_end': str(self.length),
                  'composition': "comp_auto",
                  'percentCG': '',
                  'scale_width': True,
                  'show_errorbars': True,
                  'logo_title': '',
                  'logo_label': '',
                  'show_xaxis': True,
                  'xaxis_label': '',
                  'show_yaxis': True,
                  'yaxis_label': '',
                  'yaxis_scale': 'auto',
                  'yaxis_tic_interval': '1.0',
                  'show_ends': True,
                  'show_fineprint': True,
                  'color_scheme': 'color_auto',
                  'symbols0': '',
                  'symbols1': '',
                  'symbols2': '',
                  'symbols3': '',
                  'symbols4': '',
                  'color0': '',
                  'color1': '',
                  'color2': '',
                  'color3': '',
                  'color4': '',
                  }

        values.update(
            dict((k, "" if v is False else str(v)) for k, v in kwds.items()))
        data = urlencode(values).encode("utf-8")
        req = Request(url, data)
        response = urlopen(req)
        with open(fname, "wb") as f:
            im = response.read()
            f.write(im)
import inspect
import os
import warnings

from Bio._py3k import urlopen

__docformat__ = "restructuredtext en"

url = "ftp://ftp.wwpdb.org/pub/pdb/data/monomers/components.cif.gz"

# extract name of gzip file
gzname = os.path.basename(url)
# extract name of cif file (split by sep, remove last, rejoin)
cifname = os.extsep.join(gzname.split(os.extsep)[:-1])

url_handle = urlopen(url)

with open(gzname, 'wb') as gzh:
    print("Downloading file... (approx. 29 MB)")
    while True:
        data = url_handle.read(1024)
        if len(data) == 0:
            break
        gzh.write(data)

# size as of 13 April 2012
if os.path.getsize(gzname) < 29944258:
    warnings.warn("ERROR: Downloaded file is too small",
                  RuntimeWarning)

fh = gzip.open(gzname, 'rb')
Example #13
0
    def weblogo(self,fname,format="PNG",version="2.8.2", **kwds):
        """
        uses the Berkeley weblogo service to download and save a weblogo of
        itself

        requires an internet connection.
        The parameters from **kwds are passed directly to the weblogo server.

        Currently, this method uses WebLogo version 3.3.
        These are the arguments and their default values passed to
        WebLogo 3.3; see their website at http://weblogo.threeplusone.com
        for more information:

            'stack_width' : 'medium',
            'stack_per_line' : '40',
            'alphabet' : 'alphabet_dna',
            'ignore_lower_case' : True,
            'unit_name' : "bits",
            'first_index' : '1',
            'logo_start' : '1',
            'logo_end': str(self.length),
            'composition' : "comp_auto",
            'percentCG' : '',
            'scale_width' : True,
            'show_errorbars' : True,
            'logo_title' : '',
            'logo_label' : '',
            'show_xaxis': True,
            'xaxis_label': '',
            'show_yaxis': True,
            'yaxis_label': '',
            'yaxis_scale': 'auto',
            'yaxis_tic_interval' : '1.0',
            'show_ends' : True,
            'show_fineprint' : True,
            'color_scheme': 'color_auto',
            'symbols0': '',
            'symbols1': '',
            'symbols2': '',
            'symbols3': '',
            'symbols4': '',
            'color0': '',
            'color1': '',
            'color2': '',
            'color3': '',
            'color4': '',

        """
        from Bio._py3k import urlopen, urlencode, Request

        frequencies = self.format('transfac')
        url = 'http://weblogo.threeplusone.com/create.cgi'
        values = {'sequences': frequencies,
                  'format': format.lower(),
                  'stack_width': 'medium',
                  'stack_per_line': '40',
                  'alphabet': 'alphabet_dna',
                  'ignore_lower_case': True,
                  'unit_name': "bits",
                  'first_index': '1',
                  'logo_start': '1',
                  'logo_end': str(self.length),
                  'composition': "comp_auto",
                  'percentCG': '',
                  'scale_width': True,
                  'show_errorbars': True,
                  'logo_title': '',
                  'logo_label': '',
                  'show_xaxis': True,
                  'xaxis_label': '',
                  'show_yaxis': True,
                  'yaxis_label': '',
                  'yaxis_scale': 'auto',
                  'yaxis_tic_interval': '1.0',
                  'show_ends': True,
                  'show_fineprint': True,
                  'color_scheme': 'color_auto',
                  'symbols0': '',
                  'symbols1': '',
                  'symbols2': '',
                  'symbols3': '',
                  'symbols4': '',
                  'color0': '',
                  'color1': '',
                  'color2': '',
                  'color3': '',
                  'color4': '',
                  }
        for k, v in kwds.items():
            if isinstance(values[k], bool):
                if not v:
                    v = ""
            values[k]=str(v)

        data = urlencode(values)
        req = Request(url, data)
        response = urlopen(req)
        f = open(fname,"w")
        im = response.read()

        f.write(im)
        f.close()