#!/usr/bin/env python # coding: utf-8 # # Intermine-Python: Tutorial 12: More about Queries # Welcome to your twelfth intermine-python tutorial. # This tutorial will cover some more functionalities of a query. Queries are the basis of all research in InterMine and being able to manage them more effectively is always useful. # In[1]: from intermine.webservice import Service # In[2]: service = Service("https://www.flymine.org/query/service") query=service.new_query() # In[3]: query.add_view("Gene.organism.name","Gene.symbol") # Suppose, the query is not as simple as a strict cumulative filter and the user wants combinations of constraints. For example, the user wants all genes such that the gene symbol is either ‘eve’ or ‘zen’. This can be incorporated in the following way using set_logic: # In[4]: gene_is_eve = query.add_constraint("Gene.symbol", "=", "eve") gene_is_zen = query.add_constraint("Gene.symbol", "=", "zen") query.set_logic(gene_is_eve | gene_is_zen) # In[5]: for row in query.rows(): print(row) # The query results can be converted into a dictionary in the following way: # In[6]: for row in query.rows(): print(row.to_d()) # Similarly, row.to_l() can be used for conversion of the results into a list. # count() can be used to print the total number of rows in a query: # In[7]: query.count() # to_xml() can be used to return a readable XML serialisation of the query: # In[8]: query.to_xml() # clear_view() can be used to clear the output column list: # In[9]: query.clear_view() # In[10]: for row in query.rows(): print(row) # In these ways, queries can be utilized to a greater extent and produce more fruitful results.