From e9909efbb7f96339a8f2d4e510e4893bf3ab257a Mon Sep 17 00:00:00 2001 From: Jonathan Karr Date: Tue, 3 Mar 2020 13:41:42 -0500 Subject: [PATCH] renaming extended tutorial and adding intro tutorial --- examples/1. Introductory tutorial.ipynb | 423 ++++++++++++++++++ ...orial.ipynb => 2. Extended tutorial.ipynb} | 0 2 files changed, 423 insertions(+) create mode 100644 examples/1. Introductory tutorial.ipynb rename examples/{Tutorial.ipynb => 2. Extended tutorial.ipynb} (100%) diff --git a/examples/1. Introductory tutorial.ipynb b/examples/1. Introductory tutorial.ipynb new file mode 100644 index 0000000..d0f4c13 --- /dev/null +++ b/examples/1. Introductory tutorial.ipynb @@ -0,0 +1,423 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`BcForms` is a toolkit for concretely describing the primary structure of macromolecular complexes, including non-canonical monomeric forms and intra and inter-subunit crosslinks. `BcForms` includes a textual grammar for describing complexes and a Python library, a command line program, and a REST API for validating and manipulating complexes described in this grammar. `BcForms` represents complexes as sets of subunits, with their stoichiometries, and covalent crosslinks which link the subunits. DNA, RNA, and protein subunits can be represented using `BpForms`. Small molecule subunits can be represented using `openbabel.OBMol`, typically imported from SMILES or InChI." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This notebook illustrates how to use the `BcForms` Python library via some simple. Please see the second tutorial for more details and more examples. Please also see the [documentation](https://docs.karrlab.org/bcforms/) for more information about the `BcForms` grammar and more instructions for using the `BcForms` website, JSON REST API, and command line interface." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Import BpForms and BcForms libraries" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import bcforms\n", + "import bpforms" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Create complexes from their string representations" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "form_1 = bcforms.BcForm().from_str('2 * subunit_a + 3 * subunit_b')\n", + "form_1.set_subunit_attribute('subunit_a', 'structure',\n", + " bpforms.ProteinForm().from_str('CAAAAAAAA'))\n", + "form_1.set_subunit_attribute('subunit_b', 'structure',\n", + " bpforms.ProteinForm().from_str('AAAAAAAAC'))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "form_2 = bcforms.BcForm().from_str(\n", + " '2 * subunit_a'\n", + " '| x-link: [type: disulfide | l: subunit_a(1)-1 | r: subunit_a(2)-1]')\n", + "form_2.set_subunit_attribute('subunit_a', 'structure',\n", + " bpforms.ProteinForm().from_str('CAAAAAAAA'))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Create complexes programmatically" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "form_1_b = bcforms.BcForm()\n", + "form_1_b.subunits.append(bcforms.core.Subunit('subunit_a', 2,\n", + " bpforms.ProteinForm().from_str('CAAAAAAAA')))\n", + "form_1_b.subunits.append(bcforms.core.Subunit('subunit_b', 3,\n", + " bpforms.ProteinForm().from_str('AAAAAAAAC')))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "form_2_b = bcforms.BcForm()\n", + "subunit = bcforms.core.Subunit('subunit_a', 2,\n", + " bpforms.ProteinForm().from_str('CAAAAAAAA'))\n", + "form_2_b.subunits.append(subunit)\n", + "form_2_b.crosslinks.append(bcforms.core.OntologyCrosslink(\n", + " 'disulfide', 'subunit_a', 1, 'subunit_a', 1, 1, 2))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Get properties of polymers" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Subunits" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[,\n", + " ]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "form_1.subunits" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Crosslinks" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "form_2.crosslinks " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Get the string representation of a complex" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'2 * subunit_a + 3 * subunit_b'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "str(form_1_b) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Check equality of complexes" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "form_1_b.is_equal(form_1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Calculate properties of a complex" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Molecular structure" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + " >" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "form_1.get_structure()[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## SMILES representation" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'C(=O)([C@@H]([NH3+])CS)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)O.C(=O)([C@@H]([NH3+])CS)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)O.C[C@H]([NH3+])C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@H](C(=O)O)CS.C[C@H]([NH3+])C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@H](C(=O)O)CS.C[C@H]([NH3+])C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@@H](C)C(=O)N[C@H](C(=O)O)CS'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "form_1.export('smiles') " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Formula" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "AttrDefault(, False, {'C': 135.0, 'H': 240.0, 'N': 45.0, 'O': 50.0, 'S': 5.0})" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "form_1.get_formula()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Charge" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "form_1.get_charge()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Molecular weight" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3453.9699999999993" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "form_1.get_mol_wt()" + ] + } + ], + "metadata": { + "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.6" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/examples/Tutorial.ipynb b/examples/2. Extended tutorial.ipynb similarity index 100% rename from examples/Tutorial.ipynb rename to examples/2. Extended tutorial.ipynb