{ "cells": [ { "cell_type": "code", "execution_count": 13, "metadata": { "init_cell": true }, "outputs": [ { "data": { "text/html": [ "\n", "
" ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.display import HTML\n", "HTML('''\n", "
''')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Uploading to SynBioHub\n", "\n", "Using this notebook will allow you to visualize your Excel data and store it in SynBioHub. First, make sure your Excel spreadsheet follows the template provided by the TASBE-Flow Analytics Tutorial: https://github.com/TASBE/TASBEFlowAnalytics-Tutorial/blob/master/batch_template.xlsm\n", "\n", "After downloading the accompanying python code to this notebook, make sure that it is in the same directory as your Excel file. See the README for more detailed instructions." ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "init_cell": true }, "outputs": [], "source": [ "from sbol import *\n", "import re\n", "import sys\n", "import xlrd\n", "from ipywidgets import widgets\n", "import getpass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Select File:\n", "\n", "Select the Excel spreadsheet you want to model." ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "code_folding": [], "init_cell": true }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c67d5b6c5f9649cea44d3f1b93e6ffae", "version_major": 2, "version_minor": 0 }, "text/plain": [ "FileUploadWidget(label='Browse Files', _dom_classes=('widget_item', 'btn-group'))" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1e17df49e5fd4d709bc553b7c4bae39d", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import display, clear_output\n", "import fileupload\n", "\n", "uploader = fileupload.FileUploadWidget()\n", "uploader.label = 'Browse Files'\n", "\n", "output = widgets.Output()\n", "\n", "def _handle_upload(change):\n", " with output:\n", " w = change['owner']\n", " with open(w.filename, 'wb') as f:\n", " f.write(w.data)\n", " clear_output(True)\n", " print('Uploaded `{}` ({:.2f} kB)'.format(\n", " w.filename, len(w.data) / 2**10))\n", "\n", "display(uploader,output)\n", "uploader.observe(_handle_upload, names='data')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Checking File Compatability:\n", "Press the button below to confirm upload:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "code_folding": [], "init_cell": true, "scrolled": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7c354c6083a843bcb2aaa8ec0b4bb3cc", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Button(description='Proceed', style=ButtonStyle())" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "278f39219066421ba1b9d37590f9a677", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from tqdm import tqdm\n", "import time\n", "import os\n", "\n", "ActionButton = widgets.Button(\n", " description = 'Proceed'\n", ")\n", "out = widgets.Output()\n", "def on_button_clicked(_):\n", " with out:\n", " clear_output()\n", " try:\n", " val = str(uploader.data,'utf-8')\n", " except:\n", " val = 1\n", " if val == '':\n", " print(\"You must upload a file first.\")\n", " return\n", " else:\n", " with tqdm(total=1000) as pbar:\n", " file_name = uploader.filename\n", " pbar.set_description(\"Converting \\\"%s\\\" to SBOL...\" % file_name)\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " name,extension = os.path.splitext(file_name)\n", " counter = 0\n", " for i in ['.xlsm','.xlsx','.xltx','.xltm','.xls','.xlm','.xlt']:\n", " if extension == i:\n", " counter = 1\n", " break\n", " if counter != 1:\n", " print('Error: \"%s\" file format is not supported.' % extension)\n", " else: \n", " %run -i 'SBOLconverter.py'\n", " pbar.update(48)\n", " time.sleep(0.1)\n", "\n", " global doc\n", " pbar.update(48)\n", " time.sleep(0.1) \n", " doc = Document()\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " setHomespace('http://bu.edu/dasha') \n", " Config.setOption('sbol_typed_uris',False)\n", " Config.setOption('sbol_compliant_uris',True)\n", " pbar.update(48)\n", " time.sleep(0.1)\n", "\n", " wb = MakeBook(file_name)\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " ExperimentSheetName = 'Experiment DNA sample' #future: allow user to enter sheet name, store it here\n", " ExpSheet = ExpSheetFinder(wb,ExperimentSheetName)\n", " if ExpSheet == -1:\n", " return\n", " pbar.update(40)\n", " time.sleep(0.1)\n", " ExpName = ExpNameFinder(wb)\n", " if ExpName == -1:\n", " return\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " Unit = UnitCollectionFunc(ExpSheet)\n", " if Unit == -1:\n", " return\n", " pbar.update(48)\n", " time.sleep(0.1) \n", " existingNamesDict = LCPDictionaryCaller()\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " (ModList,PlasmidList_orig) = PlasModList(ExpSheet)\n", " if (ModList == -1 and PlasmidList_orig == -1):\n", " return\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " PlasmidList_norepeat = PlasNoRepeat(PlasmidList_orig)\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " newModList = ModListCleaner(ModList,ExpName)\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " ModDefDict = ModMaker(ModList,newModList,ExpSheet,doc)\n", " if ModDefDict == -1:\n", " return\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " SampleSheet = SamplesSheetFinder(wb)\n", " if SampleSheet == -1:\n", " return\n", " (SampleList, SampleDescriptions) = SampleListDesc(SampleSheet)\n", " if SampleList == -1 and SampleDescriptions == -1:\n", " return\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " ConditionDictionary = SampleExpConditions(SampleSheet, SampleList)\n", " if ConditionDictionary == -1:\n", " return\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " ConditionKeyDict = ConditionKeyExtractor(wb)\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " (SampleModDefDict, newSampleList, notInDict) = SampleModMaker(SampleSheet, SampleList, SampleDescriptions, ConditionDictionary, ExpName, existingNamesDict, ConditionKeyDict, doc)\n", " if SampleModDefDict == -1 and newSampleList == -1:\n", " return\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " ret = ModAdder(SampleList, newSampleList, SampleModDefDict, ModList, newModList, ModDefDict, ConditionDictionary)\n", " if ret == -1:\n", " return\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " (CompDefDict,notInDict2) = CompMaker(PlasmidList_norepeat, existingNamesDict, doc)\n", " pbar.update(48)\n", " time.sleep(0.1)\n", " ret = FuncMaker(ModList, newModList, ModDefDict, CompDefDict, ExpSheet, Unit, doc)\n", " pbar.update(48)\n", " time.sleep(0.1)\n", "\n", " if notInDict != [] or notInDict2 != []:\n", " print('Warning:')\n", " for val in notInDict:\n", " print('%s not found in the LCP Project Dictionary.' % val)\n", " for val in notInDict2:\n", " print('%s not found in the LCP Project Dictionary.' % val)\n", " print('\\nYou may continue but it is highly recommended that the terms be added first. \\n')\n", " \n", " print('Success!')\n", "\n", "display(ActionButton,out)\n", "ActionButton.on_click(on_button_clicked) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Enter Project Details:\n", "Enter the **displayID** (REQUIRED, alphanumeric and underscore characters only, cannot begin with a digit), **project name** (optional, if you want to elaborate on the displayID), **project description**, and **version** (REQUIRED for the collection URI) of the Project you want to upload to. If it already exists, entering only the displayID and version is sufficient." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 17, "metadata": { "init_cell": true }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "40a94a09588a4e40b6d89152179a35bd", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Text(value='', description='displayID'), Text(value='', description='name'), Textarea(value='',…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "displaywidget = widgets.Text(\n", " value='',\n", " description = 'displayID'\n", ")\n", "namewidget = widgets.Text(\n", " value='',\n", " description = 'name'\n", ")\n", "descriptionwidget = widgets.Textarea(\n", " value='',\n", " description = 'description'\n", ")\n", "versionwidget = widgets.Text(\n", " description = 'version',\n", " placeholder = 'for example 1.0.0 or 1'\n", ")\n", "collectionbox = widgets.VBox([displaywidget,namewidget,descriptionwidget,versionwidget])\n", "collectionbox\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Enter Experiment Details:\n", "Enter the **displayID** (REQUIRED, alphanumeric and underscore characters only, cannot begin with a digit), **experiment name** (optional, if you want to elaborate on the displayID), and the **experiment description** of the new Experiment you will be uploading." ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "init_cell": true }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "59c4afca11df44729fcb161bda49511a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Text(value='', description='displayID'), Text(value='', description='name'), Textarea(value='',…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "subIDwidget = widgets.Text(\n", " value='',\n", " description = 'displayID'\n", ")\n", "subcolnamewidget = widgets.Text(\n", " value='',\n", " description = 'name'\n", ")\n", "subdescriptionwidget = widgets.Textarea(\n", " value='',\n", " description = 'description'\n", ")\n", "\n", "subcollectionbox = widgets.VBox([subIDwidget,subcolnamewidget,subdescriptionwidget])\n", "subcollectionbox\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Enter Login Information:\n", "Enter your **username** and **password** for the SynBioHub account you want to upload your collection to." ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "init_cell": true, "scrolled": true }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "dd8eedc990f74cbf8c12cc68c8cf84dc", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Text(value='', description='Username:', placeholder=''), Password(description='Password:'), But…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "usernamewidget = widgets.Text(\n", " value='',\n", " placeholder='',\n", " description='Username:',\n", " disabled=False\n", ")\n", "loginButton = widgets.Button(\n", " description = 'Login'\n", ")\n", "#^if in the future login comes before actual upload\n", "# uploadButton = widgets.Button(\n", "# description = 'Upload to SynBioHub'\n", "# )\n", "\n", "passwordwidget = widgets.Password(\n", " description = 'Password:'\n", ")\n", "\n", "# yesButton = widgets.Button(\n", "# description = 'Yes'\n", "# )\n", "\n", "# noButton = widgets.Button(\n", "# description = 'No'\n", "# )\n", "\n", "# YesNoBox = widgets.HBox([yesButton, noButton])\n", "\n", "# def YesButtonClicked(_):\n", "# formatlist = [displaywidget.value,subIDwidget.value]\n", "# print('Creating a new project with displayID \"{}\" containing an experiment with displayID \"{}\".'.format(*formatlist))\n", "# doc.displayId = displaywidget.value\n", "# doc.name = namewidget.value\n", "# doc.description = descriptionwidget.value\n", "# doc.version = versionwidget.value\n", "# NewProjUpload(usernamewidget.value,passwordwidget.value,doc)\n", "# sep = '@'\n", "# text = usernamewidget.value \n", "# rest = text.split(sep, 1)[0]\n", "# rootcolURI = \"https://synbiohub.org/user/\" + rest + \"/\" + displaywidget.value + \"/\" + displaywidget.value + \"_collection/\" + versionwidget.value\n", "# print(rootcolURI)\n", "# return\n", " \n", "# def NoButtonClicked(_):\n", "# print('Upload stopped.')\n", "# return\n", "\n", "# out = widgets.Output()\n", "\n", "def on_button_clicked(_):\n", " if (usernamewidget.value == '') or (passwordwidget.value == ''):\n", " print('You must enter your username and password.')\n", " return\n", " sbh = LoginFunc(usernamewidget.value,passwordwidget.value)\n", " print('Login successful')\n", " return\n", "\n", "sbh = loginButton.on_click(on_button_clicked)\n", "box = widgets.VBox([usernamewidget,passwordwidget,loginButton])\n", "box\n", "\n" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "init_cell": true }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8c7333529aa54f729b91755258bc1b08", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Button(description='Upload to SynBioHub', style=ButtonStyle())" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "uploadButton = widgets.Button(\n", " description = 'Upload to SynBioHub'\n", ")\n", "yesButton = widgets.Button(\n", " description = 'Yes'\n", ")\n", "\n", "noButton = widgets.Button(\n", " description = 'No'\n", ")\n", "\n", "YesNoBox = widgets.HBox([yesButton, noButton])\n", "\n", "def YesButtonClicked(_):\n", " formatlist = [displaywidget.value,subIDwidget.value]\n", " print('Creating a new project with displayID \"{}\" containing an experiment with displayID \"{}\".'.format(*formatlist))\n", " doc.displayId = displaywidget.value\n", " doc.name = namewidget.value\n", " doc.description = descriptionwidget.value\n", " doc.version = versionwidget.value\n", " NewProjUpload(usernamewidget.value,passwordwidget.value,doc)\n", " sep = '@'\n", " text = usernamewidget.value \n", " rest = text.split(sep, 1)[0]\n", " rootcolURI = \"https://synbiohub.org/user/\" + rest + \"/\" + displaywidget.value + \"/\" + displaywidget.value + \"_collection/\" + versionwidget.value\n", " print(rootcolURI)\n", " return\n", " \n", "def NoButtonClicked(_):\n", " print('Upload stopped.')\n", " return\n", "\n", "out = widgets.Output()\n", "\n", "def on_uploadbutton_clicked(_):\n", " sep = '@'\n", " text = usernamewidget.value \n", " rest = text.split(sep, 1)[0]\n", " rootcolURI = \"https://synbiohub.org/user/\" + rest + \"/\" + displaywidget.value + \"/\" + displaywidget.value + \"_collection/\" + versionwidget.value\n", " sbh = LoginFunc(usernamewidget.value,passwordwidget.value)\n", " ret = UploadFunc(sbh,subIDwidget.value,subcolnamewidget.value,subdescriptionwidget.value,displaywidget.value,namewidget.value,descriptionwidget.value,versionwidget.value,rootcolURI,doc)\n", " if ret == 1:\n", " print('test')\n", " print('No project with the displayID \"{}\" found.'.format(displaywidget.value))\n", " print('Do you want to create a new project with this displayID?')\n", " yesButton.on_click(YesButtonClicked)\n", " noButton.on_click(NoButtonClicked)\n", " display(YesNoBox)\n", " elif ret == 2:\n", " print(rootcolURI)\n", " return\n", " else:\n", " return\n", "\n", "uploadButton.on_click(on_uploadbutton_clicked)\n", "uploadButton\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "celltoolbar": "Initialization Cell", "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.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }