{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Creating an InterMine workflow using the API" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We are going to re-create the workflow we did using the web interface using the python API.\n", "\n", "We start by importing the Service class from InterMine's webservice module. You will need to access your account on humanMine and you do this through an API token. You can get your token by logging into [HumanMine](http://www.humanmine.org/) and going to the account details tab within MyMine. Cut and paste your token into the code below." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "from intermine.webservice import Service\n", "service = Service(\"http://www.humanmine.org/humanmine/service\", token = \"YOUR TOKEN HERE\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Our first query looked at whether the set of Pax6 targets (from list PL_Pax6_Targets) are expressed in the pancreas. In the web interface we used a template to run this query, but here we will create a query object. " ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "query = service.new_query(\"Gene\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First we will define the output columns that we want in our result - i.e the view. We want to add fields (attributes) from both the Gene class and the proteinAtlasExpression class." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query.add_view(\n", " \"primaryIdentifier\", \"symbol\", \"proteinAtlasExpression.cellType\",\n", " \"proteinAtlasExpression.level\", \"proteinAtlasExpression.reliability\",\n", " \"proteinAtlasExpression.tissue.name\"\n", ")\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, add the constraints to your query. We want to constrain the Gene class to the genes in the PL_Pax6_Targets list." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query.add_constraint(\"Gene\", \"IN\", \"PL_Pax6_Targets\", code = \"A\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We also need to constrain the expression level to be \"high\" or \"medium\" and the tissue to be \"pancreas\"." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query.add_constraint(\"proteinAtlasExpression.tissue.name\", \"=\", \"Pancreas\", code = \"B\")\n", "query.add_constraint(\"proteinAtlasExpression.level\", \"ONE OF\", [\"Medium\", \"High\"], code = \"C\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, let's check what the query returns by looping through the rows and printing the results:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(u'84618', u'NT5C1A', u'exocrine glandular cells', u'Medium', u'Supported', u'Pancreas')\n", "(u'29880', u'ALG5', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'10097', u'ACTR2', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'10097', u'ACTR2', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'476', u'ATP1A1', u'exocrine glandular cells', u'High', u'Enhanced', u'Pancreas')\n", "(u'23200', u'ATP11B', u'exocrine glandular cells', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'374868', u'ATP9B', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'490', u'ATP2B1', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'490', u'ATP2B1', u'islets of Langerhans', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'54828', u'BCAS3', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'54828', u'BCAS3', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'1121', u'CHM', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'1121', u'CHM', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'55152', u'DALRD3', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'55152', u'DALRD3', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'5422', u'POLA1', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'23085', u'ERC1', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'2045', u'EPHA7', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'2045', u'EPHA7', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'2048', u'EPHB2', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'55120', u'FANCL', u'exocrine glandular cells', u'Medium', u'Supported', u'Pancreas')\n", "(u'55120', u'FANCL', u'islets of Langerhans', u'Medium', u'Supported', u'Pancreas')\n", "(u'28964', u'GIT1', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'2736', u'GLI2', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'2736', u'GLI2', u'islets of Langerhans', u'High', u'Approved', u'Pancreas')\n", "(u'6928', u'HNF1B', u'exocrine glandular cells', u'High', u'Enhanced', u'Pancreas')\n", "(u'9922', u'IQSEC1', u'exocrine glandular cells', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'8543', u'LMO4', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'8543', u'LMO4', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'26468', u'LHX6', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'26468', u'LHX6', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'987', u'LRBA', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'4211', u'MEIS1', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'4212', u'MEIS2', u'exocrine glandular cells', u'High', u'Enhanced', u'Pancreas')\n", "(u'4212', u'MEIS2', u'islets of Langerhans', u'High', u'Enhanced', u'Pancreas')\n", "(u'140609', u'NEK7', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'140609', u'NEK7', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'5087', u'PBX1', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'5087', u'PBX1', u'islets of Langerhans', u'Medium', u'Supported', u'Pancreas')\n", "(u'5090', u'PBX3', u'exocrine glandular cells', u'Medium', u'Supported', u'Pancreas')\n", "(u'5090', u'PBX3', u'islets of Langerhans', u'Medium', u'Supported', u'Pancreas')\n", "(u'9678', u'PHF14', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'23133', u'PHF8', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'23133', u'PHF8', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'5862', u'RAB2A', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'5862', u'RAB2A', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'27316', u'RBMX', u'exocrine glandular cells', u'Medium', u'Supported', u'Pancreas')\n", "(u'27316', u'RBMX', u'islets of Langerhans', u'Medium', u'Supported', u'Pancreas')\n", "(u'55703', u'POLR3B', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'23328', u'SASH1', u'exocrine glandular cells', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'23328', u'SASH1', u'islets of Langerhans', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'9792', u'SERTAD2', u'exocrine glandular cells', u'High', u'Enhanced', u'Pancreas')\n", "(u'84193', u'SETD3', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'7110', u'TMF1', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'7110', u'TMF1', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'80700', u'UBXN6', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'27072', u'VPS41', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'65125', u'WNK1', u'islets of Langerhans', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'51741', u'WWOX', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'51741', u'WWOX', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'3983', u'ABLIM1', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'4301', u'AFDN', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'51319', u'RSRC1', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'51319', u'RSRC1', u'islets of Langerhans', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'657', u'BMPR1A', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'84529', u'C15orf41', u'exocrine glandular cells', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'171425', u'CLYBL', u'exocrine glandular cells', u'High', u'Enhanced', u'Pancreas')\n", "(u'171425', u'CLYBL', u'islets of Langerhans', u'High', u'Enhanced', u'Pancreas')\n", "(u'1478', u'CSTF2', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'1478', u'CSTF2', u'islets of Langerhans', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'905', u'CCNT2', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'905', u'CCNT2', u'islets of Langerhans', u'High', u'Supported', u'Pancreas')\n", "(u'3491', u'CYR61', u'exocrine glandular cells', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'1848', u'DUSP6', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'26610', u'ELP4', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'26610', u'ELP4', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'79767', u'ELMO3', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'8891', u'EIF2B3', u'exocrine glandular cells', u'Medium', u'Supported', u'Pancreas')\n", "(u'8891', u'EIF2B3', u'islets of Langerhans', u'Medium', u'Supported', u'Pancreas')\n", "(u'8667', u'EIF3H', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'8667', u'EIF3H', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'11340', u'EXOSC8', u'exocrine glandular cells', u'High', u'Uncertain', u'Pancreas')\n", "(u'83989', u'FAM172A', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'83989', u'FAM172A', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'63877', u'FAM204A', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'55137', u'FIGN', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'55137', u'FIGN', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'93986', u'FOXP2', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'93986', u'FOXP2', u'islets of Langerhans', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'2971', u'GTF3A', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'2619', u'GAS1', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'3172', u'HNF4A', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'3187', u'HNRNPH1', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'3187', u'HNRNPH1', u'islets of Langerhans', u'High', u'Supported', u'Pancreas')\n", "(u'8339', u'HIST1H2BG', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'8339', u'HIST1H2BG', u'islets of Langerhans', u'High', u'Supported', u'Pancreas')\n", "(u'3205', u'HOXA9', u'islets of Langerhans', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'3217', u'HOXB7', u'exocrine glandular cells', u'High', u'Uncertain', u'Pancreas')\n", "(u'3233', u'HOXD4', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'3233', u'HOXD4', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'3397', u'ID1', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'3397', u'ID1', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'3615', u'IMPDH2', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'3615', u'IMPDH2', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'57117', u'INTS12', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'57117', u'INTS12', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'359948', u'IRF2BP2', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'359948', u'IRF2BP2', u'islets of Langerhans', u'High', u'Approved', u'Pancreas')\n", "(u'3728', u'JUP', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'3728', u'JUP', u'islets of Langerhans', u'Medium', u'Supported', u'Pancreas')\n", "(u'57565', u'KLHL14', u'exocrine glandular cells', u'High', u'Uncertain', u'Pancreas')\n", "(u'57565', u'KLHL14', u'islets of Langerhans', u'High', u'Uncertain', u'Pancreas')\n", "(u'114818', u'KLHL29', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'22920', u'KIFAP3', u'exocrine glandular cells', u'Medium', u'Supported', u'Pancreas')\n", "(u'22920', u'KIFAP3', u'islets of Langerhans', u'Medium', u'Supported', u'Pancreas')\n", "(u'83938', u'LRMDA', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'201255', u'LRRC45', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'54674', u'LRRN3', u'exocrine glandular cells', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'143098', u'MPP7', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'143098', u'MPP7', u'islets of Langerhans', u'High', u'Enhanced', u'Pancreas')\n", "(u'145282', u'MIPOL1', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'145282', u'MIPOL1', u'islets of Langerhans', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'219402', u'MTIF3', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'219402', u'MTIF3', u'islets of Langerhans', u'High', u'Approved', u'Pancreas')\n", "(u'5607', u'MAP2K5', u'exocrine glandular cells', u'Medium', u'Supported', u'Pancreas')\n", "(u'51776', u'MAP3K20', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'124540', u'MSI2', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'124540', u'MSI2', u'islets of Langerhans', u'High', u'Approved', u'Pancreas')\n", "(u'4082', u'MARCKS', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'4082', u'MARCKS', u'islets of Langerhans', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'4756', u'NEO1', u'exocrine glandular cells', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'4774', u'NFIA', u'exocrine glandular cells', u'High', u'Enhanced', u'Pancreas')\n", "(u'340371', u'NRBP2', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'340371', u'NRBP2', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'2494', u'NR5A2', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'2494', u'NR5A2', u'islets of Langerhans', u'High', u'Supported', u'Pancreas')\n", "(u'116039', u'OSR2', u'islets of Langerhans', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'5080', u'PAX6', u'islets of Langerhans', u'High', u'Supported', u'Pancreas')\n", "(u'5727', u'PTCH1', u'exocrine glandular cells', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'5727', u'PTCH1', u'islets of Langerhans', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'5195', u'PEX14', u'exocrine glandular cells', u'Medium', u'Supported', u'Pancreas')\n", "(u'5195', u'PEX14', u'islets of Langerhans', u'Medium', u'Supported', u'Pancreas')\n", "(u'5144', u'PDE4D', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'5150', u'PDE7A', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'144100', u'PLEKHA7', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'144100', u'PLEKHA7', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'389072', u'PLEKHM3', u'exocrine glandular cells', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'389072', u'PLEKHM3', u'islets of Langerhans', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'5339', u'PLEC', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'22827', u'PUF60', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'22827', u'PUF60', u'islets of Langerhans', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'5033', u'P4HA1', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'54681', u'P4HTM', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'54681', u'P4HTM', u'islets of Langerhans', u'Medium', u'Supported', u'Pancreas')\n", "(u'10196', u'PRMT3', u'exocrine glandular cells', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'10196', u'PRMT3', u'islets of Langerhans', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'5566', u'PRKACA', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'5566', u'PRKACA', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'6210', u'RPS15A', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'6428', u'SRSF3', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'6428', u'SRSF3', u'islets of Langerhans', u'High', u'Supported', u'Pancreas')\n", "(u'55084', u'SOBP', u'exocrine glandular cells', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'55084', u'SOBP', u'islets of Langerhans', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'115286', u'SLC25A26', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'6840', u'SVIL', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'6809', u'STX3', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'6809', u'STX3', u'islets of Langerhans', u'High', u'Approved', u'Pancreas')\n", "(u'57616', u'TSHZ3', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'6938', u'TCF12', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'6934', u'TCF7L2', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'6934', u'TCF7L2', u'islets of Langerhans', u'High', u'Supported', u'Pancreas')\n", "(u'6907', u'TBL1X', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'6907', u'TBL1X', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'3842', u'TNPO1', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'3842', u'TNPO1', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'6902', u'TBCA', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'6902', u'TBCA', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'7533', u'YWHAH', u'islets of Langerhans', u'Medium', u'Uncertain', u'Pancreas')\n", "(u'9039', u'UBA3', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'9039', u'UBA3', u'islets of Langerhans', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'9690', u'UBE3C', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'9690', u'UBE3C', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'84669', u'USP32', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'84669', u'USP32', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'7444', u'VRK2', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'143187', u'VTI1A', u'exocrine glandular cells', u'High', u'Supported', u'Pancreas')\n", "(u'9686', u'VGLL4', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'79971', u'WLS', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'23613', u'ZMYND8', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'84858', u'ZNF503', u'exocrine glandular cells', u'High', u'Approved', u'Pancreas')\n", "(u'84858', u'ZNF503', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n", "(u'25925', u'ZNF521', u'exocrine glandular cells', u'Medium', u'Enhanced', u'Pancreas')\n", "(u'23414', u'ZFPM2', u'exocrine glandular cells', u'Medium', u'Approved', u'Pancreas')\n", "(u'23414', u'ZFPM2', u'islets of Langerhans', u'Medium', u'Approved', u'Pancreas')\n" ] } ], "source": [ "for row in query.rows():\n", " print(row[\"primaryIdentifier\"], row[\"symbol\"], row[\"proteinAtlasExpression.cellType\"], \\\n", " row[\"proteinAtlasExpression.level\"], row[\"proteinAtlasExpression.reliability\"], \\\n", " row[\"proteinAtlasExpression.tissue.name\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We want to save this set of genes (i.e genes from the Pax6 target set that are expressed in the pancreas) for further analysis. To do this we define our python list and loop through our results again - this time, instead of printing the results, we append just the primary identifiers returned to our list." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "UpinPancreas = list()\n", "for row in query.rows():\n", " UpinPancreas.append(row[\"primaryIdentifier\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and check that the list we have created looks correct:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[u'84618', u'29880', u'10097', u'10097', u'476', u'23200', u'374868', u'490', u'490', u'54828', u'54828', u'1121', u'1121', u'55152', u'55152', u'5422', u'23085', u'2045', u'2045', u'2048', u'55120', u'55120', u'28964', u'2736', u'2736', u'6928', u'9922', u'8543', u'8543', u'26468', u'26468', u'987', u'4211', u'4212', u'4212', u'140609', u'140609', u'5087', u'5087', u'5090', u'5090', u'9678', u'23133', u'23133', u'5862', u'5862', u'27316', u'27316', u'55703', u'23328', u'23328', u'9792', u'84193', u'7110', u'7110', u'80700', u'27072', u'65125', u'51741', u'51741', u'3983', u'4301', u'51319', u'51319', u'657', u'84529', u'171425', u'171425', u'1478', u'1478', u'905', u'905', u'3491', u'1848', u'26610', u'26610', u'79767', u'8891', u'8891', u'8667', u'8667', u'11340', u'83989', u'83989', u'63877', u'55137', u'55137', u'93986', u'93986', u'2971', u'2619', u'3172', u'3187', u'3187', u'8339', u'8339', u'3205', u'3217', u'3233', u'3233', u'3397', u'3397', u'3615', u'3615', u'57117', u'57117', u'359948', u'359948', u'3728', u'3728', u'57565', u'57565', u'114818', u'22920', u'22920', u'83938', u'201255', u'54674', u'143098', u'143098', u'145282', u'145282', u'219402', u'219402', u'5607', u'51776', u'124540', u'124540', u'4082', u'4082', u'4756', u'4774', u'340371', u'340371', u'2494', u'2494', u'116039', u'5080', u'5727', u'5727', u'5195', u'5195', u'5144', u'5150', u'144100', u'144100', u'389072', u'389072', u'5339', u'22827', u'22827', u'5033', u'54681', u'54681', u'10196', u'10196', u'5566', u'5566', u'6210', u'6428', u'6428', u'55084', u'55084', u'115286', u'6840', u'6809', u'6809', u'57616', u'6938', u'6934', u'6934', u'6907', u'6907', u'3842', u'3842', u'6902', u'6902', u'7533', u'9039', u'9039', u'9690', u'9690', u'84669', u'84669', u'7444', u'143187', u'9686', u'79971', u'23613', u'84858', u'84858', u'25925', u'23414', u'23414']\n" ] } ], "source": [ "print(UpinPancreas)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We now need to save the list to our intermine account so we can use it again in a later query. The ListManager class provides methods to manage list contents and operations." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lm=service.list_manager()\n", "lm.create_list(content=UpinPancreas, list_type=\"Gene\", name=\"UpinPancreas\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Log in to HumanMine and check your list has been created." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Second query: Diabetes genes \n", "\n", "Our second query (which we created using the query builder) found genes that are associated with the diesease diabetes. Re-create this query using code as follows:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(u'4938', u'OAS1')\n", "(u'208', u'AKT2')\n", "(u'6833', u'ABCC8')\n", "(u'640', u'BLK')\n", "(u'1234', u'CCR5')\n", "(u'54901', u'CDKAL1')\n", "(u'5611', u'DNAJC3')\n", "(u'169792', u'GLIS3')\n", "(u'6927', u'HNF1A')\n", "(u'6928', u'HNF1B')\n", "(u'8462', u'KLF11')\n", "(u'5325', u'PLAGL1')\n", "(u'9882', u'TBC1D4')\n", "(u'346171', u'ZFP57')\n", "(u'26060', u'APPL1')\n", "(u'1636', u'ACE')\n", "(u'359', u'AQP2')\n", "(u'551', u'AVP')\n", "(u'554', u'AVPR2')\n", "(u'11132', u'CAPN10')\n", "(u'1056', u'CEL')\n", "(u'1493', u'CTLA4')\n", "(u'5167', u'ENPP1')\n", "(u'2056', u'EPO')\n", "(u'9451', u'EIF2AK3')\n", "(u'50943', u'FOXP3')\n", "(u'2642', u'GCGR')\n", "(u'2645', u'GCK')\n", "(u'2820', u'GPD2')\n", "(u'3077', u'HFE')\n", "(u'3172', u'HNF4A')\n", "(u'3159', u'HMGA1')\n", "(u'57061', u'HYMAI')\n", "(u'51124', u'IER3IP1')\n", "(u'3710', u'ITPR3')\n", "(u'3630', u'INS')\n", "(u'10644', u'IGF2BP2')\n", "(u'3643', u'INSR')\n", "(u'3667', u'IRS1')\n", "(u'8660', u'IRS2')\n", "(u'3557', u'IL1RN')\n", "(u'3559', u'IL2RA')\n", "(u'3569', u'IL6')\n", "(u'3990', u'LIPC')\n", "(u'4544', u'MTNR1B')\n", "(u'9479', u'MAPK8IP1')\n", "(u'4760', u'NEUROD1')\n", "(u'5078', u'PAX4')\n", "(u'3651', u'PDX1')\n", "(u'5444', u'PON1')\n", "(u'5468', u'PPARG')\n", "(u'3767', u'KCNJ11')\n", "(u'5506', u'PPP1R3A')\n", "(u'5770', u'PTPN1')\n", "(u'26191', u'PTPN22')\n", "(u'56729', u'RETN')\n", "(u'387082', u'SUMO4')\n", "(u'6514', u'SLC2A2')\n", "(u'169026', u'SLC30A8')\n", "(u'6648', u'SOD2')\n", "(u'6934', u'TCF7L2')\n", "(u'7422', u'VEGFA')\n", "(u'7466', u'WFS1')\n", "(u'50982', u'NIDDM3')\n", "(u'100188782', u'NIDDM4')\n" ] } ], "source": [ "query2 = service.new_query(\"Gene\")\n", "query2.add_view(\"primaryIdentifier\", \"symbol\")\n", "query2.add_constraint(\"organism.name\", \"=\", \"Homo sapiens\", code = \"A\")\n", "query2.add_constraint(\"diseases.name\", \"CONTAINS\", \"diabetes\", code = \"B\")\n", "\n", "for row in query2.rows():\n", " print (row[\"primaryIdentifier\"], row[\"symbol\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and save the set of genes returned as a list:" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "diabetesGenes = list()\n", "for row in query2.rows():\n", " diabetesGenes.append(row[\"primaryIdentifier\"])" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lm=service.list_manager()\n", "lm.create_list(content=diabetesGenes, list_type=\"Gene\", name=\"diabetesGenes\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we used a list intersect to find those genes that are upregulated in the pancreas that are also associated with the disease diabetes. We need to intersect the first (UpinPancreas) and second (diabetesGenes) lists that we created. We can do this using the intersect method from the ListManager class." ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lm.intersect([\"UpinPancreas\", \"diabetesGenes\"], \"intersectedList\")" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "intersectedList = lm.get_list(\"intersectedList\")" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "intersectedList (3 Gene) 2019-02-12T11:34:10+0000 Intersection of UpinPancreas and diabetesGenes\n" ] } ], "source": [ "print(intersectedList)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Final Query: GWAS \n", "\n", "Finally, we fed the intersected list from above back into another query to see if there was any association of these genes with diabetes phenotypes according to GWAS studies. Note that we now start our query from the GWAS class:" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "query = service.new_query(\"GWAS\")" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query.add_view(\n", " \"results.associatedGenes.primaryIdentifier\",\n", " \"results.associatedGenes.symbol\", \"results.associatedGenes.name\",\n", " \"results.SNP.primaryIdentifier\", \"results.pValue\", \"results.phenotype\",\n", " \"firstAuthor\", \"name\", \"publication.pubMedId\",\n", " \"results.associatedGenes.organism.shortName\"\n", ")\n" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query.add_constraint(\"results.pValue\", \"<=\", \"1e-04\", code = \"B\")\n", "query.add_constraint(\"results.phenotype\", \"CONTAINS\", \"diabetes\", code = \"C\")\n", "query.add_constraint(\"results.associatedGenes\", \"IN\", \"intersectedList\", code = \"D\")" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(u'3172', u'HNF4A', u'hepatocyte nuclear factor 4 alpha', u'rs6017317', 1e-11, u'Type 2 diabetes', u'Cho YS', u'Type 2 diabetes', u'22158537', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 2e-15, u'Type 2 diabetes', u'Kho AN', u'Type 2 diabetes', u'22101970', u'H. sapiens')\n", "(u'3172', u'HNF4A', u'hepatocyte nuclear factor 4 alpha', u'rs4812829', 3e-10, u'Type 2 diabetes', u'Kooner JS', u'Type 2 diabetes', u'21874001', u'H. sapiens')\n", "(u'6928', u'HNF1B', u'HNF1 homeobox B', u'rs4430796', 2e-11, u'Type 2 diabetes', u'Li H', u'Type 2 diabetes', u'22961080', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 2e-40, u'Type 2 diabetes', u'Perry JR', u'Type 2 diabetes', u'22693455', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 4e-21, u'Type 2 diabetes', u'Perry JR', u'Type 2 diabetes', u'22693455', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 1e-30, u'Type 2 diabetes and other traits', u'Rung', u'Type 2 diabetes and other traits', u'19734900', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 5e-08, u'Type 2 diabetes', u'Salonen', u'Type 2 diabetes', u'17668382', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 2e-31, u'Type 2 diabetes', u'Saxena', u'Type 2 diabetes', u'17463246', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 1e-08, u'Type 2 diabetes', u'Scott', u'Type 2 diabetes', u'17463248', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 2e-34, u'Type 2 diabetes', u'Sladek', u'Type 2 diabetes', u'17293876', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 2e-10, u'Type 2 diabetes', u'Steinthorsdottir', u'Type 2 diabetes', u'17460697', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 8e-12, u'Type 2 diabetes', u'Takeuchi', u'Type 2 diabetes', u'19401414', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 9e-30, u'Type 2 diabetes', u'Timpson', u'Type 2 diabetes', u'19056611', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 6e-16, u'Type 2 diabetes', u'Timpson', u'Type 2 diabetes', u'19056611', u'H. sapiens')\n", "(u'6928', u'HNF1B', u'HNF1 homeobox B', u'rs4430796', 2e-06, u'Type 2 diabetes', u'Voight', u'Type 2 diabetes', u'20581827', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 2e-51, u'Type 2 diabetes', u'Voight', u'Type 2 diabetes', u'20581827', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs4506565', 5e-12, u'Type 2 diabetes', u'WTCCC', u'Type 1 diabetes', u'17554300', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7903146', 3e-23, u'Type 2 diabetes', u'Zeggini', u'Type 2 diabetes', u'18372903', u'H. sapiens')\n", "(u'6934', u'TCF7L2', u'transcription factor 7 like 2', u'rs7901695', 1e-48, u'Type 2 diabetes', u'Zeggini', u'Type 2 diabetes', u'17463249', u'H. sapiens')\n" ] } ], "source": [ "for row in query.rows():\n", " print(row[\"results.associatedGenes.primaryIdentifier\"], row[\"results.associatedGenes.symbol\"], \\\n", " row[\"results.associatedGenes.name\"], row[\"results.SNP.primaryIdentifier\"], \\\n", " row[\"results.pValue\"], row[\"results.phenotype\"], row[\"firstAuthor\"], row[\"name\"], \\\n", " row[\"publication.pubMedId\"], row[\"results.associatedGenes.organism.shortName\"])" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "HNF4A\n", "TCF7L2\n", "HNF4A\n", "HNF1B\n", "TCF7L2\n", "TCF7L2\n", "TCF7L2\n", "TCF7L2\n", "TCF7L2\n", "TCF7L2\n", "TCF7L2\n", "TCF7L2\n", "TCF7L2\n", "TCF7L2\n", "TCF7L2\n", "HNF1B\n", "TCF7L2\n", "TCF7L2\n", "TCF7L2\n", "TCF7L2\n" ] } ], "source": [ "for row in query.rows():\n", " print(row[\"results.associatedGenes.symbol\"])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.14" } }, "nbformat": 4, "nbformat_minor": 2 }