Package intermine :: Module query :: Class Template
[hide private]
[frames] | no frames]

Class Template

source code

object --+    
         |    
     Query --+
             |
            Template

A Class representing a predefined query

Templates are ways of saving queries and allowing others to run them simply. They are the main interface to querying in the webapp

SYNOPSIS

example:

 service = Service("http://www.flymine.org/query/service")
 template = service.get_template("Gene_Pathways")
 for row in template.results(A={"value":"eve"}):
   process_row(row)
   ...

A template is a subclass of query that comes predefined. They are typically retrieved from the webservice and run by specifying the values for their existing constraints. They are a concise and powerful way of running queries in the webapp.

Being subclasses of query, everything is true of them that is true of a query. They are just less work, as you don't have to design each one. Also, you can store your own templates in the web-app, and then access them as a private webservice method, from anywhere, making them a kind of query in the cloud - for this you will need to authenticate by providing log in details to the service.

The most significant difference is how constraint values are specified for each set of results.


See Also: Template.results

Instance Methods [hide private]
 
__init__(self, *args, **kwargs)
Instantiation is identical that of queries.
source code
dict
to_query_params(self)
Template.to_query_params() -> dict(string, string)
source code
string
get_results_path(self)
Template.get_results_path() → str
source code
Template
get_adjusted_template(self, con_values)
Template.get_adjusted_template(con_values) → Template
source code
intermine.webservice.ResultIterator
results(self, row='rr', start=0, size=None, **con_values)
This method returns the same values with the same options as the method of the same name in Query (see intermine.query.Query).
source code
list
get_results_list(self, row='rr', start=0, size=None, **con_values)
This method performs the same as the method of the same name in Query, and it shares the semantics of Template.results().
source code
int
count(self, **con_values)
Obtain the number of rows a particular query will return, without having to fetch and parse all the actual data.
source code

Inherited from Query: __iter__, __str__, add_constraint, add_join, add_path_description, add_sort_order, add_view, children, clear_view, clone, column, first, get_constraint, get_default_sort_order, get_list_append_uri, get_list_upload_uri, get_logic, get_sort_order, get_subclass_dict, one, outerjoin, prefix_path, set_logic, to_Node, to_formatted_xml, to_xml, validate_logic, validate_sort_order, verify, verify_constraint_paths, verify_join_paths, verify_pd_paths, verify_views, where

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Methods [hide private]

Inherited from Query: from_xml

Class Variables [hide private]

Inherited from Query: LEADING_OP_PATTERN, LOGIC_OPS, LOGIC_PRODUCT, LOGIC_SPLIT_PATTERN, SO_SPLIT_PATTERN, TRAILING_OP_PATTERN, x, y

Properties [hide private]
  editable_constraints
Template.editable_constraints -> list(intermine.constraints.Constraint)

Inherited from Query: coded_constraints, constraints

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args, **kwargs)
(Constructor)

source code 

Constructor

Instantiation is identical that of queries. As with queries, these are best obtained from the intermine.webservice.Service factory methods.

Parameters:
  • model - an instance of intermine.model.Model. Required
  • service - an instance of l{intermine.service.Service}. Optional, but you will not be able to make requests without one.
  • validate - a boolean - defaults to True. If set to false, the query will not try and validate itself. You should not set this to false.
Overrides: object.__init__

to_query_params(self)

source code 

Returns the query parameters needed for the webservice

Template.to_query_params() -> dict(string, string)

Overrides the method of the same name in query to provide the parameters needed by the templates results service. These are slightly more complex:

  • name: The template's name
  • for each constraint: (where [i] is an integer incremented for each constraint)
    • constraint[i]: the path
    • op[i]: the operator
    • value[i]: the value
    • code[i]: the code
    • extra[i]: the extra value for ternary constraints (optional)
Returns: dict
Overrides: Query.to_query_params

get_results_path(self)

source code 

Returns the path section pointing to the REST resource

Template.get_results_path() → str

Internally, this just calls a constant property in intermine.service.Service

This overrides the method of the same name in Query

Returns: string
the path to the REST resource
Overrides: Query.get_results_path

get_adjusted_template(self, con_values)

source code 

Gets a template to run

Template.get_adjusted_template(con_values) → Template

When templates are run, they are first cloned, and their values are changed to those desired. This leaves the original template unchanged so it can be run again with different values. This method does the cloning and changing of constraint values

Returns: Template
Raises:
  • ConstraintError - if the constraint values specify values for a non-editable constraint.

results(self, row='rr', start=0, size=None, **con_values)

source code 

Get an iterator over result rows

This method returns the same values with the same options as the method of the same name in Query (see intermine.query.Query). The main difference in in the arguments.

The template result methods also accept a key-word pair set of arguments that are used to supply values to the editable constraints. eg:

 template.results(
   A = {"value": "eve"},
   B = {"op": ">", "value": 5000}
 )

The keys should be codes for editable constraints (you can inspect these with Template.editable_constraints) and the values should be a dictionary of constraint properties to replace. You can replace the values for "op" (operator), "value", and "extra_value" and "values" in the case of ternary and multi constraints.

Parameters:
  • row - the format for the row. Defaults to "rr". Valid options are "rr", "dict", "list", "jsonrows", "jsonobject", "tsv", "csv".
Returns: intermine.webservice.ResultIterator
Raises:
Overrides: Query.results

get_results_list(self, row='rr', start=0, size=None, **con_values)

source code 

Get a list of result rows

This method performs the same as the method of the same name in Query, and it shares the semantics of Template.results().

Returns: list
Overrides: Query.get_results_list

count(self, **con_values)

source code 

Return the total number of rows this template returns

Obtain the number of rows a particular query will return, without having to fetch and parse all the actual data. This method makes a request to the server to report the count for the query, and is sugar for a results call.

Returns: int
Raises:
Overrides: Query.count

Property Details [hide private]

editable_constraints

Return the list of constraints you can edit

Template.editable_constraints -> list(intermine.constraints.Constraint)

Templates have a concept of editable constraints, which is a way of hiding complexity from users. An underlying query may have five constraints, but only expose the one that is actually interesting. This property returns this subset of constraints that have the editable flag set to true.

Get Method:
unreachable.editable_constraints(self) - Template.editable_constraints -> list(intermine.constraints.Constraint)