Пример #1
0
    def datasets(self, mart, raw=False):
        """to retrieve datasets available for a mart:

        :param str mart: e.g. ensembl. see :attr:`names` for a list of valid MART names
            the mart is the database. see lookfor method or databases attributes

        >>> s = BioMart(verbose=False)
        >>> s.datasets("prod-intermart_1")
        ['protein', 'entry', 'uniparc']


        """
        if mart not in self.names:
            raise BioServicesError(
                "Provided mart name (%s) is not valid. see 'names' attribute" %
                mart)
        ret = self.http_get("?type=datasets&mart=%s" % mart, frmt="txt")

        if raw is False:
            try:
                ret2 = [
                    x.split("\t") for x in ret.split("\n") if len(x.strip())
                ]
                ret = [x[1] for x in ret2]
            except:
                ret = ["?"]

        return ret
Пример #2
0
    def create_filter(self, name, value, dataset=None):
        if dataset:
            valid_filters = self.filters(dataset).keys()
            if name not in valid_filters:
                raise BioServicesError("Invalid filter name. ")

        _filter = """        <Filter name = "%s" value = "%s"/>""" % (name, value)
        return _filter
Пример #3
0
 def create_attribute(self, name, dataset=None):
     #s.attributes(dataset)
     # valid dataset
     if dataset:
         valid_attributes = self.attributes(dataset).keys()
         if name not in valid_attributes:
             raise BioServicesError("Invalid attribute name. ")
     attrib = """        <Attribute name = "%s" />""" % name
     return attrib
Пример #4
0
    def get_datasets(self, mart): 
        """Retrieve datasets with description"""
        if mart not in self.names:
            raise BioServicesError("Provided mart name (%s) is not valid. see 'names' attribute" % mart)

        ret = self.http_get("?type=datasets&mart=%s" %mart, frmt="txt")
        import pandas as pd
        df = pd.read_csv(StringIO(ret), sep='\t', 
            header=None, usecols=[1,2], names=['name', 'description']) 
        return df
Пример #5
0
 def get_xml(self):
     if self.dataset is None:
         raise BioServicesError("data set must be set. Use add_dataset method")
     xml = self.header
     xml += self.dataset + "\n\n"
     for line in self.filters:
         xml += line +"\n"
     for line in self.attributes:
         xml += line + "\n"
     xml += self.footer
     return xml
Пример #6
0
    def show_pie(self):
        """a simple example to demonstrate how to visualise number of
        interactions found in various databases

        """
        try:
            from pylab import pie, clf, title, show, legend
        except ImportError:
            from bioservices import BioServicesError
            raise BioServicesError("You must install pylab/matplotlib to use this functionality")
        labels = range(1, self.N + 1)
        print(labels)
        counting = [len(self.relevant_interactions[i]) for i in labels]


        clf()
        #pie(counting, labels=[str(int(x)) for x in labels], shadow=True)
        pie(counting, labels=[str(x) for x in counting], shadow=True)
        title("Number of interactions found in N databases")
        legend([str(x) + " database(s)" for x in labels])
        show()