intermine.lists package

Submodules

intermine.lists.list module

class intermine.lists.list.List(**args)[source]

Bases: object

Lists represent stored collections of data and saved result sets in an InterMine data warehouse. This class is an abstraction of this information, and provides mechanisms for managing the data.

example:

>>> from intermine.webservice import Service
>>>
>>> flymine = Service("www.flymine.org/query", "SOMETOKEN")
>>> new_list = flymine.create_list(["h", "zen", "eve", "bib"], "Gene", name="My New List")
>>>
>>> another_list = flymine.get_list("Some other list")
>>> combined_list = new_list | another_list # Same syntax as for sets
>>> combined_list.name = "Union of the other lists"
>>>
>>> print "The combination of the two lists has %d elements" % combined_list.size
>>> print "The combination of the two lists has %d elements" % len(combined_list)
>>>
>>> for row in combined_list:
...     print row

Lists are created from a webservice, and can be manipulated in various ways. The operations are:

* Union: this | that
* Intersection: this & that
* Symmetric Difference: this ^ that
* Asymmetric Difference (subtraction): this - that
* Appending: this += that
Lists can be created from a list of identifiers that could be::
  • stored in a file
  • held in a list or set
  • contained in a string

In all these cases the syntax is the same:

>>> new_list = service.create_list(content, type, name="Some name", description="Some description", tags=["some", "tags"])

Lists can also be created from a query’s result with the exact same syntax. In the case of queries, the type is not required, but the query should have just one view, and it should be an id.

>>> query = service.new_query()
>>> query.add_view("Gene.id")
>>> query.add_constraint("Gene.length", "<", 100)
>>> new_list = service.create_list(query, name="Short Genes")
LOG = <logging.Logger object>
add_tags(*tags)[source]

Calls the server to add these tags, and updates this lists tags.

append(appendix)[source]

Append the arguments to this list

calculate_enrichment(widget, background=None, correction='Holm-Bonferroni', maxp=0.05, filter='')[source]

example:

>>> for item in service.get_list("some list").calculate_enrichment("thingy_enrichment"):
...     print item.identifier, item.p_value

Gets an iterator over the rows for an enrichment calculation. Each row represents a record with the following properties:

  • identifier {str}
  • p-value {float}
  • matches {int}
  • description {str}

The enrichment row object may be treated as an object with property access, or as a dictionary, supporting key lookup with the [] operator:

>>> p_value = row['p-value']
count

Alias for obj.size. Also available as len(obj)

date_created

When this list was originally created

del_name()[source]

Raises an error - lists must always have a name

delete()[source]

Calls the webservice to delete this list immediately. This object should not be used after this method is called - attempts to do so will raise errors.

description

The human readable description of this list

get_name()[source]

The name of the list used to access it programmatically

is_authorized

Whether or not the current user is authorised to make changes to this list

list_type

The type of the InterMine objects this list can contain

make_list_constraint(path, op)[source]

Implementation of trait that allows use of these objects in list constraints

name

The name of this list

remove_tags(*tags)[source]

Calls the server to remove these tags, and updates this lists tags.

set_name(new_name)[source]

Setting the list’s name causes the list’s name to be updated on the server.

size

Return the number of elements in the list. Also available as len(obj)

status

The upgrade status of this list

tags

The tags associated with this list

title

The fixed title of this list

to_query()[source]

Return a new query constrained to the objects in this list, and with a single view column of the objects ids.

@rtype: intermine.query.Query

update_tags(*tags)[source]

Calls the server to remove these tags, and updates this lists tags.

intermine.lists.listmanager module

class intermine.lists.listmanager.ListManager(service)[source]

Bases: object

This class provides methods to manage list contents and operations.

This class may be called itself, but all the useful methods it has are also available on the Service object, which delegates to this class, while other methods are more coneniently accessed through the list objects themselves.

NB: The methods for creating lists can conflict in threaded applications, if two threads are each allocated the same unused list name. You are strongly advised to use locks to synchronise any list creation requests (create_list, or intersect, union, subtract, diff) unless you are choosing your own names each time and are confident that these will not conflict.

DEFAULT_DESCRIPTION = 'List created with Python client library'
DEFAULT_LIST_NAME = 'my_list'
DIFFERENCE_PATH = '/lists/diff/json'
INTERSECTION_PATH = '/lists/intersect/json'
LOG = <logging.Logger object>
SUBTRACTION_PATH = '/lists/subtract/json'
UNION_PATH = '/lists/union/json'
add_tags(to_tag, tags)[source]

Returns the current tags of this list.

create_list(content, list_type='', name=None, description=None, tags=[], add=[])[source]

If no name is given, the list will be considered to be a temporary list, and will be automatically deleted when the program ends. To prevent this happening, give the list a name, either on creation, or by renaming it.

This method is not thread safe for anonymous lists - it will need synchronisation with locks if you intend to create lists with multiple threads in parallel.

@param content: The source of the identifiers for this list. This can be:
  • A string with white-space separated terms.
  • The name of a file that contains the terms.
  • A file-handle like thing (something with a ‘read’ method)
  • An iterable of identifiers
  • A query with a single column.
  • Another list.
@param list_type: The type of objects to include in the list. This parameter is not
required if the content parameter implicitly includes the type (as queries and lists do).
@param name: The name for the new list. If none is provided one will be generated, and the
list will be deleted when the list manager exits context.

@param description: A description for the list (free text, default = None) @param tags: A set of strings to use as tags (default = []) @param add: The issues groups that can be treated as matches. This should be a

collection of strings naming issue groups that would otherwise be ignored, but in this case will be added to the list. The available groups are:

  • DUPLICATE - More than one match was found.

  • WILDCARD - A wildcard match was made.

  • TYPE_CONVERTED - A match was found, but in another type (eg. found a protein

    and we could convert it to a gene).

  • OTHER - other issue types

  • :all - All issues should be considered acceptable.

This only makes sense with text uploads - it is not required (or used) when the content is a list or a query.

@rtype: intermine.lists.List

delete_lists(lists)[source]

Delete the given lists from the webserver

delete_temporary_lists()[source]

Delete all the lists considered temporary (those created without names)

get_all_list_names()[source]

Get all the names of the lists in a particular webservice

get_all_lists()[source]

Get all the lists on a webservice

get_list(name)[source]

Return a list from the service by name, if it exists

get_list_count()[source]

Return the number of lists accessible at the given webservice. This number will vary depending on who you are authenticated as.

get_tags(im_list)[source]

Returns the current tags of this list.

get_unused_list_name()[source]

This method returns a new name that does not conflict with any currently existing list name.

The list name is only guaranteed to be unused at the time of allocation.

intersect(lists, name=None, description=None, tags=[])[source]

Calculate the intersection of a given set of lists, and return the list representing the result

l(name)[source]

Alias for get_list

make_list_names(lists)[source]

Turn a list of things into a list of list names

parse_list_upload_response(response)[source]

Intepret the response from the webserver to a list request, and return the List it describes

refresh_lists()[source]

Update the list information with the latest details from the server

remove_tags(to_remove_from, tags)[source]

Returns the current tags of this list.

static safe_dict(d)[source]

Recursively clone json structure with UTF-8 dictionary keys

subtract(lefts, rights, name=None, description=None, tags=[])[source]

Calculate the subtraction of rights from lefts, and return the list representing the result

union(lists, name=None, description=None, tags=[])[source]

Calculate the union of a given set of lists, and return the list representing the result

xor(lists, name=None, description=None, tags=[])[source]

Calculate the symmetric difference of a given set of lists, and return the list representing the result

exception intermine.lists.listmanager.ListServiceError[source]

Bases: intermine.errors.WebserviceError

Errors thrown when something goes wrong with list requests

intermine.lists.listmanager.safe_key(maybe_unicode)[source]

Module contents