Exemplo n.º 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()
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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()