def select(self, *columns, **kwargs): """ Construct a new Query object with the given columns selected. ============================================================= As new_query, except that instead of a root class, a list of output column expressions are passed instead. """ if "xml" in kwargs: return self.load_query(kwargs["xml"]) if len(columns) == 1: view = columns[0] if isinstance(view, Attribute): return Query(self.model, self).select( "%s.%s" % (view.declared_in.name, view)) if isinstance(view, Reference): return Query(self.model, self).select( "%s.%s.*" % (view.declared_in.name, view)) elif not isinstance(view, Column) and not str(view).endswith("*"): path = self.model.make_path(view) if not path.is_attribute(): return Query(self.model, self).select(str(view) + ".*") return Query(self.model, self).select(*columns)
def load_query(self, xml, root=None): """ Construct a new Query object for the given webservice ===================================================== This is the standard method for instantiating new Query objects. Queries require access to the data model, as well as the service itself, so it is easiest to access them through this factory method. @return: L{intermine.query.Query} """ return Query.from_xml(xml, self.model, root=root)
from intermine.query import Query from intermine.model import Model m = Model('http://www.flymine.org/query/service/model') q = Query(m) q.name = 'Foo' q.description = 'a query made out of pythons' q.add_view("Gene.name Gene.symbol") q.add_constraint('Gene', 'LOOKUP', 'eve') q.add_constraint('Gene.length', '>', 50000) q.add_constraint('Gene', 'Clone') q.add_constraint('Gene.symbol', 'ONE OF', ['eve', 'zen']) q.add_join('Gene.alleles') q.add_path_description('Gene', 'One of those gene-y things') print q.to_xml() print q.to_formatted_xml()