Webservice::InterMine::Query - an object representation of a query on an InterMine database


  # Queries should be created by their webservices, or through
  # the Webservice::InterMine factory module

  my $query = $service->new_query;

      'Get all genes in Drosophilids annotated with GO Terms in the Biological Process namespace'


  $query->set_sort_order('Gene.primaryIdentifier', 'asc');

      path  => 'Gene.goAnnotation.ontologyTerm.namespace',
      op    => '=',
      value => 'biological_process',

      path  => '',
      op    => 'CONTAINS',
      value => 'Drosophila',

  my $results = $query->results(as => 'arrayrefs');

  for my $row (@$results) {
      my ($name, $id, $go_term) = @$row;
      print "$name ($id): $go_term\n";


This module is allows you to construct complex queries and obtain results from webservices which implement InterMine genomic databases.


add_view( [@paths] | [$comma_sep_paths] | [$space_sep_paths])

Adds the paths to the view (result columns). If the argument to add_view is a comma or space separated string, it will be split automatically. All paths must be valid for the model being used, or an exception will be thrown.

set_sort_order( $path, [$direction] )

Defines the sort order for the results to be a particular column in the view (this column must already be in the view, or an exception will be thrown). You do not have to set the sort order manually, the default column is the first column of the view, and the default direction is 'asc'.

constraint methods:

  • add_constraint(%args or $string)

    Adds a constraint the the query. Returns the constraint object. See Webservice::InterMine::Cookbook::Recipe2 and Webservice::InterMine::Cookbook::Recipe3.

  • all_constraints

    Get a list of all the constraint objects attached to the query.

  • remove_constraint($constraint_obj)

    Removes the constraint from the query

  • find_constraints( \&coderef )

    Finds all constraints that match the code reference criterion - eg:

      my @eq_cons = $query->find_constraints(sub {$_->op eq '='});
  • count_constraints

    Returns the number of constraints on the query (or 0 if none)

  • clear_constraints

    Removes all the constraints from the query

  • coded_constraints

    Returns only the constraints that have codes (and can thus be combined to define the logic)

  • constraint_codes

    Returns the contraint codes currently being used by the constraints on the query.

add_join(%args or $path)

Adds a join description to the query (see Webservice::InterMine::Cookbook::Recipe4).


Adds a path description to the query (see Webservice::InterMine::Cookbook::Recipe4).


Get the logic for the query as an object. The Logic object is string overloaded to its human readable string representation (also available with ->code).

see: Webservice::InterMine::LogicalSet

set_logic(EXPR or $str)

Sets the current logic for the query. Illegal logic expressions or strings will cause exceptions to be thrown.


  # Parse a string
  $query->set_logic("A and (B or C)");

  # Perform boolean logic on constraint objects
  $query->set_logic($conA & ($conB | $conC));

results([as => Str, size => Int, start => Int, columnheaders => Bool])

Gets a page of results (defined by start and size - defaulting to all results from the beginning) in a requested format. (See Webservice::InterMine::Cookbook::Recipe5)

The formats are:

  • string

    Returns all rows as one string, with fields separated by tabs and lines separated by new-lines ("\n"). If you are wanting to simply store the results in a flat file, this is probably what you want.

    If you would like column headers, add the parameter: <code>columnheaders => 1</code>

  • strings

    Returns all rows as strings (without new-lines) in an arrayref.

  • hashref[s] [default]

    Returns an arrayref of hashrefs, where the keys are the view columns.

  • arrayref[s]

    Returns an arrayref of arrayrefs, where the fields are in the same order as the view columns.

  • count

    Returns the total number or results, rather than the results themselves.

  • jsonobjects

    By default returns an arrayref of native perl data structures (hashrefs) which correspond to the data format of InterMine jsonobjects (

    Optionally it can return the jsonobjects processed as:

    • raw: the raw text string

    • inflate: inflated objects using autoload

      The inflated objects allow method access to the internal hash using autoloaded accessors, but all objects will be blessed into the same type (Webservice::InterMine::ResultObject), so there is no guarantee of interface (other than inspecting the internal hash).

    • instantiate: real Moose objects

      The instantiated objects allow method access to their internal hash using true accessors, with type-constraints, inheritance, support for "isa" and "ref", coercion of attributes, delegating collections, and all the other things you would expect from a Moose object. Each object will be instantiated as an instance of its class (ie. a $gene will be a member of the "Gene" class).


returns a results object that allows you to iterate through the results row by row, in whatever format you choose. Please see Webservice::InterMine::Cookbook::Recipe6 and Webservice::InterMine::Cookbook::Recipe7.

suspend_validation | resume_validation | validate

Queries will by default check for errors in construction as they are being defined. You can choose to turn this off, which might be useful if you don't want to care about the order you add elements to the query (ie. you might call set_sort_order before add_view), or if you are concerned about speed. In most cases the recommendation is to not turn validation off, unless of course, you really know what you are doing. Calling validate at any point will always perform the validation checks, even if you have suspended validation.


Returns an xml string representation of the query. This is suitable for serialisation of queries.



Alex Kalderimis


Please report any bugs or feature requests to


You can find documentation for this module with the perldoc command.

    perldoc Webservice::InterMine::Query

You can also look for information at:


Copyright 2006 - 2010 FlyMine, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.