{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Intermine-Python: Tutorial 9: Creating Lists" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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. " ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from intermine.webservice import Service" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Enter your login information, uncomment the line of code and then run it. " ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#service=Service(\"www.flymine.org/flymine/service\",username=\"Enter username\",password=\"Enter password\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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. " ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": true }, "outputs": [], "source": [ "symbols=[\"eve\",\"zen\",\"rudimentary\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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. " ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "lm=service.list_manager()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lm.create_list(content=symbols,list_type=\"Gene\",name=\"my list\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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. " ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": true }, "outputs": [], "source": [ "query=service.new_query(\"Gene\")" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query.add_constraint(\"Gene\",\"IN\",\"my list\")" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query.add_constraint(\"symbol\",\"=\",\"eve\")" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lm.create_list(query,name=\"my list 2\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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. " ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#file=\"Enter/File/Path.tsv\"\n", "#lm.create_list(file,list_type=\"Gene\",name=\"my list 3\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you want to view the names of all the lists available, use the following:" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "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'])" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lm.get_all_list_names()" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python [conda root]", "language": "python", "name": "conda-root-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.2" } }, "nbformat": 4, "nbformat_minor": 1 }