This tutorial will talk about how you can create and save lists in your account. Like the previous tutorial, you will need to provide your login information while creating a service object.
You can either provide a list of identifiers (for example, gene symbols) and the Intermine Server will try to resolve them into objects in the database or you provide a query that specifies exactly what you want.
from intermine.webservice import Service
Enter your login information, uncomment the line of code and then run it.
#service=Service("www.flymine.org/flymine/service",username="Enter username",password="Enter password")
We will look at three methods in this tutorial. Let's say you want to upload a list of strings (Gene Symbols). We begin by declaring a list, which I've called symbols.
symbols=["eve","zen","rudimentary"]
Note that you can use their secondary identifiers or DB identifiers instead if you're more comfortable with that. So if you changed symbols to ["CG2328","zen","rudimentary"] or ["eve","FBgn0004053","rudimentary] it would not be an issue as Intermine would be able to resolve it for you.
To create a list, you need to declare a list manager object. We then use the create_list method as shown below. Remember to define a name for the list, otherwise the list will be lost once the session will be terminated.
lm=service.list_manager()
lm.create_list(content=symbols,list_type="Gene",name="my list")
<intermine.lists.list.List at 0x7fec5547f4e0>
We will now look at how you can save a list from a query. Suppose that you want to extract only the information regarding the gene symbol "eve" stored in the previous list that we uploaded. You can do it as shown below.
query=service.new_query("Gene")
query.add_constraint("Gene","IN","my list")
<ListConstraint: Gene IN my list>
query.add_constraint("symbol","=","eve")
<BinaryConstraint: Gene.symbol = eve>
lm.create_list(query,name="my list 2")
<intermine.lists.list.List at 0x7fec554874a8>
Finally, let's say that you have a file with a list of gene identifiers stored on your machine, which you want to upload as a list. Change the string stored to match the path location of your file. Uncomment the lines of code and run it.
#file="Enter/File/Path.tsv"
#lm.create_list(file,list_type="Gene",name="my list 3")
If you want to view the names of all the lists available, use the following:
lm.get_all_list_names()
dict_keys(['PL FlyAtlas_brain_top', 'second list', 'PL FlyTF_putativeTFs', 'H. sapiens orthologues of FlyTF_site_specific_1', 'esyN demo list', 'my list', 'first list', 'PL FlyAtlas_maleglands_top', 'my_list_1', 'PL FlyAtlas_hindgut_top', 'my list 2', 'PL FlyTF_site_specific_TFs'])