{ "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": 1, "metadata": {}, "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": 2, "metadata": {}, "outputs": [], "source": [ "service=Service(\"https://www.flymine.org/flymine/service\",username=\"demo@intermine.org\",password=\"demo\")" ] }, { "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": 3, "metadata": {}, "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": 4, "metadata": {}, "outputs": [], "source": [ "lm=service.list_manager()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lm.delete_lists([\"my list\"])\n", "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": 6, "metadata": {}, "outputs": [], "source": [ "query=service.new_query(\"Gene\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query.add_constraint(\"Gene\",\"IN\",\"my list\")" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query.add_constraint(\"symbol\",\"=\",\"eve\")" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lm.delete_lists([\"my list 2\"])\n", "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": 10, "metadata": {}, "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": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['Gene List (Fri Aug 23 2019 15:39:10 GMT+0100 (British Summer Time))', 'Gene List (Mon Jun 03 2019 14:12:11 GMT+0100 (BST))', 'Gene list for D. melanogaster 03 Jun 2019 13:10:42', 'H. sapiens orthologues of FlyTF_site_specific_1', 'PL FlyAtlas_brain_top', 'PL FlyAtlas_head_top', 'PL FlyAtlas_hindgut_top', 'PL FlyAtlas_maleglands_top', 'PL FlyAtlas_ovary_top', 'PL FlyAtlas_testis_top', 'PL FlyAtlas_tubules_top', 'PL FlyTF_PWM_TFs', 'PL FlyTF_REDfly_TFs', 'PL FlyTF_putativeTFs', 'PL FlyTF_site_specific_TFs', 'PL FlyTF_trusted_TFs', 'PL classI', 'PL classII', 'PL classIII', 'PL classIIIa', 'PL classIIIb', 'PL classIIIc', 'PL classIIa', 'PL classIIb', 'PL classIIc', 'PL classIa', 'PL classIb', 'PL dme_immunity_genes', 'Testing stuff', 'UseCase1_transcripts_ERstress', 'UseCase1_transcripts_oxidativeStress', 'UseCase5_ScreenHits', 'UseCase5_backgroundGeneList', 'bobo', 'bobo_1', 'combination-1', 'combination-2', 'esyN demo list', 'esyN demo list_1', 'my list', 'my list 2', 'my_list_1'])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lm.get_all_list_names()" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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.6.9" } }, "nbformat": 4, "nbformat_minor": 1 }