首页 > 解决方案 > 将 bool_list 传递给 pybiomart 包中的方法

问题描述

我正在使用pybiomart python,我想使用此处提供的过滤器之一。其中一个过滤器是boolean_list类型。我不确定在使用该类型的过滤器值时如何传递参数。我通过显示以下内容的方法 知道它是boolean_list类型:dataset.list_filters()在此处输入图像描述

我的查询如下:

from pybiomart import Server, Dataset
a=[False]*20
a[7]=True
dataset=Dataset(name='hsapiens_gene_ensembl', host='http://www.ensembl.org')
dataset.query(attributes=['uniprotswissprot'],filters={'id_list_protein_domain_and_feature_filters':a})

我在这里所做的是我将a作为过滤dic中相应过滤器的值传递。我认为我将a定义为 boolean_list (这是我的想法)。我将 a 定义为 20 个布尔值的列表,False除了我需要的那个之外,我都做了True请从biomart网站的 GUI 中查看下面的屏幕截图。我想选择With Pfam ID(s)作为该过滤器的值(id_list_protein_domain_and_feature_filters)问题是当我运行该查询时,我收到以下错误:

---------------------------------------------------------------------------
BiomartException                          Traceback (most recent call last)
<ipython-input-19-3b59f9b0b207> in <module>()
      3 a[2]=True
      4 dataset=Dataset(name='hsapiens_gene_ensembl', host='http://www.ensembl.org')
----> 5 dataset.query(attributes=['uniprotswissprot'],filters={'id_list_protein_domain_and_feature_filters':a})

/usr/local/lib/python3.7/dist-packages/pybiomart/dataset.py in query(self, attributes, filters, only_unique, use_attr_names)
    264         # Raise exception if an error occurred.
    265         if 'Query ERROR' in response.text:
--> 266             raise BiomartException(response.text)
    267 
    268         # Parse results into a DataFrame.

BiomartException: Query ERROR: caught BioMart::Exception::Database: Error during query execution: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' ensembl_mart_103.hsapiens_gene_ensembl__translation__main main WHERE (.  'False' at line 1 

我要做的基本上是选择组合框中的一项(如下面来自 biomart 网站 GUI 的屏幕截图)提前谢谢。 我想通过 pybiomart 包执行的 GUI 过滤器选择示例

标签: pythonbiomart

解决方案


推荐阅读