diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..70755a0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*.pyc +__pycache__ +*.egg-info +build/* +dist/* +doc/_build + +.ipynb_checkpoints diff --git a/CHANGES.md b/CHANGES.md new file mode 100644 index 0000000..57669a5 --- /dev/null +++ b/CHANGES.md @@ -0,0 +1,55 @@ +# CHANGES proposed to PythonCyc 1.0 +# Rodrigo Santibáñez @ Network Biology Lab (NBL), Universidad Mayor, 2019 + +# Beware that there is a number of functions that works in the +# pathway tools lisp interpreter (ptlisp), but no from the python interface. +# For those functions, the API prints the query to the standard output. + +Section 5 API functions +- Section 5.1 enumeration functions +* The documentation of the function all-rxns has the argument type that could be set to non-spontaneous. However, the valid cases are :ALL, :PROTEIN-SMALL-MOLECULE-REACTION, :PROTEIN-REACTION, :TRNA-REACTION, :SPONTANEOUS, :SPONTANEOUS-HT, :ENZYME, :ENZYME-HT, :SMALL-MOLECULE, :SMALL-MOLECULE-HT, :METAB-PATHWAYS, :ALL-RXNS-METAB-PATHWAYS-WITH-DUPLICATES-HT, :METAB-SMM, :SMM, :METAB-SMM-HT, :METAB-COMPLETE-SMM, :METAB-ALL, :TRANSPORT-HT, :TRANSPORT, and :ENZYME-NOT-IN-PWY. The docstring was updated with the valid cases (but not their descriptions). +* The documentation of the function all_transported_chemicals has a valid argument show_compartment. However, the pythoncyc API doesn't include the argument. Added the keyword to PGDB.py, line 787. Tested in pathway tools lisp interpreter with (with-organism (:org-id '|ECOLI|) (all-transported-chemicals :primary-only? nil :show-compartment 'CCO-CYTOSOL )) returning a list of instances and classes, but I doubt if I give a valid show-compartment keyword. + +- Section 5.1.1 operations on reactions +* The documentation of the function enzymes_of_reaction has the arguments experimental-only? and local-only-p. However, the pythoncyc API has close similar experimental_only and local_only arguments. To be consistent with documentation, I changed the local_only argument to local_only_p. +* The documentation has the description for the rxn-without-sequenced-enzyme-p function, but the lisp function is reaction-without-sequenced-enzyme-p. Moreover, the describe function says reaction-without-sequenced-enzyme-p doesn't recognize the argument complete?. I tested in the lisp interpreter with (with-organism (:org-id '|ECOLI|) (reaction-without-sequenced-enzyme-p '|RXN-15348| )) returning T. However when I run the code in python, it fails with An internal error occurred in the running Pathway Tools application: :error, The function 'REACTION-WITHOUT-SEQUENCED-ENZYME-P' is not allowed to be called in restricted mode. +* The function pathway-hole-p don't have the argument hole-if-any-gene-without-position? as tested with the describe function in the lisp interpreter. I deleted the argument from the API. +* The function rxn-present? is incorrectly queried as rxn-present-p. Tested with (with-organism (:org-id '|ECOLI|) (rxn-present? '|RXN-15348| )) returning T. Moreover, the lisp function has the INCLUDE-SPONTANEOUS? argument absent from the documentation and from the API: (with-organism (:org-id '|ECOLI|) (rxn-present? '|RXN-15348| :INCLUDE-SPONTANEOUS )) returns T, but fails if (with-organism (:org-id '|ECOLI|) (rxn-present? '|RXN-15348| :INCLUDE-SPONTANEOUS? T )). I don't know (yet) how to add the argument to the code. +* The documentation describes the function compartment-of-rxn but it isn't a function or wasn't defined as a function. Tested with (describe 'compartment-of-rxn). + +- Section 5.1.2 Operations on pathways +* sorted argument of functions genes_of_pathway and enzymes_of_pathway now works. Probably it should be renamed because of a clash with the python sorted function. + +- Section 5.1.3 Operations on Enzymatic Reactions +* er argument of functions enzrxn_activators and enzrxn_inhibitors was changed to enzrxn for consistency with other functions. +* function pathway-allows-enzrxn is implemented in ptools as pathway-allows-enzrxn?, but gives the following error: function 'PATHWAY-ALLOWS-ENZRXN?' is not allowed to be called in restricted mode + +- Section 5.1.4 Operations on Proteins. +* p argument of functions monomers_of_protein and base_components_of_protein changed to protein for consistency with other functions +* functions reduce_modified_proteins and genes_of_proteins always require a list of proteins, even if the list has only one element. I added a check to make sure the functions work even if the user mistakenly gives a single frameid. +* the argument INCLUDE-SUBREACTIONS? from function reactions-of-enzyme is undocumented. I included it in the pythoncyc API. I don't know how to use the kb argument of the function +* incomplete documentation for enzyme_p; argument type admits non-transport-non-pathway and the argument was renamed to type_of_reactions because of clash with python type function +* LEADER-PEPTIDE-P is implemented as LEADER-PEPTIDE?. Changes don't work similarly to pathway-allows-enzrxn?. +* argument compartments is mandatory but it wasn't present in function protein_in_compartment_p. Added to the function and works correctly. +* problem: (with-organism (:org-id '|ECOLI|) (all-transporters-across :membranes '|CCO-MEMBRANE| )) returns NIL when it should be equivalent to (with-organism (:org-id '|ECOLI|) (all-transporters-across :membranes :all )), according to the documentation + +- Section 5.1.5 Operations on Genes. +* item argument on function gene_p changed to gene for consistency with ther function +* INCLUDE-GENE-PROD-AS-SUBSTRATE? argument of function pathways-of-gene is undocumented and not present in pythoncyc API and it was added. As well, argument INCLUDE-SUPER-PWYS? is now correctly interpreted. +* documentation has the function connecting-genes but isn't present in ptools. Tested with (apropos "connecting") +* documentation states that argument max-gap of functions gene-clusters and neighboring-genes-p is optional, but the API set it to None. Changed to 10 to match the documentation. +* adjacent_genes_p and neighboring_genes_p functions check if the two genes are the same, returning None if they are "adjacent" or "neighbors" +* rna_coding_gene is implemented as rna_coding_gene?. Changed and tested with (with-organism (:org-id '|ECOLI|) (rna-coding-gene? '|EG11414| )) but pythoncyc fails similarly to pathway-allows-enzrxn? + +- Section 5.1.6 Operations on Regulatory Frames +* transcription_factor_p is implemented as transcription-factor? and regulator_of_type as regulator_of_type?. Both work correctly in the lisp interpreter but pythoncyc fails similarly as pathway-allows-enzrxn? +* regulators_of_operon_transcription function accept only lists, similarly to reduce_modified_proteins, also modified in the same way to ensure the function receives a list even if the user gives a single frameid. +* problem: I don't know how to use the mode argument in transcription_factor_ligands function, therefore I don't know if the function works or not. + +- Section 5.1.7 Operations on Compounds +* substrate-of-generic-rxn is implemented as substrate-of-generic-rxn?, works in the interpreter but not from pythoncyc. +* documentation defines the function activated-or-inhibited-by-compound, but pythoncyc has the deactivated-or-inhibited-by-compound. I modified the function but raises the error function is not allowed to be called in restricted mode, but works in the lisp interpreter. I'm out of ideas for the reason of this recurrent error. + +- Section 5.1.8 Object Name Manipulation Operations +* get-name-string fails and working on it +* full_enzyme_name optional arguments were included in the function, been the reason of failure. Changed to kwargs and working diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..6311329 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include examples/*ipynb diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f34f1c2 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +build-package: + rm -rf build + rm -rf PythonCyc.egg-info + rm -rf __pycache__ + python3 setup.py bdist_wheel sdist + +clean-package: + python3 setup.py clean + +install-package: + python3 setup.py clean build install diff --git a/README.md b/README.md index 6cca8fc..56f887b 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,19 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +PythonCyc 2.0, January 2020 +=========================== + +Overview +-------- + +An updated version of the original PythonCyc API from Mario Latendresse. + +This module has been tested under Python 3.6 and Python 3.8, with examples +at https://github.com/networkbiolab/PythonCyc/tree/master/examples + +Disclaimer: a number of functions remains broken. + PythonCyc 1.0, November 2014 ============================ @@ -49,13 +62,13 @@ Documentation tutorial.html under the doc directory of this package, or go directly to the tutorial by clicking the following link https://github.com/latendre/PythonCyc/blob/master/doc/tutorial.md -2) For the API documentation of PythonCyc, please consult http://pythoncyc.readthedocs.org. +2) For the API documentation of PythonCyc, please consult http://pythoncyc.readthedocs.org. 3) For the latest news about PythonCyc, please consult http://bioinformatics.ai.sri.com/ptools/pythoncyc.html Author ------- +------ Mario Latendresse, latendre@AI.SRI.COM diff --git a/examples/Operations_on_Compounds.ipynb b/examples/Operations_on_Compounds.ipynb new file mode 100644 index 0000000..d4ffabc --- /dev/null +++ b/examples/Operations_on_Compounds.ipynb @@ -0,0 +1,272 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# to run the script, you need to start pathway tools form the command line \n", + "# using the -lisp -python options. Example (from the pathway tools github repository)\n", + "\n", + "import os\n", + "# os.system('nohup /opt/pathway-tools/pathway-tools -lisp -python &')\n", + "os.system('nohup pathway-tools -lisp -python-local-only &') # added cybersecurity" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# modify sys.path to recognize local pythoncyc\n", + "import sys\n", + "\n", + "module_path = os.path.abspath(os.path.join('../'))\n", + "sys.path = [module_path]\n", + "\n", + "# sys.path" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|META|', '|ECOLI|']\n" + ] + } + ], + "source": [ + "import pythoncyc\n", + "all_orgids = pythoncyc.all_orgids()\n", + "print(all_orgids)\n", + "\n", + "meta = pythoncyc.select_organism(u'|META|')\n", + "ecoli = pythoncyc.select_organism(u'|ECOLI|')\n", + "\n", + "compounds = [x.frameid for x in ecoli.compounds.instances][0:2]\n", + "reactions = [x.frameid for x in ecoli.reactions.instances][0:2]\n", + "enzymes = ecoli.all_enzymes(type_of_reactions = ':chemical-change')[0:2]" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|RXN0-5298|'], ['|RXN0-1922|']]\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "cpd\n", + "A child of class |Compounds|. \n", + "non-specific-too?\n", + "Keyword, Optional If non-nil, returns all generic reactions where cpd, or a \n", + "parent of cpd, appears as a substrate. \n", + "transport-only?\n", + "Keyword, Optional If non-nil, return only transport reactions. \n", + "compartment\n", + "Keyword, Optional If non-nil, return only reactions within the specified \n", + "compartment. \n", + "enzymatic?\n", + "Keyword, Optional If non-nil, return only enzymatic reactions. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for compound in compounds:\n", + " lst.append(ecoli.reactions_of_compound(compound, enzymatic = True))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "try:\n", + " lst = []\n", + " for compound in compounds:\n", + " for reaction in reactions:\n", + " lst.append(ecoli.substrate_of_generic_rxn(compound, reaction))\n", + " print(lst[-10:])\n", + "except:\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|FUCCAT-PWY|', '|FUC-RHAMCAT-PWY|'], []]\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "cpd\n", + "An instance of class |Compounds|. \n", + "non-specific-too?\n", + "Keyword, Optional If non-nil, returns all generic reactions where cpd, or a \n", + "parent of cpd, appears as a substrate. \n", + "modulators?\n", + "Keyword, Optional If non-nil, returns pathways where cpd appears as a regulator \n", + "as well. \n", + "phys-relevant?\n", + "Keyword, Optional If true, then only return inhibitors that are associated with \n", + "|Regulation| instances that have the 'physiologically‑relevant? slot set to \n", + "non-nil. \n", + "include-rxns?\n", + "Keyword, Optional If non-nil, then return a list of reaction-pathway pairs. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for compound in compounds:\n", + " lst.append(ecoli.pathways_of_compound(compound))#, modulators = True, include_rxns = True))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "cpds\n", + "An instance or list of instances of class |Compounds|. \n", + "mode\n", + "Keyword, Optional Represents the type of regulation. Can take on the values of \n", + "“+”, “-”, or 'nil. \n", + "mechanisms\n", + "Keyword, Optional Keywords from the 'mechanism slot of the corresponding \n", + "sub-class of the class |Regulation|. If non-nil, only regulation objects with \n", + "mechanisms in this list will be explored for regulated objects. \n", + "phys-relevant?\n", + "Keyword, Optional If true, then only return inhibitors that are associated with \n", + "|Regulation| instances that have the 'physiologically‑relevant? slot set to \n", + "non-nil. \n", + "slots\n", + "Keyword A list of enzymatic reaction slots to \n", + "\"\"\"\n", + "\n", + "try:\n", + " lst = []\n", + " for compound in compounds:\n", + " lst.append(ecoli.activated_or_inhibited_by_compound(compound))\n", + " print(lst[-10:])\n", + "except:\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for compound in compounds:\n", + " lst.append(ecoli.tfs_bound_to_compound(compound, include_inactive = True))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['dsbd-rxn', 'rxn0-4342']\n", + "['4-hydroxy-2-oxovalerate aldolase', 'L,D-transpeptidase YcfS']\n" + ] + } + ], + "source": [ + "# Object Name Manipulation Operations\n", + "# lst = []\n", + "# for reaction in reactions:\n", + "# lst.append(ecoli.get_name_string(reaction))\n", + "# print lst[-10:]\n", + "# print ''\n", + "\n", + "lst = []\n", + "for reaction in reactions:\n", + " lst.append(ecoli.full_enzyme_name(reaction))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for enzyme in enzymes:\n", + " lst.append(ecoli.enzyme_activity_name(enzyme))\n", + "print(lst[-10:])" + ] + }, + { + "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": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/Operations_on_Enzymatic-Reactions.ipynb b/examples/Operations_on_Enzymatic-Reactions.ipynb new file mode 100644 index 0000000..9b91921 --- /dev/null +++ b/examples/Operations_on_Enzymatic-Reactions.ipynb @@ -0,0 +1,251 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# to run the script, you need to start pathway tools form the command line \n", + "# using the -lisp -python options. Example (from the pathway tools github repository)\n", + "\n", + "import os\n", + "# os.system('nohup /opt/pathway-tools/pathway-tools -lisp -python &')\n", + "os.system('nohup pathway-tools -lisp -python-local-only &') # added cybersecurity" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# modify sys.path to recognize local pythoncyc\n", + "import sys\n", + "\n", + "module_path = os.path.abspath(os.path.join('../'))\n", + "sys.path = [module_path]\n", + "\n", + "# sys.path" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|META|', '|ECOLI|']\n" + ] + } + ], + "source": [ + "import pythoncyc\n", + "all_orgids = pythoncyc.all_orgids()\n", + "print(all_orgids)\n", + "\n", + "meta = pythoncyc.select_organism(u'|META|')\n", + "ecoli = pythoncyc.select_organism(u'|ECOLI|')" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[], [], [], [], [], [], [], [], [], []]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst = []\n", + "for enzrxn in ecoli.all_rxns(type_of_reactions = 'all'):\n", + " lst.append(ecoli.cofactors_and_pgroups_of_enzrxn(enzrxn = enzrxn))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[], [], [], [], [], [], [], [], [], []]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "er\n", + "An instance of the class |Enzymatic‑Reactions|. \n", + "phys-relevant-only?\n", + "Optional If true, then only return activators that are associated with \n", + "|Regulation| instances that have the 'physiologically‑relevant? slot set to \n", + "non-nil. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for enzrxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.enzrxn_activators(enzrxn = enzrxn, phys_relevant_only=True))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[], [], [], [], [], [], [], [], [], []]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst = []\n", + "for enzrxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.enzrxn_inhibitors(enzrxn = enzrxn, phys_relevant_only = True))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[], [], [], [], [], [], [], [], [], []]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "enzrxn\n", + "An instance of the class |Enzymatic‑Reactions|. \n", + "include-super-pwys?\n", + "Keyword, Optional If non-nil, then not only will the direct pathways in which \n", + "enzrxn is associated in be returned, but also any enclosing super-pathways. If \n", + "enzrxn is associated with a reaction that is directly associated with a \n", + "super-pathway, then the function might return super-pathways even if this option \n", + "is nil.\n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for enzrxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.pathways_of_enzrxn(enzrxn = enzrxn, include_super_pwys = False))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "ename": "PToolsError", + "evalue": "An internal error occurred in the running Pathway Tools application: :error, The function 'PATHWAY-ALLOWS-ENZRXN?' is not allowed to be called in restricted mode.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mPToolsError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mrxn2\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mecoli\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mall_rxns\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype_of_reactions\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'metab-smm'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 18\u001b[0m lst.append([rxn1, rxn2, ecoli.pathway_allows_enzrxn(\n\u001b[0;32m---> 19\u001b[0;31m pwy = pwy, rxn = rxn1, enzrxn = rxn2, single_species = u'|ECOLI|')])\n\u001b[0m\u001b[1;32m 20\u001b[0m \u001b[0mlst\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/shared/D1/opt/repositories/git-reps/PythonCyc.networkbiolab/pythoncyc/PGDB.py\u001b[0m in \u001b[0;36mpathway_allows_enzrxn\u001b[0;34m(self, pwy, rxn, enzrxn, single_species)\u001b[0m\n\u001b[1;32m 1644\u001b[0m \u001b[0;31m# single_species is optional for the Lisp version.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1645\u001b[0m \u001b[0;31m# TODO\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1646\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msendPgdbFnCallBool\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'pathway-allows-enzrxn?'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmay_be_frameid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpwy\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmay_be_frameid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrxn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmay_be_frameid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0menzrxn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msingle_species\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1647\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1648\u001b[0m \u001b[0;31m# Section 5.1.4 Operations on Proteins\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/shared/D1/opt/repositories/git-reps/PythonCyc.networkbiolab/pythoncyc/PGDB.py\u001b[0m in \u001b[0;36msendPgdbFnCallBool\u001b[0;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[1;32m 377\u001b[0m \u001b[0mThis\u001b[0m \u001b[0mmethod\u001b[0m \u001b[0mtakes\u001b[0m \u001b[0mcare\u001b[0m \u001b[0mof\u001b[0m \u001b[0mtranslating\u001b[0m \u001b[0mno\u001b[0m \u001b[0mvalue\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0man\u001b[0m \u001b[0mempty\u001b[0m \u001b[0mlist\u001b[0m \u001b[0mto\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 378\u001b[0m \t\t\"\"\"\n\u001b[0;32m--> 379\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msendPgdbFnCall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 380\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 381\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/shared/D1/opt/repositories/git-reps/PythonCyc.networkbiolab/pythoncyc/PGDB.py\u001b[0m in \u001b[0;36msendPgdbFnCall\u001b[0;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[1;32m 370\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 371\u001b[0m \u001b[0mfnCall\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mprepareFnCall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 372\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msendPgdbQuery\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfnCall\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 373\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 374\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0msendPgdbFnCallBool\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/shared/D1/opt/repositories/git-reps/PythonCyc.networkbiolab/pythoncyc/PGDB.py\u001b[0m in \u001b[0;36msendPgdbQuery\u001b[0;34m(self, query)\u001b[0m\n\u001b[1;32m 359\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mpythoncyc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconfig\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_debug\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 360\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlisp_query\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 361\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mPTools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msendQueryToPTools\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlisp_query\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 362\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 363\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0msendPgdbFnCall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/shared/D1/opt/repositories/git-reps/PythonCyc.networkbiolab/pythoncyc/PTools.py\u001b[0m in \u001b[0;36msendQueryToPTools\u001b[0;34m(query)\u001b[0m\n\u001b[1;32m 195\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 196\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mmsg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstartswith\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m':error'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 197\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mPToolsError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'An internal error occurred in the running Pathway Tools application: {:s}'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 198\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 199\u001b[0m \u001b[0;31m# Return some result.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mPToolsError\u001b[0m: An internal error occurred in the running Pathway Tools application: :error, The function 'PATHWAY-ALLOWS-ENZRXN?' is not allowed to be called in restricted mode." + ] + } + ], + "source": [ + "\"\"\"\n", + "pwy\n", + "An instance of the class |Pathways|. \n", + "rxn\n", + "An instance of the class |Reactions|. \n", + "enzrxn\n", + "An instance of the class |Enzymatic‑Reactions|. \n", + "single-species\n", + "Optional An instance of the class |Organisms| If set, then enzrxn has the \n", + "further stricture that it must be an enzymatic reaction present in the organism \n", + "specified by the value passed to single‑species.\n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for pwy in ecoli.all_pathways(selector = ':all', base = True):\n", + " for rxn1 in ecoli.all_rxns(type_of_reactions = 'all'):\n", + " for rxn2 in ecoli.all_rxns(type_of_reactions = 'metab-smm'):\n", + " lst.append([rxn1, rxn2, ecoli.pathway_allows_enzrxn(\n", + " pwy = pwy, rxn = rxn1, enzrxn = rxn2, single_species = u'|ECOLI|')])\n", + "lst[-10:]" + ] + }, + { + "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": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/Operations_on_Genes.ipynb b/examples/Operations_on_Genes.ipynb new file mode 100644 index 0000000..418c220 --- /dev/null +++ b/examples/Operations_on_Genes.ipynb @@ -0,0 +1,591 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# to run the script, you need to start pathway tools form the command line \n", + "# using the -lisp -python options. Example (from the pathway tools github repository)\n", + "\n", + "import os\n", + "# os.system('nohup /opt/pathway-tools/pathway-tools -lisp -python &')\n", + "os.system('nohup pathway-tools -lisp -python-local-only &') # added cybersecurity" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# modify sys.path to recognize local pythoncyc\n", + "import sys\n", + "\n", + "module_path = os.path.abspath(os.path.join('../'))\n", + "sys.path = [module_path]\n", + "\n", + "# sys.path" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|META|', '|ECOLI|']\n" + ] + } + ], + "source": [ + "import pythoncyc\n", + "all_orgids = pythoncyc.all_orgids()\n", + "print(all_orgids)\n", + "\n", + "meta = pythoncyc.select_organism(u'|META|')\n", + "ecoli = pythoncyc.select_organism(u'|ECOLI|')\n", + "genes = [x.frameid for x in ecoli.genes.instances][0:2]" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|Genes|', '|Genes|']\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.gene_p(gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.enzymes_of_gene(gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|EG11414-MONOMER|', '|CPLX0-7910|', '|CPLX0-3803|'], ['|EG11127-MONOMER|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.all_products_of_gene(gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.reactions_of_gene(gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.pathways_of_gene(gene, True, True))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|COLI-K12|', '|COLI-K12|']\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.chromosome_of_gene(gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|EG11414-MONOMER|', '|EG11127-MONOMER|']\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.unmodified_gene_product(gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|EG11414-MONOMER|'], ['|EG11127-MONOMER|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.unmodified_gene_products(gene = gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|EG10850|', '|EG11024|']\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.next_gene_on_replicon(gene = gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|G7950|', '|EG11126|']\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.previous_gene_on_replicon(gene = gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "both queries are the same.\n", + "both queries are the same.\n", + "[None, False, False, None]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene1 in genes:\n", + " for gene2 in genes:\n", + " lst.append(ecoli.adjacent_genes_p(gene1, gene2))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "both queries are the same.\n", + "both queries are the same.\n", + "[None, False, False, None]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene1 in genes:\n", + " for gene2 in genes:\n", + " lst.append(ecoli.neighboring_genes_p(gene1, gene2))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'|EG11127|': ['|EG11414|']}" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ecoli.gene_clusters(genes, 4000)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "try:\n", + " lst = []\n", + " for gene in genes:\n", + " lst.append(ecoli.rna_coding_gene(gene=gene))\n", + " print(lst[-10:])\n", + "except:\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "try:\n", + " lst = []\n", + " for gene in genes:\n", + " lst.append(ecoli.protein_coding_gene(gene=gene))\n", + " print(lst[-10:])\n", + "except:\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[False, False]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.pseudo_gene_p(gene=gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[False, False]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.phantom_gene_p(gene=gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[False, False]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.dna_binding_site_p(gene=gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[False, False]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.terminator_p(gene=gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|TU0-14216|'], ['|TU0-36408|', '|TU0-36411|', '|TU0-13193|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.operon_of_gene(gene=gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|EG12115|', '|EG10850|', '|EG11414|'], ['|EG11125|', '|EG11126|', '|EG11127|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.genes_in_same_operon(gene=gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|TU0-14216|'], ['|TU0-36408|', '|TU0-13193|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.gene_transcription_units(gene=gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|EG12115|', '|EG10850|'], ['|EG11125|', '|EG11126|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.cotranscribed_genes(gene=gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.terminators_affecting_gene(gene=gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|COLI-K12|', '|COLI-K12|']\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.chromosome_of_object(gene))\n", + "print(lst[-10:])" + ] + }, + { + "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": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/Operations_on_Pathways.ipynb b/examples/Operations_on_Pathways.ipynb new file mode 100644 index 0000000..f47272f --- /dev/null +++ b/examples/Operations_on_Pathways.ipynb @@ -0,0 +1,380 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# to run the script, you need to start pathway tools form the command line \n", + "# using the -lisp -python options. Example (from the pathway tools github repository)\n", + "\n", + "import os\n", + "# os.system('nohup /opt/pathway-tools/pathway-tools -lisp -python &')\n", + "os.system('nohup pathway-tools -lisp -python-local-only &') # added cybersecurity" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# modify sys.path to recognize local pythoncyc\n", + "import sys\n", + "\n", + "module_path = os.path.abspath(os.path.join('../'))\n", + "sys.path = [module_path]\n", + "\n", + "# sys.path" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|META|', '|ECOLI|']\n" + ] + } + ], + "source": [ + "import pythoncyc\n", + "all_orgids = pythoncyc.all_orgids()\n", + "print(all_orgids)\n", + "\n", + "meta = pythoncyc.select_organism(u'|META|')\n", + "ecoli = pythoncyc.select_organism(u'|ECOLI|')" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|EG12082|',\n", + " '|EG12088|',\n", + " '|EG12090|',\n", + " '|EG12091|',\n", + " '|EG12092|',\n", + " '|EG11773|',\n", + " '|EG12093|',\n", + " '|EG12089|',\n", + " '|EG12087|',\n", + " '|EG11774|',\n", + " '|EG12086|',\n", + " '|EG12084|',\n", + " '|EG12083|',\n", + " '|EG10330|',\n", + " '|EG10331|',\n", + " '|EG10332|',\n", + " '|EG10333|']" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "pwy\n", + "An instance of the class |Pathways|. \n", + "sorted?\n", + "Keyword, Optional If true, the genes are sorted in the order in which the \n", + "corresponding reaction occurrs in the sequence of the pathway. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for pwy in ecoli.all_pathways(selector = 'all', base = True):\n", + " lst.append(ecoli.genes_of_pathway(pwy = pwy, sorted = True))\n", + "lst[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|NADH-DHI-CPLX|', '|FUMARATE-REDUCTASE|']" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "pwy\n", + "An instance of the class |Pathways|. \n", + "species\n", + "Keyword, Optional A list of species, such that in a multi-organism PGDB such as \n", + "MetaCyc, only proteins found in those organisms will be returned. This list can \n", + "include valid org‑ids, children of class |Organisms|, and strings. Please see \n", + "the documentation for the 'species slot‑unit for more information. \n", + "experimental-only?\n", + "Keyword, Optional When true, only return enzymes that have a non-computational \n", + "evidence code associated with it. \n", + "sorted?\n", + "Keyword, Optional If true, the enzymes are sorted in the order in which the \n", + "corresponding reaction occurrs in the sequence of the pathway. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for pwy in ecoli.all_pathways(selector = ':all', base = True):\n", + " lst.append(ecoli.enzymes_of_pathway(pwy = pwy, sorted = True, experimental_only = True))\n", + "lst[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|FUM|',\n", + " '|SUC|',\n", + " '|Menaquinones|',\n", + " '|Menaquinols|',\n", + " '|E-|',\n", + " '|PROTON|',\n", + " '|NAD|',\n", + " '|NADH|']" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst = []\n", + "for pwy in ecoli.all_pathways(selector = ':all', base = True):\n", + " lst.append(ecoli.compounds_of_pathway(pwy = pwy))\n", + "lst[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[['|NADH|',\n", + " '|Menaquinones|',\n", + " '|Menaquinols|',\n", + " '|PROTON|',\n", + " '|TRIMETHYLAMINE-N-O|'],\n", + " ['|TRIMETHYLAMINE-N-O|', '|NADH|'],\n", + " ['|NAD|',\n", + " '|Menaquinols|',\n", + " '|PROTON|',\n", + " '|TRIMETHYLAMINE|',\n", + " '|WATER|',\n", + " '|Menaquinones|'],\n", + " ['|WATER|', '|TRIMETHYLAMINE|', '|NAD|']]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst = []\n", + "for pwy in ecoli.all_pathways(selector = ':all', base = True):\n", + " lst.append(ecoli.substrates_of_pathway(pwy = pwy))\n", + "lst[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[],\n", + " ['|PWY-7195|', '|PWY-6556|'],\n", + " ['|PWY0-1597|'],\n", + " ['|RIBOSYN2-PWY|'],\n", + " ['|PWY0-1295|', '|PWY-6556|'],\n", + " [],\n", + " ['|PWY0-1584|', '|PWY0-1581|', '|PWY0-1573|', '|PWY0-1352|'],\n", + " [],\n", + " [],\n", + " []]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst = []\n", + "for pwy in ecoli.all_pathways(selector = ':all', base = True):\n", + " lst.append(ecoli.variants_of_pathway(pwy = pwy))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[['|RXN0-5264|', '|RXN0-5388|']], 1, 2, 2]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "pwy\n", + "An instance of the class |Pathways|, which is not a super-pathway (i.e., does \n", + "not have any entries in its 'sub‑pathways slot). \n", + "rxn-list\n", + "Optional The list of reactions to use as the starting list of connected \n", + "component clusters. Defaults to (get‑slot‑values pwy 'reaction‑list).\n", + "\n", + "pred-list\n", + "Optional The list of reaction predecessors to iterate from in order to cluster \n", + "the reactions in rxn‑list. Defaults to (get‑slot‑values pwy 'predecessors).\n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for pwy in ecoli.all_pathways(selector = ':all', base = True):\n", + " lst.append(ecoli.pathway_components(pwy = pwy))\n", + "lst[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[False, False, False, False, False, True, False, True, False, False]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst = []\n", + "for pwy in ecoli.all_pathways(selector = ':all', base = True):\n", + " lst.append(ecoli.noncontiguous_pathway_p(pwy = pwy))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[['|DMKCYT-RXN|', '|RXN-15348|', False],\n", + " ['|DMKCYT-RXN|', '|LACTALDREDUCT-RXN|', False],\n", + " ['|DMKCYT-RXN|', '|PFLDEACTIV-RXN|', False],\n", + " ['|DMKCYT-RXN|', '|OHMETPYRKIN-RXN|', False],\n", + " ['|DMKCYT-RXN|', '|RXN0-7094|', False],\n", + " ['|DMKCYT-RXN|', '|TRIOSEPISOMERIZATION-RXN|', False],\n", + " ['|DMKCYT-RXN|', '|RXN0-7298|', False],\n", + " ['|DMKCYT-RXN|', '|RXN0-1137|', False],\n", + " ['|DMKCYT-RXN|', '|BADH-RXN|', False],\n", + " ['|DMKCYT-RXN|', '|DMKCYT-RXN|', False]]" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "rxn1\n", + "An instance of the class |Reactions|. \n", + "rxn2\n", + "An instance of the class |Reactions|. \n", + "pwy\n", + "An instance of the class |Pathways|. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for pwy in ecoli.all_pathways(selector = ':all', base = True)[0:10]:\n", + " for rxn1 in ecoli.all_rxns(type_of_reactions = ':all')[0:10]:\n", + " for rxn2 in ecoli.all_rxns(type_of_reactions = ':all')[0:10]:\n", + " lst.append([rxn1, rxn2, ecoli.rxns_adjacent_in_pwy_p(rxn1 = rxn1, rxn2 = rxn2, pwy = pwy)])\n", + "# lst.append(ecoli.rxns_adjacent_in_pwy_p(rxn1 = u'|RXN0-5264|', rxn2 = u'|RXN0-5388|', pwy = pwy))\n", + "lst[-10:]" + ] + }, + { + "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": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/Operations_on_Proteins_and_Protein_Complexes.ipynb b/examples/Operations_on_Proteins_and_Protein_Complexes.ipynb new file mode 100644 index 0000000..7ed8f93 --- /dev/null +++ b/examples/Operations_on_Proteins_and_Protein_Complexes.ipynb @@ -0,0 +1,926 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# to run the script, you need to start pathway tools form the command line \n", + "# using the -lisp -python options. Example (from the pathway tools github repository)\n", + "\n", + "import os\n", + "# os.system('nohup /opt/pathway-tools/pathway-tools -lisp -python &')\n", + "os.system('nohup pathway-tools -lisp -python-local-only &') # added cybersecurity" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# modify sys.path to recognize local pythoncyc\n", + "import sys\n", + "\n", + "module_path = os.path.abspath(os.path.join('../'))\n", + "sys.path = [module_path]\n", + "\n", + "# sys.path" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|META|', '|ECOLI|']\n" + ] + } + ], + "source": [ + "import pythoncyc\n", + "all_orgids = pythoncyc.all_orgids()\n", + "print(all_orgids)\n", + "\n", + "meta = pythoncyc.select_organism(u'|META|')\n", + "ecoli = pythoncyc.select_organism(u'|ECOLI|')\n", + "proteins = [x.frameid for x in ecoli.proteins.instances][0:2]\n", + "complexes = ecoli.all_protein_complexes()[0:2]" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[['|G6106-MONOMER|'], [4]], [['|URAA-MONOMER|'], [2]]]\n", + "[[['|OPPC-MONOMER|'], [1]], [['|YHBN-MONOMER|'], [1]]]\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "p\n", + "An instance of the class |Proteins|. \n", + "coefficients?\n", + "Keyword, Optional If true, then the second return value of the function will be \n", + "a list of monomer coefficients. Defaults to true. \n", + "unmodify?\n", + "Keyword, Optional If true, obtain the monomers of the unmodified form of p.\n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.monomers_of_protein(protein = protein, coefficients = True, unmodify = True))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.monomers_of_protein(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[['|G6106-MONOMER|'], [4]], [['|URAA-MONOMER|'], [2]]]\n", + "[[['|OPPC-MONOMER|'], [1]], [['|YHBN-MONOMER|'], [1]]]\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "p\n", + "An instance of the class |Proteins|. \n", + "exclude-small-molecules?\n", + "Keyword, Optional If nil, then small molecule components are also returned. \n", + "Default value is true. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.base_components_of_protein(protein = protein, exclude_small_molecules = True))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.base_components_of_protein(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n", + "[['|OPPC-MONOMER|', '|CPLX0-3970|', '|ABC-22-CPLX|'], ['|YHBN-MONOMER|', '|CPLX0-7992|']]\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "protein\n", + "An instance of the class |Proteins|. \n", + "exclude-self?\n", + "Optional If true, then protein will not be included in the return value. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.containers_of(protein = protein, exclude_self = True))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.containers_of(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|CPLX0-7660|'], ['|CPLX0-8247|']]\n", + "[['|OPPC-MONOMER|', '|CPLX0-3970|', '|ABC-22-CPLX|'], ['|YHBN-MONOMER|', '|CPLX0-7992|']]\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "protein\n", + "An instance of the class |Proteins|. \n", + "exclude-self?\n", + "Optional If true, then protein will not be included in the return value. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.protein_or_rna_containers_of(protein = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.protein_or_rna_containers_of(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|CPLX0-7660|'], ['|CPLX0-8247|']]\n", + "[['|OPPC-MONOMER|'], ['|YHBN-MONOMER|']]\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "protein\n", + "An instance of the class |Proteins|. \n", + "exclude-self?\n", + "Optional If true, then protein will not be included in the return value. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.homomultimeric_containers_of(protein = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.homomultimeric_containers_of(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[True, True]\n", + "[True, True]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.polypeptide_or_homomultimer_p(protein = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.polypeptide_or_homomultimer_p(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|CPLX0-7660|', '|CPLX0-8247|']\n", + "['|OPPC-MONOMER|', '|YHBN-MONOMER|']\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.unmodified_form(protein = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.unmodified_form(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|CPLX0-7660|', '|CPLX0-8247|']\n", + "['|OPPC-MONOMER|', '|YHBN-MONOMER|']\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.unmodified_or_unbound_form(protein = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.unmodified_or_unbound_form(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|CPLX0-7660|'], ['|CPLX0-8247|']]\n", + "[['|OPPC-MONOMER|'], ['|YHBN-MONOMER|']]\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "prots\n", + "A list of instances of the class |Proteins|. \n", + "debind?\n", + "Keyword, Optional When non-nil, the proteins are further simplified by obtaining \n", + "the unbound form of the protein, if it is bound to a small molecule. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.reduce_modified_proteins(prots = [protein], debind = True))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.reduce_modified_proteins(prots = [protein]))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|G6106-MONOMER|', '|CPLX0-7660|'], ['|URAA-MONOMER|', '|CPLX0-8247|']]\n", + "[['|OPPC-MONOMER|', '|CPLX0-3970|', '|ABC-22-CPLX|'], ['|YHBN-MONOMER|', '|CPLX0-7992|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.all_direct_forms_of_protein(protein = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.all_direct_forms_of_protein(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|G6106-MONOMER|', '|CPLX0-7660|'], ['|URAA-MONOMER|', '|CPLX0-8247|']]\n", + "[['|OPPC-MONOMER|', '|CPLX0-3970|', '|ABC-22-CPLX|'], ['|YHBN-MONOMER|', '|CPLX0-7992|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.all_forms_of_protein(protein = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.all_forms_of_protein(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n", + "[['|OPPC-MONOMER|'], ['|YHBN-MONOMER|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.modified_forms(protein = protein, all_variants = True, exclude_self= True))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.modified_forms(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|CPLX0-7660|'], ['|CPLX0-8247|']]\n", + "[['|OPPC-MONOMER|'], ['|YHBN-MONOMER|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.modified_and_unmodified_forms(protein = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.modified_and_unmodified_forms(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|CPLX0-7660|'], ['|CPLX0-8247|']]\n", + "[['|OPPC-MONOMER|', '|CPLX0-3970|', '|ABC-22-CPLX|'], ['|YHBN-MONOMER|', '|CPLX0-7992|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.modified_containers(protein = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.modified_containers(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|CPLX0-7660|'], ['|CPLX0-8247|']]\n", + "[['|CPLX0-3970|', '|ABC-22-CPLX|'], ['|CPLX0-7992|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.top_containers(protein = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.top_containers(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n", + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.small_molecule_cplxes_of_prot(protein = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.small_molecule_cplxes_of_prot(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|G6106|'], ['|EG12129|']]\n", + "[['|EG10676|'], ['|G7665|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.genes_of_protein(protein = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.genes_of_protein(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|G6106|'], ['|EG12129|']]\n", + "[['|EG10676|'], ['|G7665|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.genes_of_proteins(prots = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.genes_of_proteins(prots = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|RXN0-4301|'], ['|TRANS-RXN-132|']]\n", + "[[], []]\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "protein\n", + "An instance of the class |Proteins|. \n", + "kb\n", + "Keyword, Optional The KB object of the KB in which to find the associated \n", + "reactions. Defaults to the current PGDB. \n", + "include-specific-forms?\n", + "Keyword, Optional When true, specific forms of associated generic reactions are \n", + "also returned. Default value is true. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.reactions_of_enzyme(protein = protein, include_subreactions = True))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.reactions_of_enzyme(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|ECOLI|'], ['|ECOLI|']]\n", + "[['|ECOLI|'], ['|ECOLI|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.species_of_protein(protein = protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.species_of_protein(protein = protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[True, True]\n", + "[False, False]\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "type\n", + "Optional Can take on one of the following values to select more precisely what \n", + "is meant by an “enzyme”:\n", + "\n", + ":any\n", + "Any protein that catalyzes a reaction is considered an enzyme. \n", + ":chemical-change\n", + "If the reactants and products of the catalyzed reactin differ, and not just by \n", + "their cellular location, then the protein is considered an enzyme. \n", + ":small-molecule\n", + "If the reactants of the catalyzed reaction differ and are small molecules, then \n", + "the protein is considered an enzyme. \n", + ":transport\n", + "If the protein catalyzes a transport reaction. \n", + ":non-transport\n", + "If the protein only catalyzes non-transport reactions. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.enzyme_p(protein = protein, type_of_reactions = 'any'))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.enzyme_p(protein = protein, type_of_reactions = 'non-transport-non-pathway'))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "try:\n", + " lst = []\n", + " for protein in complexes:\n", + " lst.append(ecoli.leader_peptide_p(protein = protein))\n", + " print(lst[-10:])\n", + "\n", + " lst = []\n", + " for protein in proteins:\n", + " lst.append(ecoli.leader_peptide_p(protein = protein))\n", + " print(lst[-10:])\n", + "except:\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|Proteins|', '|Proteins|']\n", + "['|Proteins|', '|Proteins|']\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.protein_p(protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.protein_p(protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|Protein-Complexes|', '|Protein-Complexes|']\n", + "[False, False]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.complex_p(protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.complex_p(protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|RXN0-4301|'], ['|TRANS-RXN-132|']]\n", + "[[], []]\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "p\n", + "An instance of the class |Proteins|. \n", + "check-protein-components?\n", + "Optional If true, check all components of this protein for catalyzed reactions. \n", + "Defaults to true. \n", + "check-protein-containers?\n", + "Optional If true, check the containers and modified forms of the protein for \n", + "catalyzed reactions. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.reactions_of_protein(protein = protein, check_protein_containers = True))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.reactions_of_protein(protein = protein, check_protein_components = True))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[False, False]\n", + "['|CCI-CYTOSOL-GN|', False]\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "rxn\n", + "An instance of the class |Reactions|. \n", + "compartments\n", + "A list of cellular compartments, as defined in the Cellular Components Ontology. \n", + "See frame 'CCO. \n", + "default-ok?\n", + "Keyword, Optional If true, then we return true if the reaction has no associated \n", + "compartment information, or one of its associated locations is a super-class of \n", + "one of the members of the compartments argument. \n", + "pwy\n", + "Keyword, Optional If supplied, the search for associated enzymes of the argument \n", + "rxn is limited to the given child of |Pathways|. \n", + "loose?\n", + "Keyword, Optional If true, then the compartments 'CCO‑CYTOPLASM and 'CCO‑CYTOSOL \n", + "are treated as being the same compartment. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.protein_in_compartment_p(rxn = protein, compartments = 'CCO-CYTOSOL'))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.protein_in_compartment_p(rxn = protein, compartments = ['CCO-CYTOSOL', 'CCO-MEMBRANE']))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|MTR-MONOMER|', '|G7942-MONOMER|', '|NANT-MONOMER|', '|B1006-MONOMER|', '|YDHE-MONOMER|', '|YDEA-MONOMER|', '|PITA-MONOMER|', '|YEIM-MONOMER|', '|BCR-MONOMER|', '|YGFO-MONOMER|']\n" + ] + } + ], + "source": [ + "\"\"\"\n", + "membranes\n", + "Keyword Either :all or a list of instances of the class. Defaults to :all \n", + "'CCO‑MEMBRANE. \n", + "method\n", + "Either :location or :reaction‑compartments. :location will check the 'locations \n", + "slot, while :reaction‑compartments will examine the compartments of reaction \n", + "substrates. Default value is :location. \n", + "\"\"\"\n", + "\n", + "lst = ecoli.all_transporters_across(membranes = 'all')\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n", + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in complexes:\n", + " lst.append(ecoli.autocatalytic_reactions_of_enzyme(protein))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.autocatalytic_reactions_of_enzyme(protein))\n", + "print(lst[-10:])" + ] + }, + { + "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": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/Operations_on_Reactions.ipynb b/examples/Operations_on_Reactions.ipynb new file mode 100644 index 0000000..1dc2bdb --- /dev/null +++ b/examples/Operations_on_Reactions.ipynb @@ -0,0 +1,586 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# to run the script, you need to start pathway tools form the command line \n", + "# using the -lisp -python options. Example (from the pathway tools github repository)\n", + "\n", + "import os\n", + "# os.system('nohup /opt/pathway-tools/pathway-tools -lisp -python &')\n", + "os.system('nohup pathway-tools -lisp -python-local-only &') # added cybersecurity" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# modify sys.path to recognize local pythoncyc\n", + "import sys\n", + "\n", + "module_path = os.path.abspath(os.path.join('../'))\n", + "sys.path = [module_path]\n", + "\n", + "# sys.path" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|META|', '|ECOLI|']\n" + ] + } + ], + "source": [ + "import pythoncyc\n", + "all_orgids = pythoncyc.all_orgids()\n", + "print(all_orgids)\n", + "\n", + "meta = pythoncyc.select_organism(u'|META|')\n", + "ecoli = pythoncyc.select_organism(u'|ECOLI|')" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[['|G6350|'],\n", + " ['|EG10754|'],\n", + " [],\n", + " [],\n", + " [],\n", + " ['|EG10068|'],\n", + " ['|EG10278|', '|G7213|'],\n", + " [],\n", + " ['|G7590|'],\n", + " []]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.genes_of_reaction(rxn = rxn))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[['|NICOTINATE_NUCLEOTIDE|', '|ATP|', '|PROTON|', '|PPI|', '|DEAMIDO-NAD|'],\n", + " ['|ACETALD|', '|PYRUVATE|', '|PROTON|', '|ACETOIN|', '|CARBON-DIOXIDE|'],\n", + " ['|Protein-Red-Disulfides|',\n", + " '|MONOMER0-4152|',\n", + " '|MONOMER0-4438|',\n", + " '|Protein-Ox-Disulfides|'],\n", + " ['|PROTON|', '|AMINO-OXOBUT|', '|AMINO-ACETONE|', '|CARBON-DIOXIDE|'],\n", + " ['|Cytochromes-B-Reduced|', '|Cytochromes-B|', '|Reduced-Cytochromes-o|'],\n", + " ['|ATP|',\n", + " '|L-CITRULLINE|',\n", + " '|L-ASPARTATE|',\n", + " '|PROTON|',\n", + " '|L-ARGININO-SUCCINATE|',\n", + " '|PPI|',\n", + " '|AMP|'],\n", + " ['|ACETYL-COA|', '|CPD-7221|', '|CPD-15244|', '|CO-A|'],\n", + " ['|MONOMER0-1641|', '|TORR-CPLX|', '|CPLX0-2821|'],\n", + " ['|ATP|',\n", + " '|D-BETA-D-HEPTOSE-1-P|',\n", + " '|PROTON|',\n", + " '|ADP-D-GLYCERO-D-MANNO-HEPTOSE|',\n", + " '|PPI|'],\n", + " ['|DSBD-MONOMER|', '|CPLX0-8004|', '|DSBG-MONOMER|', '|DSBDOXI-MONOMER|']]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.substrates_of_reaction(rxn = rxn))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[['|NICONUCADENYLYLTRAN-MONOMER|'],\n", + " ['|PYRUVOXID-CPLX|'],\n", + " [],\n", + " [],\n", + " [],\n", + " ['|CPLX0-238|'],\n", + " ['|G7213-MONOMER|', '|FADA-CPLX|'],\n", + " [],\n", + " ['|CPLX0-3661|'],\n", + " []]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "rxn\n", + "An instance of the class |Reactions|. \n", + "species\n", + "Keyword, Optional A list of species, such that in a multi-organism PGDB such as \n", + "MetaCyc, only proteins found in those organisms will be returned. This list can \n", + "include valid org‑ids, children of class |Organisms|, and strings. Please see \n", + "the documentation for the 'species slot‑unit for more information. Default value \n", + "is nil. \n", + "experimental-only?\n", + "Keyword, Optional When true, only return enzymes that have a non-computational \n", + "evidence code associated with it. \n", + "local-only-p\n", + "Keyword, Optional When true, only return enzymes that catalyze the specific form \n", + "of the reaction, as opposed to enzymes that are known to catalyze a more general \n", + "form (i.e., class) of the reaction. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.enzymes_of_reaction(rxn = rxn, species = u'|ECOLI|', \n", + " experimental_only = False, local_only_p = False))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[['|PROTON|', '|ATP|', '|NICOTINATE_NUCLEOTIDE|'],\n", + " ['|PPI|', '|DEAMIDO-NAD|']],\n", + " [['|PROTON|', '|PYRUVATE|', '|ACETALD|'], ['|ACETOIN|', '|CARBON-DIOXIDE|']],\n", + " [['|MONOMER0-4152|', '|Protein-Red-Disulfides|'],\n", + " ['|MONOMER0-4438|', '|Protein-Ox-Disulfides|']],\n", + " [['|AMINO-OXOBUT|', '|PROTON|'], ['|AMINO-ACETONE|', '|CARBON-DIOXIDE|']],\n", + " [['|Cytochromes-B-Reduced|', '|Cytochromes-B|'],\n", + " ['|Cytochromes-B|', '|Reduced-Cytochromes-o|']],\n", + " [['|L-ASPARTATE|', '|L-CITRULLINE|', '|ATP|'],\n", + " ['|PROTON|', '|L-ARGININO-SUCCINATE|', '|PPI|', '|AMP|']],\n", + " [['|CPD-15244|', '|CO-A|'], ['|CPD-7221|', '|ACETYL-COA|']],\n", + " None,\n", + " [['|PROTON|', '|D-BETA-D-HEPTOSE-1-P|', '|ATP|'],\n", + " ['|ADP-D-GLYCERO-D-MANNO-HEPTOSE|', '|PPI|']],\n", + " None]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "rxn\n", + "An instance of the class |Reactions|. \n", + "direction\n", + "Keyword, Optional Can take on the following values:\n", + "\n", + ":L2R\n", + "The reaction direction goes from ‘left to right’, as described in the \n", + "|Reactions| instance. \n", + ":R2L\n", + "The reaction direction goes from ‘right to left’; the opposite of what is \n", + "described in the |Reactions| instance. \n", + "\n", + "pwy\n", + "Keyword, Optional An instance of the class |Pathways|. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.reaction_reactants_and_products(rxn = rxn))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|SMALL-MOLECULE|',\n", + " '|SMALL-MOLECULE|',\n", + " '|PROTEIN-REACTION|',\n", + " '|SMALL-MOLECULE|',\n", + " '|PROTEIN-REACTION|',\n", + " '|SMALL-MOLECULE|',\n", + " '|SMALL-MOLECULE|',\n", + " '|PROTEIN-REACTION|',\n", + " '|SMALL-MOLECULE|',\n", + " '|PROTEIN-REACTION|']" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.reaction_type(rxn = rxn))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "ename": "PToolsError", + "evalue": "An internal error occurred in the running Pathway Tools application: :error, The function 'REACTION-WITHOUT-SEQUENCED-ENZYME-P' is not allowed to be called in restricted mode.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mPToolsError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0mlst\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mrxn\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mecoli\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mall_rxns\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype_of_reactions\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m':all'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0mlst\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mecoli\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrxn_without_sequenced_enzyme_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrxn\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrxn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 13\u001b[0m \u001b[0mlst\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/shared/D1/opt/repositories/git-reps/PythonCyc.networkbiolab/pythoncyc/PGDB.py\u001b[0m in \u001b[0;36mrxn_without_sequenced_enzyme_p\u001b[0;34m(self, rxn)\u001b[0m\n\u001b[1;32m 1111\u001b[0m \u001b[0mA\u001b[0m \u001b[0mboolean\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1112\u001b[0m \t\t\"\"\"\n\u001b[0;32m-> 1113\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msendPgdbFnCallBool\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'reaction-without-sequenced-enzyme-p'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmay_be_frameid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrxn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1114\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1115\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mpathway_hole_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrxn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/shared/D1/opt/repositories/git-reps/PythonCyc.networkbiolab/pythoncyc/PGDB.py\u001b[0m in \u001b[0;36msendPgdbFnCallBool\u001b[0;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[1;32m 377\u001b[0m \u001b[0mThis\u001b[0m \u001b[0mmethod\u001b[0m \u001b[0mtakes\u001b[0m \u001b[0mcare\u001b[0m \u001b[0mof\u001b[0m \u001b[0mtranslating\u001b[0m \u001b[0mno\u001b[0m \u001b[0mvalue\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0man\u001b[0m \u001b[0mempty\u001b[0m \u001b[0mlist\u001b[0m \u001b[0mto\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 378\u001b[0m \t\t\"\"\"\n\u001b[0;32m--> 379\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msendPgdbFnCall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 380\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 381\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/shared/D1/opt/repositories/git-reps/PythonCyc.networkbiolab/pythoncyc/PGDB.py\u001b[0m in \u001b[0;36msendPgdbFnCall\u001b[0;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[1;32m 370\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 371\u001b[0m \u001b[0mfnCall\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mprepareFnCall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 372\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msendPgdbQuery\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfnCall\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 373\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 374\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0msendPgdbFnCallBool\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/shared/D1/opt/repositories/git-reps/PythonCyc.networkbiolab/pythoncyc/PGDB.py\u001b[0m in \u001b[0;36msendPgdbQuery\u001b[0;34m(self, query)\u001b[0m\n\u001b[1;32m 359\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mpythoncyc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconfig\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_debug\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 360\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlisp_query\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 361\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mPTools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msendQueryToPTools\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlisp_query\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 362\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 363\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0msendPgdbFnCall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/shared/D1/opt/repositories/git-reps/PythonCyc.networkbiolab/pythoncyc/PTools.py\u001b[0m in \u001b[0;36msendQueryToPTools\u001b[0;34m(query)\u001b[0m\n\u001b[1;32m 195\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 196\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mmsg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstartswith\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m':error'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 197\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mPToolsError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'An internal error occurred in the running Pathway Tools application: {:s}'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 198\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 199\u001b[0m \u001b[0;31m# Return some result.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mPToolsError\u001b[0m: An internal error occurred in the running Pathway Tools application: :error, The function 'REACTION-WITHOUT-SEQUENCED-ENZYME-P' is not allowed to be called in restricted mode." + ] + } + ], + "source": [ + "\"\"\"\n", + "rxn\n", + "An instance of the class |Reactions|. \n", + "complete?\n", + "Optional If true, the predicate will return true when there is any associated \n", + "gene without a sequence. If nil, the predicate will return true when all \n", + "associated genes are without a sequence. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.rxn_without_sequenced_enzyme_p(rxn = rxn))\n", + "lst[-10:]\n", + "\n", + "# this raise an error because the lisp function is REACTION-WITHOUT-SEQUENCED-ENZYME-P, \n", + "# which only argument is a rxn" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "rxn\n", + "An instance of the class |Reactions|. \n", + "hole-if-any-gene-without-position?\n", + "Keyword, Optional If true, then genes without specified coordinates for the \n", + "current organism’s genome are not counted when determining the status of the \n", + "reaction.\n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.pathway_hole_p(rxn = rxn))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.rxn_present_p(rxn = rxn))\n", + "lst[-10:]\n", + "\n", + "# this raise an error because the lisp function is RXN-PRESENT?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "specific-rxn\n", + "A child of the class |Reactions|. \n", + "generic-rxn\n", + "A child of the class |Reactions|. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.rxn_specific_form_of_rxn_p(specific_rxn = rxn, generic_rxn = u'|RXN0-3741|'))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.nonspecific_forms_of_rxn(rxn = rxn))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.specific_forms_of_rxn(rxn = rxn))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "rxn\n", + "An instance of the class |Reactions|. \n", + "compartments\n", + "A list of cellular compartments, as defined in the Cellular Components Ontology. \n", + "See frame 'CCO. \n", + "default-ok?\n", + "Keyword, Optional If true, then we return true if the reaction has no associated \n", + "compartment information, or one of its associated locations is a super-class of \n", + "one of the members of the compartments argument. \n", + "pwy\n", + "Keyword, Optional If supplied, the search for associated enzymes of the argument \n", + "rxn is limited to the given child of |Pathways|. \n", + "loose?\n", + "Keyword, Optional If true, then the compartments 'CCO‑CYTOPLASM and 'CCO‑CYTOSOL \n", + "are treated as being the same compartment.\n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.rxn_in_compartment_p(rxn = rxn, compartments = [u'|CCO_CYTOSOL|']))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "rxn\n", + "An instance of the class |Reactions|. \n", + "default\n", + "Optional The default compartment for reactions without any compartment \n", + "annotations on their substrates. The default value is 'CCO‑CYTOSOL. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.compartment_of_rxn(rxn = rxn))\n", + "lst[-10:]\n", + "\n", + "# this raise an error because the lisp function is missing (?)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "rxn\n", + "An instance of the class |Reactions|. \n", + "sides\n", + "Keyword, Optional The slots of the reaction to consider. The default value is \n", + "'(LEFT RIGHT). \n", + "default-compartment\n", + "The default compartment, as determined by the function (default‑compartment), \n", + "which currently is set to 'CCO‑CYTOSOL.\n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.compartments_of_reaction(rxn = rxn))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "rxn\n", + "An instance of the class |Reactions|. \n", + "side\n", + "Keyword, Optional The side of the reaction from which to return the transported \n", + "compound. \n", + "primary-only?\n", + "Keyword, Optional If true, then filter out common exchangers (currently defined \n", + "as '(PROTON NA CPD-1)+). If true, and the only transported compounds are in this \n", + "list, then the filter doesn’t apply. \n", + "from-compartment\n", + "Keyword, Optional A compartment (child of class 'CCO). If specified, then only \n", + "return compounds transported from that compartment. \n", + "to-compartment\n", + "Keyword, Optional A compartment (child of class 'CCO). If specified, then only \n", + "return compounds transported to that compartment. \n", + "show-compartment\n", + "Keyword, Optional A compartment (child of class 'CCO). If specified, and the \n", + "compound is modified during transport, then only return the form of the compound \n", + "as found in this compartment. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':transport'):\n", + " lst.append(ecoli.transported_chemicals(rxn = rxn))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "rxn\n", + "An instance of the class |Reactions|. \n", + "pwy\n", + "A child of the class |Pathways|. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.get_predecessors(rxn = rxn, pwy = u'PWY0-1347'))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\"\"\"\n", + "rxn\n", + "An instance of the class |Reactions|. \n", + "pwy\n", + "A child of the class |Pathways|. \n", + "\"\"\"\n", + "\n", + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.get_successors(rxn = rxn, pwy = u'PWY0-1347'))\n", + "lst[-10:]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "lst = []\n", + "for rxn in ecoli.all_rxns(type_of_reactions = ':all'):\n", + " lst.append(ecoli.rxn_w_isozymes_p(rxn = rxn))\n", + "lst[-10:]" + ] + }, + { + "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": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/Operations_on_Regulation_Frames.ipynb b/examples/Operations_on_Regulation_Frames.ipynb new file mode 100644 index 0000000..c9b0d7c --- /dev/null +++ b/examples/Operations_on_Regulation_Frames.ipynb @@ -0,0 +1,994 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# to run the script, you need to start pathway tools form the command line \n", + "# using the -lisp -python options. Example (from the pathway tools github repository)\n", + "\n", + "import os\n", + "# os.system('nohup /opt/pathway-tools/pathway-tools -lisp -python &')\n", + "os.system('nohup pathway-tools -lisp -python-local-only &') # added cybersecurity" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# modify sys.path to recognize local pythoncyc\n", + "import sys\n", + "\n", + "module_path = os.path.abspath(os.path.join('../'))\n", + "sys.path = [module_path]\n", + "\n", + "# sys.path" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|META|', '|ECOLI|']\n" + ] + } + ], + "source": [ + "import pythoncyc\n", + "all_orgids = pythoncyc.all_orgids()\n", + "print(all_orgids)\n", + "\n", + "meta = pythoncyc.select_organism(u'|META|')\n", + "ecoli = pythoncyc.select_organism(u'|ECOLI|')\n", + "\n", + "regs = [x.frameid for x in ecoli.regulation.instances][0:2]\n", + "genes = [x.frameid for x in ecoli.genes.instances][0:2]\n", + "proteins = [x.frameid for x in ecoli.proteins.instances][0:2]\n", + "tus = [x.frameid for x in ecoli.transcription_units.instances][0:2]\n", + "dna_sites = [x.frameid for x in ecoli.DNA_Binding_Sites.instances][0:2]\n", + "mrna_sites = [x.frameid for x in ecoli.mRNA_Binding_Sites.instances][0:2]\n", + "terminators = [x.frameid for x in ecoli.Terminators.instances][0:2]\n", + "promoters = [x.frameid for x in ecoli.Promoters.instances][0:2]" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[True, False]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for reg in regs:\n", + " lst.append(ecoli.activation_p(reg))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[False, True]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for reg in regs:\n", + " lst.append(ecoli.inhibition_p(reg))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.direct_regulators(gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.direct_activators(gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.direct_inhibitors(gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "try:\n", + " lst = []\n", + " for protein in proteins:\n", + " lst.append(ecoli.transcription_factor_p(protein))\n", + " print(lst[-10:])\n", + "except:\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "try:\n", + " lst = []\n", + " for protein in proteins:\n", + " lst.append(ecoli.regulator_of_type(protein, class_name = ':activator'))\n", + " print(lst[-10:])\n", + "except:\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.regulon_of_protein(protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|TU162|'], ['|TU461|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for reg in regs:\n", + " lst.append(ecoli.regulation_frame_transcription_units(reg))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], ['|REG0-11053|', '|REG0-11052|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.transcription_unit_regulation_frames(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.transcription_unit_activation_frames(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], ['|REG0-11053|', '|REG0-11052|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.transcription_unit_inhibition_frames(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.transcription_units_of_protein(protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.genes_regulated_by_protein(protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.DNA_binding_sites_of_protein(protein, all_forms = True))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], ['|PD01379|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.regulator_proteins_of_transcription_unit(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "try:\n", + " lst = []\n", + " for protein in proteins:\n", + " lst.append(ecoli.transcription_factor_ligands(protein, u':both'))\n", + " print(lst[-10:])\n", + "except:\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for protein in proteins:\n", + " lst.append(ecoli.transcription_factor_active_forms(protein))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], ['|G6761|', '|EG10457|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.genes_regulating_gene(gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.genes_regulated_by_gene(gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[None, None, None], [['|G6761-MONOMER|'], ['|PD00288|'], None]]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.regulators_of_gene_transcription(gene, by_function = True))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.transcription_unit_activators(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], ['|PD01379|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.transcription_unit_inhibitors(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[None, None, None], [None, ['|PD01379|'], None]]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.regulators_of_operon_transcription(tu, by_function = True))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[None, '|PM0-8720|']\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.transcription_unit_promoter(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|G6954|'], ['|EG11346|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.transcription_unit_genes(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|G6954|', '|EG11346|']\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.transcription_unit_first_gene(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], ['|BS0-8048|', '|BS0-8047|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.transcription_unit_binding_sites(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], ['|PD01379|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.transcription_unit_transcription_factors(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.transcription_unit_mrna_binding_sites(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|COLI-K12|', '|COLI-K12|']\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.chromosome_of_operon(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], ['|BS0-7937|', '|BS0-7936|', '|BS0-7935|', '|BS0-7225|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.binding_sites_affecting_gene(gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for gene in genes:\n", + " lst.append(ecoli.binding_site_to_regulators(gene))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|PHOSPHO-PHOB|'], ['|CPLX0-7639|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for dna_site in dna_sites:\n", + " lst.append(ecoli.binding_site_to_regulators(dna_site))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|TU0-13975|'], ['|TU0-8636|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for promoter in promoters:\n", + " lst.append(ecoli.transcription_units_of_promoter(promoter))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for promoter in promoters:\n", + " lst.append(ecoli.promoter_binding_sites(promoter))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[], []]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.transcription_unit_terminators(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|TU0-8814|'], ['|TU0-8340|']]\n", + "[['|TU0-42642|', '|TU0-42640|', '|TU0-42638|', '|TU0-42636|', '|TU281|', '|TU00342|'], ['|TU00392|']]\n", + "[['|TU0-2021|'], ['|TU0-13514|']]\n", + "[['|TU0-13975|'], ['|TU0-8636|']]\n", + "[['|TU0-14216|'], ['|TU0-36408|', '|TU0-13193|']]\n", + "[['|TU-8390|', '|TU-8389|'], ['|TU00091|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.containing_tus(tu))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for tu in mrna_sites:\n", + " lst.append(ecoli.containing_tus(tu))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for tu in dna_sites:\n", + " lst.append(ecoli.containing_tus(tu))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for tu in promoters:\n", + " lst.append(ecoli.containing_tus(tu))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for tu in genes:\n", + " lst.append(ecoli.containing_tus(tu))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for tu in terminators:\n", + " lst.append(ecoli.containing_tus(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|COLI-K12|', '|COLI-K12|']\n", + "['|COLI-K12|', '|COLI-K12|']\n", + "['|COLI-K12|', '|COLI-K12|']\n", + "['|COLI-K12|', '|COLI-K12|']\n", + "['|COLI-K12|', '|COLI-K12|']\n", + "['|COLI-K12|', '|COLI-K12|']\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.containing_chromosome(tu))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for tu in mrna_sites:\n", + " lst.append(ecoli.containing_chromosome(tu))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for tu in dna_sites:\n", + " lst.append(ecoli.containing_chromosome(tu))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for tu in promoters:\n", + " lst.append(ecoli.containing_chromosome(tu))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for tu in genes:\n", + " lst.append(ecoli.containing_chromosome(tu))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for tu in terminators:\n", + " lst.append(ecoli.containing_chromosome(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|PM0-2201|'], ['|PM0-9620|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for dna_site in dna_sites:\n", + " lst.append(ecoli.binding_site_promoters(dna_site))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|G6954|'], ['|PM0-8720|', '|EG11346|', '|BS0-8048|', '|BS0-8047|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for tu in tus:\n", + " lst.append(ecoli.transcription_unit_all_components(tu))\n", + "print(lst[-10:])" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['|TU0-2021|'], ['|TU0-13514|']]\n", + "[['|TU0-42642|', '|TU0-42640|', '|TU0-42638|', '|TU0-42636|', '|TU281|', '|TU00342|'], ['|TU00392|']]\n" + ] + } + ], + "source": [ + "lst = []\n", + "for dna_site in dna_sites:\n", + " lst.append(ecoli.binding_site_transcription_units(dna_site))\n", + "print(lst[-10:])\n", + "\n", + "lst = []\n", + "for mrna_site in mrna_sites:\n", + " lst.append(ecoli.binding_site_transcription_units(mrna_site))\n", + "print(lst[-10:])" + ] + }, + { + "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": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/enumeration_operations.ipynb b/examples/enumeration_operations.ipynb new file mode 100644 index 0000000..a01d63d --- /dev/null +++ b/examples/enumeration_operations.ipynb @@ -0,0 +1,688 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# to run the script, you need to start pathway tools form the command line \n", + "# using the -lisp -python options. Example (from the pathway tools github repository)\n", + "\n", + "import os\n", + "# os.system('nohup /opt/pathway-tools/pathway-tools -lisp -python &')\n", + "os.system('nohup pathway-tools -lisp -python-local-only &') # added cybersecurity" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# modify sys.path to recognize local pythoncyc\n", + "import sys\n", + "\n", + "module_path = os.path.abspath(os.path.join('../'))\n", + "sys.path = [module_path]\n", + "\n", + "# sys.path" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|META|', '|ECOLI|']\n" + ] + } + ], + "source": [ + "import pythoncyc\n", + "all_orgids = pythoncyc.all_orgids()\n", + "print(all_orgids)\n", + "\n", + "meta = pythoncyc.select_organism(u'|META|')\n", + "ecoli = pythoncyc.select_organism(u'|ECOLI|')" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|PWY0-1347|',\n", + " '|PWY-6690|',\n", + " '|PWY0-1348|',\n", + " '|PWY-5162|',\n", + " '|PWY0-1352|',\n", + " '|PWY0-1355|',\n", + " '|2PHENDEG-PWY|',\n", + " '|PWY0-1465|',\n", + " '|TRESYN-PWY|',\n", + " '|PANTO-PWY|']" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "selector\n", + "Optional Selects whether all pathways, or just small-molecule metabolism base \n", + "pathways. Can take either a symbol of :all or :small‑molecule. Defaults to \n", + ":all. \n", + "base?\n", + "Optional If this argument evaluates to true, only includes base pathways. \n", + "Otherwise, all pathways, including superpathways, will be returned. \n", + "\"\"\"\n", + "\n", + "ecoli.all_pathways(selector = 'all', base = True)[0:10]\n", + "ecoli.all_pathways(selector = 'small-molecule', base = True)[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|RXN-17635|',\n", + " '|RXN-6268|',\n", + " '|RXN-7282|',\n", + " '|RXN-10720|',\n", + " '|RXN-12870|',\n", + " '|RXN-14515|',\n", + " '|RXN-13460|',\n", + " '|RXN-14808|',\n", + " '|RXN-18819|',\n", + " '|RXN-15121|']" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "type\n", + "Optional The type of reaction to return. Defaults to :metab‑smm. The possible \n", + "values are:\n", + "\n", + ":all\n", + "All reactions. \n", + ":metab-pathways\n", + "All reactions found within metabolic pathways. Includes reactions that are \n", + "pathway holes. May include a handfull of reactions whose substrates are \n", + "macromolecules, e.g., ACP. Excludes transport reactions. \n", + ":metab-smm\n", + "All reactions of small molecule metabolism, whether or not they are present in a \n", + "pathway. Subsumes :metab‑pathways. \n", + ":metab-all\n", + "All enzyme-catalyzed reactions. Subsumes :metab‑smm. \n", + ":enzyme\n", + "All enzyme-catalyzed reactions (i.e., instances of either EC-Reactions class or \n", + "Unclassified-Reactions class). \n", + ":transport\n", + "All transport reactions. \n", + ":small-molecule\n", + "All reactions whose substrates are all small molecules, as opposed to \n", + "macromolecules. Excludes transport reactions. \n", + ":protein-small-molecule-reaction\n", + "One of the substrates of the reaction is a macromolecule, and one of the \n", + "substrates of the reaction is a small molecule. \n", + ":protein-reaction\n", + "All substrates of the reaction are proteins. \n", + ":trna-reaction\n", + "One of the substrates of the reaction is a tRNA. \n", + ":spontaneous\n", + "Spontaneous reactions. \n", + ":non-spontaneous\n", + "Non-spontaneous reactions that are likely to be enzyme catalyzed. Some reactions \n", + "will be returned for type :non‑spontaneous that will not be returned by \n", + ":enzyme. \n", + "\"\"\"\n", + "\n", + "ecoli.all_rxns(type_of_reactions = 'all')[0:10]\n", + "ecoli.all_rxns(type_of_reactions = 'metab-pathways')[0:10]\n", + "ecoli.all_rxns(type_of_reactions = 'metab-smm')[0:10]\n", + "ecoli.all_rxns(type_of_reactions = 'metab-all')[0:10]\n", + "ecoli.all_rxns(type_of_reactions = 'transport')[0:10]\n", + "ecoli.all_rxns(type_of_reactions = 'small-molecule')[0:10]\n", + "ecoli.all_rxns(type_of_reactions = 'protein-small-molecule-reaction')[0:10]\n", + "ecoli.all_rxns(type_of_reactions = 'protein-reaction')[0:10]\n", + "ecoli.all_rxns(type_of_reactions = 'trna-reaction')[0:10]\n", + "ecoli.all_rxns(type_of_reactions = 'spontaneous')[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['|RXN-17635|']\n" + ] + }, + { + "data": { + "text/plain": [ + "['|Protein-Arginine-Aminocarbinol|',\n", + " '|PROTON|',\n", + " '|Protein-Arginine-Imidazolidine|']" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "rxns\n", + "A list of reaction frames. \n", + "\"\"\"\n", + "print(ecoli.all_rxns(type_of_reactions = 'spontaneous')[0:1])\n", + "ecoli.all_substrates(rxns = ecoli.all_rxns(type_of_reactions = 'spontaneous')[0:1])" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|DIPYRROMETHANE|',\n", + " '|GTP|',\n", + " '|UBIQUINONE-8|',\n", + " '|AMMONIUM|',\n", + " '|LYS|',\n", + " '|HEME_O|',\n", + " '|CPD-18260|',\n", + " '|PQQ|',\n", + " '|SIROHEME|',\n", + " '|Mo-molybdopterin-cofactor|']" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ecoli.all_cofactors()[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|DEOXY-RIBOSE-1P|',\n", + " '|CPD0-1546|',\n", + " '|CPD0-1545|',\n", + " '|NACL|',\n", + " '|Gramicidins|',\n", + " '|CPD0-1633|',\n", + " '|G7642-MONOMER|',\n", + " '|CPD-9229|',\n", + " '|PENICILLIN|',\n", + " '|CPD0-2358|']" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ecoli.all_modulators()[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|LI+|',\n", + " '|MELIBIOSE|',\n", + " '|D-GALACTURONATE|',\n", + " '|PROTON|',\n", + " '|CPD0-2241|',\n", + " '|GUANINE|',\n", + " '|Nucleosides|',\n", + " '|CPD-20888|',\n", + " '|XANTHINE|',\n", + " '|N-ACETYL-D-MANNOSAMINE-6P|']" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "from-compartment\n", + "Keyword, Optional The compartment that the chemical is coming from (see Cellular \n", + "Component Ontology). \n", + "to-compartment\n", + "Keyword, Optional The compartment that the chemical is going to (see Cellular \n", + "Component Ontology). \n", + "show-compartment\n", + "Keyword, Optional Show the form of the compound as it is present in the \n", + "specified compartment (see Cellular Component Ontology), if the compound is \n", + "modified during transport. \n", + "primary-only?\n", + "Keyword, Optional If true, filter out common transport compounds, such as \n", + "protons and Na+. \n", + "\"\"\"\n", + "\n", + "ecoli.all_transported_chemicals()[0:10]\n", + "ecoli.all_transported_chemicals(primary_only = True)[0:10]\n", + "ecoli.all_transported_chemicals(from_compartment = u'|CCO-CYTOSOL|')[0:10]\n", + "ecoli.all_transported_chemicals(to_compartment = u'|CCO-CYTOSOL|')[0:10]\n", + "ecoli.all_transported_chemicals(show_compartment = 'cell')[0:10] # not valid argument" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|CPLX0-7660|',\n", + " '|CPLX0-8247|',\n", + " '|CPLX0-3102|',\n", + " '|ACETYL-COA-CARBOXYLTRANSFER-CPLX|',\n", + " '|CPLX0-7|',\n", + " '|TRANS-CPLX-204|',\n", + " '|FLAGELLAR-MOTOR-COMPLEX|',\n", + " '|1-PFK|',\n", + " '|CPLX0-8125|',\n", + " '|CPLX0-7687|']" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "filter\n", + "Keyword The type of protein complexes to return. The argument must be one of the \n", + "following values:\n", + "\n", + ":all or t\n", + "Return all protein complexes. \n", + ":hetero\n", + "Return all heteromultimers. \n", + ":homo\n", + "Return all homomultimers. \n", + "\"\"\"\n", + "\n", + "ecoli.all_protein_complexes(filter = 'all')[0:10]\n", + "ecoli.all_protein_complexes(filter = 'hetero')[0:10]\n", + "ecoli.all_protein_complexes(filter = 'homo')[0:10]\n", + "ecoli.all_protein_complexes()[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|G6165-MONOMER|',\n", + " '|PHOSPHO-NARP|',\n", + " '|G6882-MONOMER|',\n", + " '|MONOMER0-1|',\n", + " '|G7947-MONOMER|',\n", + " '|G6175-MONOMER|',\n", + " '|EG11554-MONOMER|',\n", + " '|PD01196|',\n", + " '|EG10087-MONOMER|',\n", + " '|EG10226-MONOMER|']" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "Side-Effects\n", + "\n", + "allow-modified-forms?\n", + "Keyword, Optional A boolean value. If true, modified and unmodified forms of the \n", + "protein are returned. If false, then only unmodified forms of the proteins are \n", + "returned. The default value is t.\n", + "\"\"\"\n", + "\n", + "ecoli.all_transcription_factors()[0:10]\n", + "ecoli.all_transcription_factors(allow_modified_forms = True)[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|G6165-MONOMER|',\n", + " '|NARP-MONOMER|',\n", + " '|TAR-CPLX|',\n", + " '|G6882-MONOMER|',\n", + " '|EG11140-MONOMER|',\n", + " '|EG10881-MONOMER|',\n", + " '|G7947-MONOMER|',\n", + " '|G6175-MONOMER|',\n", + " '|EG12111-MONOMER|',\n", + " '|EG11554-MONOMER|']" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "class\n", + "Keyword, Optional The class |Regulation| or a subclass. It defaults to \n", + "|Regulation‑of‑Transcription‑Initiation|. \n", + "allow-modified forms?\n", + "Keyword, Optional A boolean value. If true, modified and unmodified forms of the \n", + "protein are returned. If false, then only unmodified forms of the proteins are \n", + "returned. The default value is t.\n", + "\"\"\"\n", + "\n", + "ecoli.all_genetic_regulation_proteins(class_name = u'|Regulation|', allow_modified_forms = False)[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|EG11355-MONOMER|',\n", + " '|RPOE-MONOMER|',\n", + " '|RPOD-MONOMER|',\n", + " '|RPON-MONOMER|',\n", + " '|PD00440|',\n", + " '|RPOS-MONOMER|',\n", + " '|RPOH-MONOMER|']" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ecoli.all_sigma_factors()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[['|TU0-8814|'],\n", + " ['|TU0-8710|'],\n", + " ['|TU0-13847|'],\n", + " ['|TU0-13769|'],\n", + " ['|TU0-13667|'],\n", + " ['|TU00321|'],\n", + " ['|TU0-13385|'],\n", + " ['|TU00223|'],\n", + " ['|TU0-14243|'],\n", + " ['|TU0-14168|']]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ecoli.all_operons()[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|RXN-14142|',\n", + " '|GLUCOSE-1-PHOSPHAT-RXN|',\n", + " '|2.7.10.1-RXN|',\n", + " '|5.99.1.2-RXN|',\n", + " '|1.5.1.34-RXN|',\n", + " '|RXN-17780|',\n", + " '|KETOACYLCOATHIOL-RXN|',\n", + " '|RXN0-7251|',\n", + " '|GLYCPDIESTER-RXN|',\n", + " '|LTAA-RXN|']" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "rxns\n", + "Keyword, Optional A list of instances of the class |Reactions|. Defaults to the \n", + "result of (all‑rxns :enzyme).\n", + "\"\"\"\n", + "\n", + "ecoli.rxns_w_isozymes(rxns = ecoli.all_rxns(':enzyme'))[0:10]\n", + "ecoli.rxns_w_isozymes()[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|DCYSDESULF-RXN|',\n", + " '|RXN-14142|',\n", + " '|RXN-12402|',\n", + " '|GLUCOSE-1-PHOSPHAT-RXN|',\n", + " '|PUTTRANSAM-RXN|',\n", + " '|1.5.1.34-RXN|',\n", + " '|DHDOGALDOL-RXN|',\n", + " '|RXN-19777|',\n", + " '|RXN-12073|',\n", + " '|RXN-14285|']" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "rxns\n", + "Keyword, Optional A list of instances of the class |Reactions|. Defaults to the \n", + "result of (all‑rxns :enzyme).\n", + "\"\"\"\n", + "\n", + "ecoli.rxns_catalyzed_by_complex(rxns = ecoli.all_rxns('enzyme'))[0:10]\n", + "ecoli.rxns_catalyzed_by_complex()[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|MHPELY-MONOMER|',\n", + " '|G6571-MONOMER|',\n", + " '|G7751-MONOMER|',\n", + " '|G7910-MONOMER|',\n", + " '|G6904-MONOMER|',\n", + " '|PGLUCONDEHYDRAT-MONOMER|',\n", + " '|MONOMER0-1241|',\n", + " '|ACECITLY-CPLX|',\n", + " '|G7422-MONOMER|',\n", + " '|EG12069-MONOMER|']" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "type\n", + "Keyword, Optional A type as taken from the argument to #'enzyme?. Defaults to \n", + ":chemical‑change.\n", + "\n", + ">> type\n", + "Optional Can take on one of the following values to select more precisely what \n", + "is meant by an “enzyme”:\n", + "\n", + ":any\n", + "Any protein that catalyzes a reaction is considered an enzyme. \n", + ":chemical-change\n", + "If the reactants and products of the catalyzed reactin differ, and not just by \n", + "their cellular location, then the protein is considered an enzyme. \n", + ":small-molecule\n", + "If the reactants of the catalyzed reaction differ and are small molecules, then \n", + "the protein is considered an enzyme. \n", + ":transport\n", + "If the protein catalyzes a transport reaction. \n", + ":non-transport\n", + "If the protein only catalyzes non-transport reactions. \n", + "\"\"\"\n", + "\n", + "ecoli.all_enzymes()[0:10]\n", + "ecoli.all_enzymes(type_of_reactions = ':any')[0:10]\n", + "ecoli.all_enzymes(type_of_reactions = ':chemical-change')[0:10]\n", + "ecoli.all_enzymes(type_of_reactions = ':small-molecule')[0:10]\n", + "ecoli.all_enzymes(type_of_reactions = ':transport')[0:10]\n", + "ecoli.all_enzymes(type_of_reactions = ':non-transport')[0:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['|DCUA-MONOMER|',\n", + " '|G7399-MONOMER|',\n", + " '|YIDT-MONOMER|',\n", + " '|CORA-MONOMER|',\n", + " '|EG12134-MONOMER|',\n", + " '|EG11486-MONOMER|',\n", + " '|CYNX-MONOMER|',\n", + " '|YJDL-MONOMER|',\n", + " '|EG11512-MONOMER|',\n", + " '|GLTP-MONOMER|']" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ecoli.all_transporters()[0:10]" + ] + }, + { + "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": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/pythoncyc/PGDB.py b/pythoncyc/PGDB.py index 469db75..631641d 100644 --- a/pythoncyc/PGDB.py +++ b/pythoncyc/PGDB.py @@ -1,5 +1,5 @@ # Copyright (c) 2014, SRI International -# +# # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including @@ -7,10 +7,10 @@ # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: -# +# # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -20,3311 +20,3504 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # ---------------------------------------------------------------------- -import PTools import sys -import config -from PTools import PToolsError, PythonCycError -from PToolsFrame import Symbol, PFrame, convertLispIdtoPythonId +import pythoncyc.config +import pythoncyc.PTools as PTools +from pythoncyc.PTools import PToolsError, PythonCycError +from pythoncyc.PToolsFrame import Symbol, PFrame, convertLispIdtoPythonId + if 'IPython' in sys.modules: - from IPython.display import display, HTML - -def may_be_frameid(x): - """ - This fn is useful to convert a string to a symbol - or a list of strings to a list of symbols, to make sure it is interpreted - as a frame id; but not to apply any conversion when the arg is not a string - or a list of strings. All functions of PGDB.py apply this fn on the - arguments that need a frame ids or PFrames. - - Parm - x: a Python object. - - Side Effect - Raise an error, if x is not None, String, PFrame, or a list of these. - - Returns - A symbol, list of symbols, or x unchanged. - """ - if x == None: - return None - elif isinstance(x,list): - return [may_be_frameid(y) for y in x] - if isinstance(x,PFrame): - return x - elif isinstance(x,basestring): - return Symbol(x) - else: raise PythonCycError('Error: the argument must a string or a PFrame but given {0}.'.format(x)) - - -def mkey(s): - """ - A simple function to convert a string into a Lisp keyword. - - Parm - s, any Python object - Returns - if s is a string, it is suffixed by ':', otherwise s itself. - """ - if isinstance(s,basestring): - return ':'+s - else: return s + from IPython.display import display, HTML + +def may_be_frameid(obj): + """ + This fn is useful to convert a string to a symbol or a list of strings to a list + of symbols, to make sure it is interpreted as a frame id; but not to apply any + conversion when the arg is not a string or a list of strings. All functions of + PGDB.py apply this fn on the arguments that need a frame ids or PFrames. + + Parm + obj, any Python object. + + Side Effect + Raise an error if obj is not None, String, PFrame, or a list of these. + + Returns + A symbol, list of symbols, or obj unchanged. + """ + if obj == None: + return None + elif isinstance(obj, list): + return [ may_be_frameid(y) for y in obj ] + elif isinstance(obj, PFrame): + return obj + elif isinstance(obj, str): + return Symbol(obj) + else: + raise PythonCycError('Error: the argument must a string or a PFrame, but given {0}.'.format(obj)) + +def mkey(obj): + """ + A simple function to convert a string into a Lisp keyword. + + Parm + obj, any Python object + + Returns + if obj is a string, it is suffixed by ':', otherwise obj itself. + """ + if isinstance(obj, str): + return ':' + obj + else: + return obj def convertArgToLisp(arg, inquote=False): - """ - Convert the arg into an acceptable quoted object for Python server - running on Pathway Tools. Note that any list is converted to - a quoted Lisp list. - - Parm - arg, a PFrame, a string, a number, a boolean, None or an s-expr. - inquote, a Boolean, True => this arg is inside an already quoted expression. - Return - a string, the arg is transformed to be acceptable for the Python Lisp server. - """ - if isinstance(arg, Symbol): - return ("" if inquote else "'")+arg._name - # Type basestring includes string and unicode string. - elif isinstance(arg, basestring): - # It is either a symbol, a string or a keyword. - # If it starts and ends with '|', assumes it is a symbol and add - # a quote if not already in a quoted context otherwise just - # translates to a string. - # The tests for symbols and keywords are simplified - # because if a tab or any characters not representing a Lisp - # keyword or symbols is embedded in the string, it is not detected. - if arg[0] == '|' and arg[-1] == '|' and not (' ' in arg): - return ("" if inquote else "'")+arg - elif arg[0] == ':' and not (' ' in arg): - return arg - else: return '"'+arg+'"' - # Note: False and True are also of type int. - # So, do this test before isinstance(... (int)) - elif isinstance(arg, bool): - return 't' if arg else 'nil' - elif arg == None: - return 'nil' - elif isinstance(arg, (int, long, float, complex)): - return str(arg) - elif isinstance(arg, PFrame): - # Just using the frameid is enough (there is no need to - # refer to the PGDB) because the arg is used in a call - # using the macro 'with-organism' where the PGDB is specified. - return arg.frameid - elif isinstance(arg, list): - return (("" if inquote else "'") + - '('+' '.join(convertArgToLisp(e,inquote=True) for e in arg) + ')') - elif isinstance(arg, dict): - # Convert a dictionary into a list of lists. - # {'a':2, 'b':3} => (('a' . 2) ('b' . 3)) - return convertArgToLisp(dict.items(arg)) - elif isinstance(arg, tuple): - # A Python tuple becomes an improper list in Lisp - # (1,) => (NIL . 1) - # (1,2) => (1 . 2) - # (1,2,3) => (1 2 . 3) - return (("" if inquote else "'") + - '('+(' '.join(convertArgToLisp(e,inquote=True) for e in arg[0:-1]) if (len(arg)>1) else '()') + ' . ' - + convertArgToLisp(arg[-1],inquote=True) + ')') - else: raise PythonCycError('PythonCyc does not know how to convert to Lisp the Python argument {0}.'.format(arg)) + """ + Convert arg into an acceptable quoted object for Python server running on + Pathway Tools. Note that any list is converted to a quoted Lisp list. + + Parm + arg + a PFrame, a string, a number, a boolean, None or an s-expr. + inquote + a Boolean, True means arg is inside an already quoted expression. + + Return + a string, the arg is transformed to be acceptable for the Python Lisp server. + """ + if isinstance(arg, Symbol): + return ("" if inquote else "'") + arg._name + + # Type basestring includes string and unicode string. + elif isinstance(arg, str): + # It is either a symbol, a string or a keyword. + # If it starts and ends with '|', assumes it is a symbol and add + # a quote if not already in a quoted context otherwise just + # translates to a string. + # The tests for symbols and keywords are simplified + # because if a tab or any characters not representing a Lisp + # keyword or symbols is embedded in the string, it is not detected. + if arg[0] == '|' and arg[-1] == '|' and not (' ' in arg): + return ("" if inquote else "'") + arg + elif arg[0] == ':' and not (' ' in arg): + return arg + else: + return '"' + arg + '"' + + # Note: False and True are also of type int. + # So, do this test before isinstance(... (int)) + elif isinstance(arg, bool): + return 't' if arg else 'nil' + elif arg == None: + return 'nil' + elif isinstance(arg, (int, float, complex)): + return str(arg) + elif isinstance(arg, PFrame): + # Just using the frameid is enough (there is no need to + # refer to the PGDB) because the arg is used in a call + # using the macro 'with-organism' where the PGDB is specified. + return arg.frameid + elif isinstance(arg, list): + return (("" if inquote else "'") + + '('+' '.join(convertArgToLisp(e, inquote=True) for e in arg) + ')') + elif isinstance(arg, dict): + # Convert a dictionary into a list of lists. + # {'a':2, 'b':3} => (('a' . 2) ('b' . 3)) + return convertArgToLisp(dict.items(arg)) + elif isinstance(arg, tuple): + # A Python tuple becomes an improper list in Lisp + # (1,) => (NIL . 1) + # (1,2) => (1 . 2) + # (1,2,3) => (1 2 . 3) + return (("" if inquote else "'") + + '(' + (' '.join(convertArgToLisp(e, inquote=True) for e in arg[0:-1]) if (len(arg) > 1) else '()') + ' . ' + + convertArgToLisp(arg[-1], inquote=True) + ')') + else: + raise PythonCycError('PythonCyc does not know how to convert to Lisp the Python argument {0}.'.format(arg)) def prepareFnCall(fn, *args, **kwargs): - """ - Prepare all arguments and keyword arguments for a function call to Pathway Tools. - Parms - fn, a string, the name of the Lisp function to call. - args, list of arguments - kwargs, list of keyword arguments - Return - a string which represents a Lisp fn call with args and keyword args. - """ - args2 = ' '.join([convertArgToLisp(arg) for arg in args]) - keywords = ' '.join([':'+key+' '+str(convertArgToLisp(kwargs[key])) - for key in kwargs if kwargs[key] != None]) - return '('+fn+' '+args2+' '+keywords+')' - + """ + Prepare all arguments and keyword arguments for a function call to Pathway Tools. + + Parms + fn + a string, the name of the Lisp function to call. + args + list of arguments + kwargs + list of keyword arguments + + Return + a string which represents a Lisp fn call with args and keyword args. + """ + args2 = ' '.join([convertArgToLisp(arg) for arg in args]) + keywords = ' '.join([ ':' + key + ' ' + str(convertArgToLisp(kwargs[key])) + for key in kwargs if kwargs[key] != None ]) + + lisp_query = '(' + fn + ' ' + args2 + ' ' + keywords + ')' + if pythoncyc.config._debug: + print(lisp_query) + return lisp_query class PGDB(): - """ - Please consult the the tutorial.html file under the doc directory - for an introduction on how to use this class. - - """ - - def __init__(self, orgid): - """ - Once a PGDB object is created, it has been validated that the - organism (orgid) exists on the running Pathway Tools server. - From that PGDB object (e.g. ecoli), many classes of objects - can be retrieved by using the attribute syntax of Python, such - as ecoli.reactions. - """ - if config._debug: - print "PGDB __init__" - self._orgid = "unknown" - self._error = False - # All PFrame objects of the PGDB are stored in attribute _frames, keyed by their frame ids. - self._frames = {} - # Verify that the running Pathway Tools has the PGDB (organism). - try: - r = PTools.sendQueryToPTools('(orgid-exist-p \''+orgid+')') - except PToolsError, msg: - raise PythonCycError('Pathway Tools was unable to verify if organism (orgid) %s is known in your running Pathway Tools. More specifically: %s' % (orgid, msg)) - if not r: - raise PythonCycError("The organism orgid %s is unknown. Use pythoncyc.all_orgids() to get a list of known orgids." % orgid) - self._error = True - else: - self._orgid = orgid - return None - - def __getinitargs__(self): - """ For the Pickle module. """ - return (self._orgid,) - - def __getstate__(self): - """ For the Pickel module """ - return self.__dict__.copy() - - def __setstate__(self, dict): - """ For the Pickel module """ - self.__dict__ = dict - - def __repr__(self): - return self.__str__() - - def __str__(self): - return '' - - def __dir__(self): - return (dir(self.__class__) + self.__dict__.keys()) - - def _nb_pframes(self): - """ - Return the number of PFrame objects accessible as attributes for a PGDB object. - """ - return len(self._frames) - - def __setattr__(self, attr, val): - if attr.startswith('_'): - self.__dict__[attr] = val - return None - attrId = convertLispIdtoPythonId(attr) - if isinstance(val, PFrame): - self._frames[attrId] = val - else: - self.__dict__[attrId] = val - return None - - def __getattr__(self, attr): - """ - Attributes for a PGDB may refer to frame ids. A frame id that - has dashes in Pathway Tools, is converted to attribute with - underscores '_' instead. If an attribute does not exist yet, - a request to Pathway Tools is done to verify if it may exist - as an instance or as a class. PFrame instances and classes are - created automatically when the corresponding instances or - classes exist in the PGDB. - """ - if config._debug: - print "PGDB ",self._orgid, "__getattr__", attr - # If the converted attribute exists as an attribute. - attrId = convertLispIdtoPythonId(attr) - if attrId in self.__dict__: - return self.__dict__[attrId] - if isinstance(attr,int): - return self._frames[attr] - if attrId in self._frames: - return self._frames[attrId] - # It could be an access to a class of objects (e.g. genes -> |Genes|). - realClassName = self.is_a_class_name(attr) - if realClassName: - # Use realClassName for the frame id, not attr. - return self.get_class_data(realClassName) - # It could be an instance in the PGDB. Try to create a frame for it. - realInstanceName = self.is_an_instance_name(attr) - if realInstanceName: - # Use the realname for the frame-id so that retrieving the - # object from Pathway Tools will work. - f = PFrame(realInstanceName, self, getFrameData=True, isClass=False) - return f - else: - return None - - if 'IPython' in sys.modules: - def _ipython_display_(self): - table = "" - # A PGDB frame may contain thousands of attributes, one - # for each instance. This output is too large to print in - # most cases. Print a succinct representation of the PGDB frame. - table = table+"" - table = table+"" - table = table+"
orgid"+self._orgid+"
Number of PFrames"+str(self._nb_pframes())+"
" - display(HTML(table)) - - def __setitem__(self, attr, val): - attrId = convertLispIdtoPythonId(attr) - if isinstance(val, PFrame): - self._frames[attrId] = val - else: - self.__dict__[attrId] = val - return None - - def __getitem__(self, index): - if config._debug: - print "PGDB __getitem__", index - if (isinstance(index,int) or isinstance(index,slice)) : - if self._frames: - return self._frames[index] - else: - raise PythonCycError('This PGDB has no _frames attribute.') - - # Accessing an item such as ecoli['trp'], index is a string not a number. - if index in self._frames: - return self._frames[index] - else: - attrId = convertLispIdtoPythonId(index) - if attrId in self._frames: - return self._frames[attrId] - else: - return self.__getattr__(index) - - def __eq__(self, other): - # The name of the orgid determines the object. - if isinstance(other, PGDB): - return self._orgid == other._orgid - else: - return False - - def __ne__(self, o): - return not self.__eq__(o) - - def save_pgdb(self): - """ - Save a PGDB that has been modified in the running Pathway Tools server. - The PGDB that will be saved is based on the orgid of this PGDB object. - """ - return self.sendPgdbFnCallBool('save-kb') - - def get_major_classes(self): - """ - Get from Pathway Tools the classes Reactions, Pathways, Genes, - Compounds, Proteins, and all their instances with their data. - This method is very time consuming has - several ten of thousands of frames need to be transferred - from Pathway Tools and the corresponding PFrames need to be created. - """ - self.reactions - self.pathways - self.genes - self.compounds - self.proteins - self.get_frame_objects([f.frameid for f in self.reactions.instances]) - self.get_frame_objects([f.frameid for f in self.pathways.instances]) - self.get_frame_objects([f.frameid for f in self.genes.instances]) - self.get_frame_objects([f.frameid for f in self.compounds.instances]) - self.get_frame_objects([f.frameid for f in self.proteins.instances]) - - def sendPgdbQuery(self, query): - """ - Send a query for a specific PGDB using its orgid. - Use the macro with-organism for the Lisp Python server. - - Parm - query, a string. That string should be acceptable to the Lisp Python server. - Return - the result (as a Python object) of the execution of the query in Pathway Tools. - """ - # Evaluate a query in the context of this PGDB. - if self._orgid == "unknown": - print "Cannot send any query because the selected organism is unknown." - return None - else: - return PTools.sendQueryToPTools('(with-organism (:org-id \''+self._orgid+') '+query+')') - - def sendPgdbFnCallBool(self, fn, *args, **kwargs): - """ - Send a PGDB query to Pathway Tools that will return a Bool value. - This method takes care of translating no value or an empty list to False. - """ - result = self.sendPgdbFnCall(fn, *args, **kwargs) - if result == None or result == []: - return False - else: return result - - def sendPgdbFnCallList(self, fn, *args, **kwargs): - """ - Send a PGDB query to Pathway Tools that will return a List value. - This method takes care of translating no value or False to an empty list. - """ - result = self.sendPgdbFnCall(fn, *args, **kwargs) - if result == None or result == False: - return [] - else: return result - - def sendPgdbFnCall(self, fn, *args, **kwargs): - """ - Send a PGDB query to Pathway Tools based on function fn and arguments args and - kwargs (keyword args) and return the result. If multiple values are - returned by fn, the Pathway Tools Python server transforms them into a list. - """ - fnCall = prepareFnCall(fn, *args, **kwargs) - return self.sendPgdbQuery(fnCall) - - def is_a_class_name(self, className): - """ - Verify that className is a known class in Pathway Tools. - Return the real name of that class because the className may have - been transformed by fn class-name-p to generate the closest real class name. - - Parm - className, a string, the class name to verify. - Return - a string, either className itself, or modified by replacing - '_' to '-' or some case letters changed to match an existing class - name in Pathway Tools. - """ - return self.sendPgdbFnCallBool('class-name-p', className) - - def get_class_data(self, realClassName, getInstancesData=False): - """ - Retrieve the class slots and their values, creating a PFrame for the class. - Retrieve also the list of instances from Pathway Tools and - create a PFrame for each instance. Store the list of PFrames - in attribute 'instances' of the class object. If getInstancesData is True, - get also all instances slots and their data. - - Parms - realClassName, a string, the real name of the class to retrieve. - getInstancesData, boolean, True => get the slots and data of all instances. - - Returns - A PFrame representing the class with all its slot names - as Python attributes. - """ - fclass = PFrame(realClassName, self, getFrameData=True, isClass = True) - attrId = convertLispIdtoPythonId(realClassName) - frameids = self.sendPgdbFnCallList('get-class', fclass) - if not (frameids == None): - if getInstancesData: - # Create PFrame instances with all their slots and data. - instances = self.get_frame_objects(frameids) - else: - # Create PFrame instances but the data for each frame is not brought in now. - # Reuse a PFrame for a frameid, if it already exists for this PGDB. - instances = self.create_frame_objects(frameids) - fclass.__dict__['instances'] = instances - return fclass - - def create_frame_objects(self, frameids): - """ - Create all the required PFrames for the given frameids. - If a PFrame already exist for a frameid on the PGDB, reuse - that PFrame, otherwise create a PFrame. No data is transferred - from Pathway Tools. - - Parm - frameids, list of frame ids (strings) - Side-Effects - self is modified to contain new PFrames indexed on new frameids - Return - list of PFrames - """ - pframes = [] - for frameid in frameids: - attrID = convertLispIdtoPythonId(frameid) - if attrID in self.__dict__: - f = self.__dict__[attrID] - else: - f = PFrame(frameid, self) - self.__dict__[attrID] = f - pframes.append(f) - return pframes - - def get_frame_objects(self, frameids): - """ - For each frame id of the list frameids, retrieve the slots - and their data. Reuse the PFrame of frameid if it already exist for this PGDB, - otherwise create one and attach it to this PGDB. - - Parm - frameids, list of frame ids (strings). - Return - list of PFrames, one for each frame id. - """ - frameObjects = self.sendPgdbFnCallList('get-frame-objects', may_be_frameid(frameids)) - pframes = [] - for frameid, slotsData in frameObjects.iteritems(): - attrID = convertLispIdtoPythonId(frameid) - if attrID in self.__dict__: - f = self.__dict__[attrID] - else: - f = PFrame(frameid, self) - self.__dict__[attrID] = f - pframes.append(f) - f._gotframe = True - for slot, data in slotsData.iteritems(): - f.__dict__[convertLispIdtoPythonId(slot)] = data - return pframes - - def is_an_instance_name(self, frameid): - """ - Similar to method is_a_class_name but for a frame that is not a class. - If frameid is a real frame id of an object of this PGDB, returns frameid as is. - If not, try to convert frameid to an exist frame id by transforming cases of - letters and underscores to dashes in frameid. - - Parm - frameid, a string. - - Returns - a string representing an existing frame id in the PGDB. - """ - return self.sendPgdbFnCallBool('frameid-instance-p', Symbol(frameid)) - - def get_class_all_instances(self, className): - """ - Get all instances of the given class name for this PGDB. - ClassName must be exactly as Pathway Tools expect the name of the class, - no conversion is applied. - - Parm - className, a symbol specified as a string (e.g., '|Reactions|') - - Returns - list of frameids - """ - return self.sendPgdbFnCallList('gcai', Symbol(className)) - - def get_class_all_subs(self, classArg): - """ - Get all subclasses of the given class name for this PGDB. - If classArg is a string, it must be exactly as Pathway Tools expect the name of the class, - no conversion is applied. - - Parm - classArg, a symbol specified as a string (e.g., '|Reactions|') or as - a PFrame. - - Returns - list of frameids corresponding to the subclasses of the classArg. - """ - return self.sendPgdbFnCallList('get-class-all-subs', classArg) - - def run_fba(self, fileName): - """ - In PythonCyc there is a run_fba method defined globally in the pythoncyc - module and there is this version which is run under a specific PGDB. - Notice though that the FBA input file provided will decide which organism - is used for running FBA and may override this PGDB. - - Parms - fileName, a string which is the name of the FBA input file on the - running Pathway Tools machine. - - Returns - A list with the following values: - 1) True <=> success, the FBA completed without error (for growth, see 5) - 2) List of error messages, if any - 3) List of output messages generated by MetaFlux (FBA module) during parsing - and execution - 4) The solver (SCIP) status symbol - 5) The flux of the objective biomass, non-zero if growth - 6) Number of growth cases if FBA input file is a knockout run, - or the number of active reactions if the FBA input file is solving a model - 7) The list of reactions that were in the model after instantiation - 8) The list of reactions that were active (non zero flux) with their fluxes - """ - return self.sendPgdbFnCall('python-run-fba', fileName) - - def get_slot_values(self, frameid, slotName): - """ - Return the slot values of a frame object. - Parms - frameid - a string representing the unique identifier for a frame object. - slotName - a string representing the slot of the frame object. - - Returns - list of values of the given slot. Values can be frameids, booleans, - strings, or numbers. - - Example: - To get the substrates participating on the left of reaction RXN-9000: - meta.get_slot_values('RXN-9000', 'LEFT') - where meta is a variable bound to a PGDB object. - """ - return self.sendPgdbFnCallList('get-slot-values', Symbol(frameid), Symbol(slotName)) - - def put_slot_values(self, frameid, slotName, val): - """ - Modify the slot values of a frame object with the given val. Val is typically - a list of objects. - - Important: The modified frame is not updated for any PFrame object that might has been - previously loaded from that PGDB. This operation should be used only - for its effect on the PGDB in the running Pathway Tools application. - Parms - frameid - a string representing the unique identifier for a frame object. - slotName - a string representing the slot of the frame object. - val - a value to store in the slot, typically a list of values or objects. - Side-Effects - The slot of that frame is replaced with the new value. - - Returns - Nothing - Example: - To put the substrates participating on the left of reaction RXN-9000: - put_slot_values('RXN-9000', 'LEFT', ['CPD-9459','CPD-9460']) - """ - return self.sendPgdbFnCallList('put-slot-values', Symbol(frameid), Symbol(slotName), val) - - def put_slot_value(self, frameid, slotName, val): - """ - Modify the slot value of a frame object with the given val. Val is a single - value (e.g., not a list). - - Important: The modified frame is not updated for any PFrame object that might has been - previously loaded from that PGDB. This operation should be used only - for its effect on the PGDB in the running Pathway Tools application. - - Parms - frameid - a string representing the unique identifier for a frame object. - slotName - a string representing the slot of the frame object. - val - a value to store in the slot. - - Side-Effects - The slot of that frame is replaced with the new value - - Returns - Nothing - Example: - To put the Gibbs free energy of reaction RXN-9000: - put_slot_value('RXN-9000', 'GIBBS-0', 7.52) - """ - return self.sendPgdbFnCall('put-slot-value', Symbol(frameid), Symbol(slotName), val) - - def get_slot_value(self, frameid, slotName): - """ - Return the single slot value of a frame object. - Parms - frameid - a string representing the unique identifier for a frame object. - slotName - a string representing the slot of the frame object. - Example: - To get the substrates participating on the left of reaction RXN-9000: - get_slot_values('RXN-9000', 'LEFT') - """ - return self.sendPgdbFnCall('get-slot-value', Symbol(frameid), Symbol(slotName)) - - def all_pathways(self, selector='all', base=False): - """ - Description - Returns a list of pathway instance frames of a specified type. - Parms - selector - Selects whether all pathways, or just - small-molecule metabolism base pathways. Can take either - 'all' or 'small-molecule'. Defaults to 'all'. - base - If this boolean parameter is True, only includes - base pathways. Otherwise, all pathways, including - superpathways, will be returned. - - Return value - A list of instances of class Pathways. - """ - return self.sendPgdbFnCallList('all-pathways', mkey(selector), base) - - def all_reactions(self, type='metab-smm'): - return self.all_rxns(type) - - def all_rxns(self, type='metab-smm'): - """ - Description - Returns a set of reactions that fall within a particular category. - Parms - type - The type of reaction to return. Defaults to - 'metab-smm'. The possible values are: - - 'all' - All reactions. - 'metab-pathways' - All reactions found within metabolic pathways. Includes - reactions that are pathway holes. May include a handfull - of reactions whose substrates are macromolecules, e.g., - ACP. Excludes transport reactions. - 'metab-smm' - All reactions of small molecule metabolism, whether or - not they are present in a pathway. Subsumes - metab-pathways. - 'metab-all' - All enzyme-catalyzed reactions. Subsumes metab-smm. - 'enzyme' - All enzyme-catalyzed reactions (i.e., instances of - either EC-Reactions class or Unclassified-Reactions class). - 'transport' - All transport reactions. - 'small-molecule' - All reactions whose substrates are all small molecules, - as opposed to macromolecules. Excludes transport reactions. - 'protein-small-molecule-reaction' - One of the substrates of the reaction is a - macromolecule, and one of the substrates of the reaction - is a small molecule. - 'protein-reaction' - All substrates of the reaction are proteins. - 'trna-reaction' - One of the substrates of the reaction is a tRNA. - 'spontaneous' - Spontaneous reactions. - 'non-spontaneous' - Non-spontaneous reactions that are likely to be enzyme - catalyzed. Some reactions will be returned for type - non-spontaneous that will not be returned by enzyme. - - Return value - A list of reaction frame ids. - """ - return self.sendPgdbFnCallList('all-rxns', mkey(type)) - - def all_substrates(self, rxns): - """ - Description - Returns all unique substrates used in the reactions specified by - the parameter rxns. - Parms - rxns - A list of reaction PFrames or frame ids. - - Return value - A list of compound frame ids. There might be strings in the list, - as the left and right slots of a reaction frame can - contain strings. - """ - return self.sendPgdbFnCallList('all-substrates', may_be_frameid(rxns)) - - def all_cofactors(self): - """ - Description - Return a list of all cofactors used in the current PGDB. - Parms - None. - - Return value - A list of cofactor frame ids. - """ - return self.sendPgdbFnCallList('all-cofactors') - - - def all_modulators(self): - """ - Description - Enumerate all of the modulators, or direct regulators, in the - current PGDB. - Parms - None. - - Return value - A list of regulator frame ids. - """ - return self.sendPgdbFnCallList('all-modulators') - - - def all_sigma_factors(self): - """ - Description - Enumerate all RNA polymerase sigma factors. - Parms - None. - - Return value - A list of all instances of the class Sigma-Factors. - """ - return self.sendPgdbFnCallList('all-sigma-factors') - - def all_operons(self): - """ - Description - Enumerates all operons. In this case, an operon is defined as a - list of overlapping instances of Transcription-Units. - Parms - None. - - Return value - A list of lists of Transcription-Units, where all - Transcription-Units in the list belong to the same operon. - """ - return self.sendPgdbFnCallList('all-operons') - - def all_transporters(self): - """ - Description - Enumerate all transport proteins. - Parms - None. - - Return value - A list of instances of class Proteins. - """ - return self.sendPgdbFnCallList('all-transporters') - - def all_transported_chemicals(self, from_compartment=None, to_compartment=None, primary_only=False): - """ - Description - Enumerates all chemicals transported by transport reactions in - the current PGDB. - Parms - - from_compartment - Keyword, The compartment that the chemical is - coming from (see Cellular Component Ontology). - to_compartment - Keyword, The compartment that the chemical is - going to (see Cellular Component Ontology). - primary_only - Keyword, If True, filter out common transport - compounds, such as protons and Na+. - - Return value - A list of compound frame ids. - """ - kwargs = {'from-compartment': may_be_frameid(from_compartment), - 'to-compartment': may_be_frameid(to_compartment), - 'primary-only?': primary_only} - return self.sendPgdbFnCallList('all-transported-chemicals', **kwargs) - - def all_protein_complexes(self, filter='all'): - """ - Description - Enumerates different types of protein complexes. - Parms - filter - Keyword, The type of protein complexes to return. The - argument must be one of the following values: - - 'all' - Return all protein complexes. - 'hetero' - Return all heteromultimers. - 'homo' - Return all homomultimers. - - Return value - A list of protein complex frame ids. - """ - kwargs = {'filter': mkey(filter)} - return self.sendPgdbFnCallList('all-protein-complexes', **kwargs) - - def all_transcription_factors(self, allow_modified_forms=True): - """ - Description - Enumerates all transcription factors, or just unmodified forms - of transcription factors. - Parms - allow_modified_forms - Keyword, A boolean value. If True, modified and - unmodified forms of the protein are returned. If false, then - only unmodified forms of the proteins are returned. The - default value is t. - - Return value - A list of protein frame ids that are transcription factors. - """ - kwargs = {'allow-modified-forms?': allow_modified_forms} - return self.sendPgdbFnCallList('all-transcription-factors', **kwargs) - - def all_genetic_regulation_proteins(self, allow_modified_forms=True, class_name=None): - """ - Description - Enumerates all proteins that are involved in genetic regulation - of a particular given class. Optionally, just unmodified forms - of the proteins are returned. - Parms - class_name - Keyword, The class Regulation or a subclass. - It defaults to Regulation-of-Transcription-Initiation. - allow_modified_forms - Keyword, A boolean value. If True, modified and - unmodified forms of the protein are returned. If false, then - only unmodified forms of the proteins are returned. The - default value is True. - - Return value - A list of protein frames that are involved in the specified form - of regulation. - """ - kwargs = {'allow-modified-forms?': allow_modified_forms, - 'class' : Symbol(class_name)} - return self.sendPgdbFnCallList('all-genetic-regulation-proteins', **kwargs) - - - def rxns_w_isozymes(self, rxns=None): - """ - Description - Enumerate all reactions that have isozymes (distinct proteins or - protein classes that catalyze the same reaction). - Parms - rxns - Keyword, A list of instances of the class - Reactions. Defaults to the result of (all-rxns :enzyme). - - Return value - A list of A list of instances of the class Reactions with - isozymes. - """ - kwargs = {'rxns': may_be_frameid(rxns)} - return self.sendPgdbFnCallList('rxns-w-isozymes', **kwargs) - - def rxns_catalyzed_by_complex(self, rxns=None): - """ - Description - Enumerates all reactions catalyzed by an enzyme that is a - protein complex. - Parms - rxns - Keyword, A list of instances of the class - Reactions. Defaults to the result of (all-rxns :enzyme). - - Return value - A list of instances of the class Reactions with a protein - complex as an enzyme. - """ - kwargs = {'rxns': may_be_frameid(rxns)} - return self.sendPgdbFnCallList('rxns-catalyzed-by-complex', **kwargs) - - def all_enzymes(self, type=None): - """ - Description - Return all enzymes of a given type. - Parms - type - Keyword, A type as taken from the parameter to - fn enzyme. Defaults to 'chemical-change'. - - Return value - A list of instances of class Proteins. - """ - kwargs = {'type': type} - return self.sendPgdbFnCallList('all-enzymes', **kwargs) - - - def genes_of_reaction(self, rxn): - """ - Description - Return all genes that encode the enzymes of a given reaction. - Parms - rxn - An instance of the class Reactions, a frame id or PFrame. - - Return value - A list of instances of class Genes. - """ - return self.sendPgdbFnCallList('genes-of-reaction', may_be_frameid(rxn)) - - def substrates_of_reaction(self, rxn): - """ - Description - Return all of the reactants and products of a given reaction. - Parms - rxn - An instance of the class Reactions, a frame id or PFrame. - - Return value - A list that may consist of children of class Compounds, - children of class Polymer-Segments, or strings. - """ - return self.sendPgdbFnCallList('substrates-of-reaction', may_be_frameid(rxn)) - - def enzymes_of_reaction(self, rxn, species=None, experimental_only=None, local_only=None): - """ - Description - Return the enzymes that catalyze a given reaction. - Parms - rxn - An instance of the class Reactions, a frame id or PFrame. - species - Keyword, A list of species, such that in a - multi-organism PGDB such as MetaCyc, only proteins found in - those organisms will be returned. This list can include - valid org-ids, children of class Organisms, and - strings. Please see the documentation for the species - slot-unit for more information. Default value is nil. - experimental_only - Keyword, When True, only return enzymes that have - a non-computational evidence code associated with it. - local_only - Keyword, When True, only return enzymes that - catalyze the specific form of the reaction, as opposed to - enzymes that are known to catalyze a more general form - (i.e., class) of the reaction. - - Return value - A list of children of class Proteins or class - Protein-RNA-Complexes. - """ - kwargs = {'species': species, - 'experimental-only?': experimental_only, - 'local-only-p': local_only} - return self.sendPgdbFnCallList('enzymes-of-reaction', may_be_frameid(rxn), **kwargs) - - def reaction_reactants_and_products(self, rxn, direction=None, pwy=None): - """ - Description - Return the reactants and products of a reaction, based on a - specified direction. The direction can be specified explicity or - by giving a pathway as an argument. It is an error to both - specify the pathway and the explicit direction. If neither an - explicit direction or a pathway is given as an argument, then - the direction is computationally inferred from available - evidence within the PGDB. - Parms - rxn - An instance of the class Reactions, that is, a frame id or PFrame. - direction - Keyword, Can take on the following values: - - 'L2R' - The reaction direction goes from 'left to right', as - described in the Reactions instance. - 'R2L' - The reaction direction goes from 'right to left'; the - opposite of what is described in the Reactions - instance. - - pwy - Keyword, An instance of the class Pathways, a frame id or PFrame. - - Return value - Returns multiple values as a list. The first value is a list of reactants - as determined by the direction of the reaction, and the second - value is a list of the products as determined by the direction - of the reaction. Both lists have items that are children of - class Compounds, children of class Polymer-Segments, or - strings. - """ - kwargs = {'direction': direction, 'pwy': may_be_frameid(pwy)} - return self.sendPgdbFnCall('reaction-reactants-and-products', may_be_frameid(rxn), **kwargs) - - def reaction_type(self, rxn): - """ - Description - Returns a keyword describing the type of reaction. - Parms - rxn - An instance of the class Reactions, a frame id or PFrame. - - Return value - A string from the following list: - - 'small-molecule' - All substrates are small molecules, or small-molecule classes. - 'transport' - A substrate is marked with different compartment annotations - in the left and right slots. - 'protein-small-molecule-reaction' - At least one substrate is a protein and at least one is a - small molecule. - 'protein-reaction' - All substrates are proteins. - 'trna-reaction' - At least one substrate is a tRNA. - 'null-reaction' - No substrates or reactants are specified. - 'other' - None of the preceding cases apply. - """ - return self.sendPgdbFnCall('reaction-type', may_be_frameid(rxn)) - - def rxn_without_sequenced_enzyme_p(self, rxn, complete=None): - """ - Description - A predicate that tests if a given reaction has genes with no - associated sequence information. - Parms - rxn - An instance of the class Reactions, that is, a frame id or PFrame. - complete - Keyword, if True, the predicate will return True when there - is any associated gene without a sequence. If False, the - predicate will return True when all associated genes are - without a sequence. - - Return value - A boolean value. - """ - kwargs = {'complete': complete} - return self.sendPgdbFnCallBool('rxn-without-sequenced-enzyme-p', may_be_frameid(rxn), **kwargs) - - def pathway_hole_p(self, rxn, hole_if_any_gene_without_position=None): - """ - Description - A predicate that determines if the current reaction is - considered to be a 'pathway hole', or without an associated enzyme. - Parms - rxn - An instance of the class Reactions, a frame id or PFrame. - hole_if_any_gene_without_position - Keyword, If True, then genes without specified - coordinates for the current organism's genome are not - counted when determining the status of the reaction. - - Return value - A boolean value. - """ - kwargs = {'hole-if-any-gene-without-position?': hole_if_any_gene_without_position} - return self.sendPgdbFnCallBool('pathway-hole-p', may_be_frameid(rxn), **kwargs) - - def rxn_present_p(self, rxn): - """ - Description - A predicate that determines if there is evidence for the - occurrence of the given reaction in the current PGDB. - Parms - rxn - An instance of the class Reactions, that is, a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('rxn-present-p', may_be_frameid(rxn)) - - def rxn_specific_form_of_rxn_p(self, specific_rxn, generic_rxn): - """ - Description - A predicate that is True if the given generic reaction is a - generalized form of the given specific reaction. - Parms - specific_rxn - A child of the class Reactions, that is, a frame id or PFrame. - generic_rxn - A child of the class Reactions, that is, a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('rxn-specific-form-of-rxn-p', may_be_frameid(specific_rxn), may_be_frameid(generic_rxn)) - - def nonspecific_forms_of_rxn(self, rxn): - """ - Description - Return all of the generic forms of the given specific reaction. - Not every reaction will necessarily have a generic form. - Parms - rxn - An instance of the class Reactions, that is, a frame id or PFrame. - - Return value - A list of children of the class Reactions. - """ - return self.sendPgdbFnCallList('nonspecific-forms-of-rxn', may_be_frameid(rxn)) - - def specific_forms_of_rxn(self, rxn): - """ - Description - Return all of the specific forms of the given generic reaction. - Not every reaction will necessarily have a specific form. - Parms - rxn - A child of the class Reactions, that is, a frame id or PFrame. - - Return value - A list of instances of the class Reactions. - """ - return self.sendPgdbFnCallList('specific-forms-of-rxn', may_be_frameid(rxn)) - - def rxn_in_compartment_p(self, rxn, compartments, default_ok=None, pwy=None, loose=None): - """ - Description - A predicate that checks if the given reaction is present in a - list of cellular compartments. - Parms - rxn - An instance of the class Reactions, a frame id or PFrame. - compartments - A list of cellular compartments, as defined in the Cellular - Components Ontology. See frame CCO. - default_ok - Keyword, If True, then we return True if the - reaction has no associated compartment information, or one - of its associated locations is a super-class of one of the - members of the compartments parameter. - pwy - Keyword, a frame id or PFrame. - If supplied, the search for associated - enzymes of the parameter rxn is limited to the given child - of Pathways. - loose - Keyword, boolean. If True, then the compartments - CCO-CYTOPLASM and CCO-CYTOSOL are treated as being the - same compartment. - - Return value - A boolean value. - """ - kwargs = {'default-ok?': default_ok, 'pwy': may_be_frameid(pwy), 'loose': loose} - return self.sendPgdbFnCallBool('rxn-in-compartment-p', may_be_frameid(rxn), compartments, **kwargs) - - def compartment_of_rxn(self, rxn, default=None): - """ - Description - Returns the compartment of the reaction for non-transport - reactions. - Parms - rxn - An instance of the class Reactions, that is, a frame id or PFrame. - default - Keyword, The default compartment for reactions without any - compartment annotations on their substrates. The default - value is CCO-CYTOSOL. - - Return value - A child of the class CCO. - """ - return self.sendPgdbFnCall('compartment-of-rxn', may_be_frameid(rxn), default) - - def compartments_of_reaction(self, rxn, sides=None, default_compartment=None): - """ - Description - Returns the compartments associated with the given reaction. - Parms - rxn - An instance of the class Reactions, a frame id or PFrame. - sides - Keyword, The slots of the reaction to consider. - The default value is (LEFT RIGHT). - default_compartment - Keyword, - The default compartment, as determined by the function - (default-compartment), which currently is set to - CCO-CYTOSOL. - - Return value - A list of children of the class CCO. - """ - kwargs = {'sides': sides, 'default-compartment': may_be_frameid(default_compartment)} - return self.sendPgdbFnCallList('compartments-of-reaction', may_be_frameid(rxn), **kwargs) - - def transported_chemicals(self, rxn, side=None, primary_only=None, - from_compartment=None, to_compartment=None, show_compartment=None): - """ - Description - Return the compounds in a transport reaction that change - compartments. - Parms - rxn - An instance of the class Reactions, a frame id or PFrame. - side - Keyword, The side of the reaction from which to - return the transported compound. - primary_only - Keyword, If True, then filter out common - exchangers (currently defined as (PROTON NA CPD-1)+). If - True, and the only transported compounds are in this list, - then the filter doesn't apply. - from_compartment - Keyword, A compartment (child of class CCO). - If specified, then only return compounds transported from - that compartment. - to_compartment - Keyword, A compartment (child of class CCO). - If specified, then only return compounds transported to that - compartment. - show_compartment - Keyword, A compartment (child of class CCO). - If specified, and the compound is modified during transport, - then only return the form of the compound as found in this - compartment. - - Return value - A list of children of class Compounds. - """ - kwargs = {'side': side, - 'primary-only?': primary_only, - 'from-compartment': may_be_frameid(from_compartment), - 'to-compartment': may_be_frameid(to_compartment), - 'show-compartment': may_be_frameid(show_compartment)} - return self.sendPgdbFnCallList('transported-chemicals', may_be_frameid(rxn), **kwargs) - - def get_predecessors(self, rxn, pwy): - """ - Description - Return a list of all reactions that are direct predecessors - (i.e., occurr earlier in the pathway) of the given reaction in - the given pathway. - Parms - rxn - An instance of the class Reactions, a frame id or PFrame. - pwy - A child of the class Pathways. - - Return value - A list of instances of the class Reactions. - """ - return self.sendPgdbFnCallList('get-predecessors', may_be_frameid(rxn), may_be_frameid(pwy)) - - def get_successors(self, rxn, pwy): - """ - Description - Return a list of all reactions that are direct successors (i.e., - occurr later in the pathway) of the given reaction in the given - pathway. - Parms - rxn - An instance of the class Reactions, a frame id or PFrame. - pwy - A child of the class Pathways. - - Return value - A list of instances of the class Reactions. - """ - return self.sendPgdbFnCallList('get-successors', may_be_frameid(rxn), may_be_frameid(pwy)) - - def rxn_w_isozymes_p(self, rxn): - """ - Description - A predicate that tests if a given reaction has any associated - isozymes (distinct proteins or protein classes that catalyze the - same reaction). - Parms - rxn - An instance of the class Reactions, a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('rxn-w-isozymes-p', may_be_frameid(rxn)) - - def genes_of_pathway(self, pwy, sorted=None): - """ - Description - Return all genes coding for enzymes in the given pathway. - Parms - pwy - An instance of the class Pathways, a frame id or PFrame. - sorted? - Keyword, If True, the genes are sorted in the - order in which the corresponding reaction occurrs in the - sequence of the pathway. - - Return value - A list of instances of class Genes. - """ - kwargs = {'sorted': sorted} - return self.sendPgdbFnCallList('genes-of-pathway', may_be_frameid(pwy), **kwargs) - - def enzymes_of_pathway(self, pwy, species=None, experimental_only=None, sorted=None): - """ - Description - Return all enzymes that are present in the given pathway. - Parms - - pwy - An instance of the class Pathways, a frame id or PFrame. - species - Keyword, A list of species, such that in a - multi-organism PGDB such as MetaCyc, only proteins found in - those organisms will be returned. This list can include - valid org-ids, children of class Organisms, and - strings. Please see the documentation for the species - slot-unit for more information. - experimental_only - Keyword, When True, only return enzymes that have - a non-computational evidence code associated with it. - sorted - Keyword, If True, the enzymes are sorted in the - order in which the corresponding reaction occurrs in the - sequence of the pathway. - - Return value - A list of children of class Proteins or class - Protein-RNA-Complexes. - """ - kwargs = {'species': species, 'experimental-only?': experimental_only, 'sorted': sorted} - return self.sendPgdbFnCallList('enzymes-of-pathway', may_be_frameid(pwy), **kwargs) - - def compounds_of_pathway(self, pwy): - """ - Description - Return all substrates of all reactions that are within the given - pathway. - Parms - - pwy - An instance of the class Pathways, a frame id or PFrame. - - Return value - A list of children of class Compounds, children of class - Polymer-Segments, or strings. - """ - return self.sendPgdbFnCallList('compounds-of-pathway', may_be_frameid(pwy)) - - def substrates_of_pathway(self, pwy): - """ - Description - Bearing in mind the direction of all reactions within a pathway, - this function returns the substrates of the reactions in four - groups: a list of all reactant compounds (compounds occurring on - the left side of some reaction in the given pathway), the list - of proper reactants (the subset of reactants that are not also - products), a list of all products, and a list of all proper - products. - Parms - - pwy - An instance of the class Pathways, a frame id or PFrame. - - Return value - Four values as a list, each of which is a list of substrates. A substrate - may be a child of class Compounds, a child of class - Polymer-Segments, or a string. - """ - return self.sendPgdbFnCall('substrates-of-pathway', may_be_frameid(pwy)) - - def variants_of_pathway(self, pwy): - """ - Description - Returns all variants of a pathway. - Parms - - pwy - An instance of the class Pathways, a frame id or PFrame. - - Return value - A list of instance of the class Pathways. - """ - return self.sendPgdbFnCallList('variants-of-pathway', may_be_frameid(pwy)) - - def pathway_components(self, pwy, rxn_list=None, pred_list=None): - """ - Description - Returns all of the connected components of a pathway. A - connected component of a pathway is a set of reactions in the - pathway such that for all reactions R1 in the connected - component, a predecessor relationship holds between R1 and some - other reaction R2 in the connected component, and each connected - component is of maximal size. Every pathway will have from 1 to - N connected components, where N is the number of reactions in - the pathway. Most pathways have one connected component, but not - all. - Parms - - pwy, a frame id or PFrame. - An instance of the class Pathways, which is not a - super-pathway (i.e., does not have any entries in its - sub-pathways slot). - rxn_list - Keyword, The list of reactions to use as the starting list - of connected component clusters. Defaults to - the content of slot reaction-list in pwy. - - pred_list - Keyword, The list of reaction predecessors to iterate from - in order to cluster the reactions in rxn-list. Defaults to - list in slot predecessors of pwy. - - Return value - Returns three values as a list: the connected components as a list of - lists of the form ((r1 r2 r3) (r4 r5) (r6 r7 r8)) where each - sub-list contains all reactions in one connected component, the - number of connected components, and the length of the reaction - list. - """ - kwargs = {'rxn-list': may_be_frameid(rxn_list), 'pred-list': may_be_frameid(pred_list)} - return self.sendPgdbFnCall('pathway-components', may_be_frameid(pwy), **kwargs) - - def noncontiguous_pathway_p(self, pwy): - """ - Description - A predicate that determines if the pathway contains more than - one connected component. See function pathway-components for - more explanation. - Parms - - pwy - An instance of the class Pathways, a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('noncontiguous-pathway-p', may_be_frameid(pwy)) - - def rxns_adjacent_in_pwy_p(self, rxn1, rxn2, pwy): - """ - Description - A predicate to determine if two given reactions are adjacent to - one another in the given pathway. - Parms - - rxn1 - An instance of the class Reactions, a frame id or PFrame. - rxn2 - An instance of the class Reactions, a frame id or PFrame. - pwy - An instance of the class Pathways, a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('rxns-adjacent-in-pwy-p', may_be_frameid(rxn1), may_be_frameid(rxn2), may_be_frameid(pwy)) - - def cofactors_and_pgroups_of_enzrxn(self, enzrxn): - """ - Description - Returns the cofactors and prosthetic groups of an enzymatic - reaction. - Parms - - enzrxn - An instance of the class Enzymatic-Reactions, a frame id or PFrame. - - Return value - A list of children of class Chemicals or strings, - representing cofactors and/or prosthetic groups. - """ - return self.sendPgdbFnCallList('cofactors-and-pgroups-of-enzrxn', may_be_frameid(enzrxn)) - - def enzrxn_activators(self, er, phys_relevant_only=None): - """ - Description - Returns the list of activators (generally small molecules) of - the enzymatic reaction frame. - Parms - - er - An instance of the class Enzymatic-Reactions, a frame id or PFrame. - phys_relevant_only - Keyword, If True, then only return activators that are - associated with Regulation instances that have the - physiologically-relevant? slot set to True. - - Return value - A list of children of the class Chemicals. - """ - # phys_relevant_only is optional for the Lisp version - return self.sendPgdbFnCallList('enzrxn-activators', may_be_frameid(er), phys_relevant_only) - - def enzrxn_inhibitors(self, er, phys_relevant_only=None): - """ - Description - Returns the list of inhibitors (generally small molecules) of - the enzymatic reaction frame. - Parms - - er - An instance of the class Enzymatic-Reactions, a frame id or PFrame. - phys_relevant_only - Keyword, If True, then only return inhibitors that are - associated with Regulation instances that have the - physiologically-relevant? slot set to True. - - Return value - A list of children of the class Chemicals. - """ - # phys_relevant_only is optional for the Lisp version - return self.sendPgdbFnCallList('enzrxn-inhibitors', may_be_frameid(er), phys_relevant_only) - - def pathways_of_enzrxn(self, enzrxn, include_super_pwys=None): - """ - Description - Returns the list of pathways in which the given enzymatic - reaction participates. - Parms - - enzrxn - An instance of the class Enzymatic-Reactions, a frame id or PFrame. - include_super_pwys - Keyword, If True, then not only will the - direct pathways in which enzrxn is associated in be - returned, but also any enclosing super-pathways. If enzrxn - is associated with a reaction that is directly associated - with a super-pathway, then the function might return - super-pathways even if this option is nil. - - Return value - A list of instances of class Pathways. - """ - kwargs = {'include-super-pwys?': include_super_pwys} - return self.sendPgdbFnCallList('pathways-of-enzrxn', may_be_frameid(enzrxn), **kwargs) - - def pathway_allows_enzrxn(self, pwy, rxn, enzrxn, single_species=None): - """ - Description - A predicate which returns a True value if the given pathway - allows the given enzymatic reaction to catalyze the given - reaction. Certain pathways have a list of enzymatic reactions - that are known not to catalyze certain reactions. See the - documentation of slot-unit enzyme-use for more information. - Parms - - pwy - An instance of the class Pathways, a frame id or PFrame. - rxn - An instance of the class Reactions, a frame id or PFrame. - enzrxn - An instance of the class Enzymatic-Reactions, a frame id or PFrame. - single_species - Keyword, An instance of the class Organisms If set, - then enzrxn has the further stricture that it must be an - enzymatic reaction present in the organism specified by the - value passed to single-species. - - Return value - A boolean value. - """ - # single_species is optional for the Lisp version. - return self.sendPgdbFnCallBool('pathway-allows-enzrxn', may_be_frameid(pwy), may_be_frameid(rxn), may_be_frameid(enzrxn), single_species) - - def monomers_of_protein(self, p, coefficients=None, unmodify=None): - """ - Description - Returns the monomers of the given protein complex. - Parms - - p - An instance of the class Proteins, a frame id or PFrame. - coefficients - Keyword, If True, then the second return value of - the function will be a list of monomer coefficients. - Defaults to True. - unmodify - Keyword, If True, obtain the monomers of the - unmodified form of p. - - Return value - First value is a list of instances of the class Proteins. If - coefficients? is True, then the second value is the - corresponding coefficients of the monomers fromthe first return - value. - """ - kwargs = {'coefficients?': coefficients, 'unmodify?': unmodify} - return self.sendPgdbFnCallList('monomers-of-protein', may_be_frameid(p), **kwargs) - - def base_components_of_protein(self, p, exclude_small_molecules=None): - """ - Description - Same as function monomers-of-protein, but also returns - components of the protein that are RNAs or compounds, not just - polypeptides. - Parms - - p - An instance of the class Proteins, a frame id or PFrame. - exclude_small_molecules - Keyword, If nil, then small molecule components - are also returned. Default value is True. - - Return value - Two values as a list. The first value is a list of the components, which - can be instances of the following classes: Polypeptides, - RNA, and Compounds. The second value is a list of the - corresponding coefficients of the components in the first value. - """ - kwargs = {'exclude-small-molecules?': exclude_small_molecules} - return self.sendPgdbFnCall('base-components-of-protein', may_be_frameid(p), **kwargs) - - def containers_of(self, protein, exclude_self=None): - """ - Description - Return all complexes of which the given protein is a direct or - indirect component. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - exclude_self - Keyword, If True, then protein will not be included in - the return value. - - Return value - A list of instances of the class Proteins. - """ - # exclude_self is an optional parameter for the Lisp fn version. - return self.sendPgdbFnCallList('containers-of', may_be_frameid(protein), exclude_self) - - def protein_or_rna_containers_of(self, protein, exclude_self=None): - """ - Description - This function is the same as the function containers-of, - except that it only includes containers that are instances of - either class Protein-Complexes, or class - Protein-RNA-Complexes. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - exclude_self - Keyword, If True, then protein will not be included in - the return value. - - Return value - A list of instances of the class Proteins. - """ - # exclude_self is an optional parameter for the Lisp fn version. - return self.sendPgdbFnCallList('protein-or-rna-containers-of', may_be_frameid(protein), exclude_self) - - def homomultimeric_containers_of(self, protein, exclude_self=None): - """ - Description - This function is the same as the function containers-of, - except that it only includes containers that are homomultimers. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - exclude_self - Keyword, If True, then protein will not be included in - the return value. - - Return value - A list of instances of the class Proteins. - """ - # exclude_self is an optional parameter for the Lisp fn version. - return self.sendPgdbFnCallList('homomultimeric-containers-of', may_be_frameid(protein), exclude_self) - - def polypeptide_or_homomultimer_p(self, protein): - """ - Description - A predicate that determines if the given protein is a - polypeptide or a homomultimer. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('polypeptide-or-homomultimer-p', may_be_frameid(protein)) - - def unmodified_form(self, protein): - """ - Description - Return the unmodified form of the given protein, which might be - the same as the given protein. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - - Return value - An instance of the class Proteins. - """ - return self.sendPgdbFnCall('unmodified-form', may_be_frameid(protein)) - - def unmodified_or_unbound_form(self, protein): - """ - Description - Return the unmodified form or unbound (to a small molecule) form - of the given protein, which might be the same as the given protein. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - - Return value - An instance of the class Proteins. - """ - return self.sendPgdbFnCall('unmodified-or-unbound-form', may_be_frameid(protein)) - - def reduce_modified_proteins(self, prots, debind=None): - """ - Description - Given a list of proteins, the function converts all of the - proteins to their unmodified form, and then removes any - duplicates from the subsequent list. - Parms - - prots - A list of instances of the class Proteins, a frame id or PFrame. - debind - Keyword, When True, the proteins are further - simplified by obtaining the unbound form of the protein, if - it is bound to a small molecule. - - Return Value - A list of instances of the class Proteins. - """ - kwargs = {'debind?': debind} - return self.sendPgdbFnCallList('reduce-modified-proteins', may_be_frameid(prots), **kwargs) - - def all_direct_forms_of_protein(self, protein): - """ - Description - Given a protein, this function will return all of the directly - related proteins of its modified and unmodified forms, meaning - all of their direct subunits and all of their direct containers. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - - Return Value - A list of instances of the class Proteins. - """ - return self.sendPgdbFnCallList('all-direct-forms-of-protein', may_be_frameid(protein)) - - def all_forms_of_protein(self, protein): - """ - Description - Given a protein, this function will return all of the related - proteins of its modified and unmodified forms, meaning all of - their subunits and all of their containers. Unlike - all_direct_forms_of_protein, this function is not limited to - the direct containers only. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - - Return value - A list of instances of the class Proteins. - """ - return self.sendPgdbFnCallList('all-forms-of-protein', may_be_frameid(protein)) - - def modified_forms(self, protein, exclude_self=None, all_variants=None): - """ - Description - Returns all modified forms of a protein. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - exclude_self - Keyword, If True, then protein will not be included in - the return value. - all_variants - Keyword, If True, and protein is a modified form, then - we return all of the modified forms of the unmodified forms - of protein. - - Return value - A list of instances of the class Proteins. - """ - # Parameters exclude_self and all_variants are optionals for the Lisp fn version. - return self.sendPgdbFnCallList('modified-forms', may_be_frameid(protein), exclude_self, all_variants) - - def modified_and_unmodified_forms(self, protein): - """ - Description - Returns all of the modified and unmodified forms of the given - protein. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - - Return value - A list of instances of the class Proteins. - """ - return self.sendPgdbFnCallList('modified-and-unmodified-forms', may_be_frameid(protein)) - - def modified_containers(self, protein): - """ - Description - Returns all containers of a protein (including itself), and all - modified forms of the containers. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - - Return value - A list of instances of the class Proteins. - """ - return self.sendPgdbFnCallList('modified-containers', may_be_frameid(protein)) - - def top_containers(self, protein): - """ - Description - Return the top-most containers (i.e., they are not a component - of any other protein complex) of the given protein. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - - Return value - A list of instances of the class Proteins. - """ - return self.sendPgdbFnCallList('top-containers', may_be_frameid(protein)) - - def small_molecule_cplxes_of_prot(self, protein): - """ - Description - Return all of the forms of the given protein that are complexes - with small molecules. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - - Return value - A list of instances of the class Proteins. - """ - return self.sendPgdbFnCallList('small-molecule-cplxes-of-prot', may_be_frameid(protein)) - - def genes_of_protein(self, protein): - """ - Description - Given a protein, return the set of genes which encode all of the - monomers of the protein. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - - Return value - A list of instances of the class Genes. - """ - return self.sendPgdbFnCallList('genes-of-protein', may_be_frameid(protein)) - - def genes_of_proteins(self, protein): - """ - Description - The same as genes_of_protein, except that it takes a list of - proteins and returns a set of genes. - Parms - - protein - A list of instances of the class Proteins, a frame id or PFrame. - - Return value - A list of instances of the class Genes. - """ - return self.sendPgdbFnCallList('genes-of-proteins', may_be_frameid(protein)) - - def reactions_of_enzyme(self, protein, kb=None, include_specific_forms=None): - """ - Description - Return all of the reactions associated with a given protein via - enzymatic reactions. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - kb - Keyword, The KB object of the KB in which to find - the associated reactions. Defaults to self. - include_specific_forms - Keyword, When True, specific forms of associated - generic reactions are also returned. Default value is True. - - Return value - A list of instances of the class Reactions. - """ - kwargs = {'kb': kb, 'include-specific-forms?': include_specific_forms} - return self.sendPgdbFnCallList('reactions-of-enzyme', may_be_frameid(protein), **kwargs) - - def species_of_protein(self, protein): - """ - Description - Get the associated species for the given protein. - Parms - - protein - A list of instances of the class Proteins, a frame id or PFrame. - - Return value - An instance of the class Organisms, or a string. - """ - return self.sendPgdbFnCall('species-of-protein', may_be_frameid(protein)) - - def enzyme_p(self, protein, type=None): - """ - Description - Predicate that determines whether a specified protein is an - enzyme or not. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - type - Keyword, Can take on one of the following values to select - more precisely what is meant by an "enzyme": - - 'any' - Any protein that catalyzes a reaction is considered an - enzyme. - 'chemical-change' - If the reactants and products of the catalyzed reactin - differ, and not just by their cellular location, then - the protein is considered an enzyme. - 'small-molecule' - If the reactants of the catalyzed reaction differ and - are small molecules, then the protein is considered an - enzyme. - 'transport' - If the protein catalyzes a transport reaction. - 'non-transport' - If the protein only catalyzes non-transport reactions. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('enzyme-p', may_be_frameid(protein), mkey(type)) - - def leader_peptide_p(self, protein): - """ - Description - A predicate that determines whether the given protein is a - leader peptide. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('leader-peptide-p', may_be_frameid(protein)) - - def protein_p(self, frame): - """ - Description - A predicate that determines whether the given frame is a protein. - Parms - - frame - a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('protein-p', may_be_frameid(frame)) - - def complex_p(self, frame): - """ - Description - A predicate that determines whether the given frame is a - protein complex. - Parms - - frame - a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('complex-p', may_be_frameid(frame)) - - def reactions_of_protein(self, protein, check_protein_components=None, - check_protein_containers=None): - """ - Description - Returns all of the associated reactions that the given protein, - or its components, catalyzes. - Parms - - protein - An instance of the class Proteins, a frame id or PFrame. - check_protein_components? - Keyword, If True, check all components of this protein for - catalyzed reactions. Defaults to True. - check_protein_containers? - Keyword, If True, check the containers and modified forms - of the protein for catalyzed reactions. - - Return value - A list of instances of class Reactions. - """ - return self.sendPgdbFnCallList('reactions-of-protein', may_be_frameid(protein), - check_protein_components, check_protein_containers) - - def protein_in_compartment_p(self, rxn, compartments, default_ok=None, pwy=None, loose=None): - """ - Description - A predicate that checks if the given reaction is present in a - list of cellular compartments. - Parms - - rxn - An instance of the class Reactions, a frame id or PFrame. - compartments - A list of cellular compartments, as defined in the Cellular - Components Ontology. See frame CCO. - default_ok - Keyword, If True, then we return True if the - reaction has no associated compartment information, or one - of its associated locations is a super-class of one of the - members of the compartments parameter. - pwy - Keyword, a frame id or PFrame. If supplied, the search for associated - enzymes of the parameter rxn is limited to the given child - of Pathways. - loose - Keyword, If True, then the compartments - CCO-CYTOPLASM and CCO-CYTOSOL are treated as being the - same compartment. - - Return value - A boolean value. - """ - kwargs = {'default-ok?': default_ok, 'pwy': may_be_frameid(pwy), 'loose?': loose} - return self.sendPgdbFnCallBool('protein-in-compartment-p', may_be_frameid(rxn), **kwargs) - - def all_transporters_across(self, membranes=None, method=None): - """ - Description - Returns a list of transport proteins that transport across one - of the given membranes. - Parms - membranes - Keyword, Either all or a list of instances of the class. - Defaults to all CCO-MEMBRANE. - method - Keyword, - Either 'location' or 'reaction-compartments'. 'location' - will check the locations slot, while - 'reaction-compartments' will examine the compartments of - reaction substrates. Default value is 'location'. - - Return value - A list of instances of class Proteins. - """ - kwargs = {'membranes': may_be_frameid(membranes), 'method': method} - return self.sendPgdbFnCallList('all-transporters-across', **kwargs) - - def autocatalytic_reactions_of_enzyme(self, protein): - """ - Description - Returns a list of reaction frames, where the protein - participates as a substrate of the reaction, and the reaction - has no associated Enzymatic Reaction frame. This implies that - the protein substrate of the reaction might autocatalyzing the - reaction. - Parms - protein - An instance frame of class Proteins, a frame id or PFrame. - - Return value - A list of instances of class Reactions. - """ - return self.sendPgdbFnCallList('autocatalytic-reactions-of-enzyme', may_be_frameid(protein)) - - def gene_p(self, item): - """ - Description - A predicate to determine if the given frame is a gene. - Parms - item - a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('gene-p', may_be_frameid(item)) - - def enzymes_of_gene(self, gene): - """ - Description - Collects all of the enzymes encoded by the given gene, including - modified forms and complexes in which it is a sub-component. - Parms - gene - An instance of class Genes, a frame id or PFrame. - - Return value - A list of instances of class Proteins. - """ - return self.sendPgdbFnCallList('enzymes-of-gene', may_be_frameid(gene)) - - def all_products_of_gene(self, gene): - """ - Description - Collects all proteins (not necessarily enzymes) that are encoded - by the given gene. - Parms - gene - An instance of class Genes, a frame id or PFrame. - - Return value - A list of instances of class Proteins. - """ - return self.sendPgdbFnCallList('all-products-of-gene', may_be_frameid(gene)) - - def reactions_of_gene(self, gene): - """ - Description - Returns all reactions catalyzed by enzymes encoded by the given - gene. - Parms - gene - An instance of class Genes, a frame id or PFrame. - - Return value - A list of instances of class Reactions. - """ - return self.sendPgdbFnCallList('reactions-of-gene', may_be_frameid(gene)) - - def pathways_of_gene(self, gene, include_super_pwys=None): - """ - Description - Returns the pathways of enzymes encoded by the given gene. - Parms - gene - An instance of class Genes, a frame id or PFrame. - include_super_pwys - Keyword, If True, then not only will the - direct pathways in which gene encodes an enzyme be - returned, but also any enclosing super-pathways. If gene - is associated with a reaction that is directly associated - with a super-pathway, then the function might return - super-pathways even if this option is nil. - - Return value - A list of instances of class Pathways. - """ - kwargs = {'include-super-pwys': include_super_pwys} - return self.sendPgdbFnCallList('pathways-of-gene', may_be_frameid(gene), **kwargs) - - def chromosome_of_gene(self, gene): - """ - Description - Returns the replicon on which the gene is located. If the gene - is located on a contig that is, in turn, part of a chromosome, - then the contig is returned. - Parms - gene - An instance of class Genes, a frame id or PFrame. - - Return value - An instance of class Genetic-Elements. - """ - return self.sendPgdbFnCall('chromosome-of-gene', may_be_frameid(gene)) - - def unmodified_gene_product(self, gene): - """ - Description - Returns the first element of the list returned by the function - unmodified-gene-products. This is useful if you are sure that - there are no alternative splice forms of your gene. - Parms - gene - An instance of class Genes, a frame id or PFrame. - - Return value - An instance of either class Polypeptides or 'RNA. - """ - return self.sendPgdbFnCall('unmodified-gene-product', may_be_frameid(gene)) - - def unmodified_gene_products(self, gene): - """ - Description - Return all of the unmodified gene products (i.e. alternative - splice forms) of the given gene. - Parms - gene - An instance of class Genes, a frame id or PFrame. - - Return value - A list of instances of either class Polypeptides or 'RNA. - """ - return self.sendPgdbFnCallList('unmodified-gene-products', may_be_frameid(gene)) - - def next_gene_on_replicon(self, gene): - """ - Description - Return the next gene on the replicon. - Parms - gene - An instance of class Genes, a frame id or PFrame. - - Return value - Returns two values as a list. The first value is the next gene, or nil if - there is not a next gene (i.e., the gene is at the end of a - linear replicon). The second value is 'last' if the gene is the - last gene on a linear replicon. - """ - return self.sendPgdbFnCall('next-gene-on-replicon', may_be_frameid(gene)) - - def previous_gene_on_replicon(self, gene): - """ - Description - Return the previous gene on the replicon. - Parms - gene - An instance of class Genes, a frame id or PFrame. - - Return value - Returns two values as a list. The first value is the previous gene, or nil - if there is not a previous gene (i.e., the gene is at the - beginning of a linear replicon). The second value is 'first' if - the gene is the first gene on a linear replicon. - """ - return self.sendPgdbFnCall('previous-gene-on-replicon', may_be_frameid(gene)) - - def adjacent_genes_p(self, g1, g2): - """ - Description - Given two genes, this predicate will return True if they are on - the same replicon, and adjacent to one another. - Parms - g1 - An instance of class Genes, a frame id or PFrame. - g2 - An instance of class Genes, a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('adjacent-genes?', may_be_frameid(g1), may_be_frameid(g2)) - - def neighboring_genes_p(self, g1, g2, n=None): - """ - Description - Given two genes, this predicate determines if the two genes are - "neighbors", or within a certain number of genes from one - another along the replicon. - Parms - g1 - An instance of class Genes, a frame id or PFrame. - g2 - An instance of class Genes, a frame id or PFrame. - n - Keyword, An integer representing the number of genes g1 - and g2 can be from one another. Default value is 10. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('neighboring-genes-p', may_be_frameid(g1), may_be_frameid(g2), n) - - def gene_clusters(self, genes, max_gap=None): - """ - Description - Groups together genes based on whether each gene is a gene - neighbor with other genes. - Parms - genes - A list of instances of class Genes, a frame id or PFrame. - max_gap - Keyword, An integer representing the number of genes any - pair from genes can be from one another. Default value is 10. - - Return value - A list of lists, where the first element of each sub-list is a - gene from genes, and the rest of the list are all of the gene - neighbors of the first gene. - """ - return self.sendPgdbFnCallList('gene-clusters', may_be_frameid(genes), max_gap) - - def rna_coding_gene(self, gene): - """ - Description - A predicate that determines if the given gene encodes an RNA. - Parms - gene - An instance of the class Genes, a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('rna-coding-gene', may_be_frameid(gene)) - - def protein_coding_gene(self, gene): - """ - Description - A predicate that determines if the given gene encodes a protein - (as opposed to an RNA). - Parms - gene - An instance of the class Genes, a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('protein-coding-gene', may_be_frameid(gene)) - - def pseudo_gene_p(self, gene): - """ - Description - A predicate that determines if the given gene is a pseudo-gene. - Parms - gene - An instance of the class Genes, a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('pseudo-gene-p', may_be_frameid(gene)) - - def phantom_gene_p(self, gene): - """ - Description - A predicate that determines if the given gene is a phantom gene. - Parms - gene - An instance of the class Genes, a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('phantom-gene-p', may_be_frameid(gene)) - - def dna_binding_site_p(self, gene): - """ - Description - A predicate that determines if the given frame is an instance of - the class DNA-Binding-Sites. - Parms - gene - A frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('dna-binding-site-p', may_be_frameid(gene)) - - def terminator_p(self, gene): - """ - Description - A predicate that determines if the given object is an instance - of the class Terminators. - Parms - gene - A frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('terminatorp', may_be_frameid(gene)) - - def operon_of_gene(self, gene): - """ - Description - Given a gene, return a list of transcription units that form the - operon containing the gene. - Parms - gene - An instance of class Genes, a frame id or PFrame - - Return value - A list of instances of class Transcription-Units. - """ - return self.sendPgdbFnCallList('operon-of-gene', may_be_frameid(gene)) - - def genes_in_same_operon(self, gene): - """ - Description - Given a gene, return all other genes in the same operon. - Parms - gene - An instance of class Genes, a frame id or PFrame. - - Return value - A list of instances of class Genes. - """ - return self.sendPgdbFnCallList('genes-in-same-operon', may_be_frameid(gene)) - - def gene_transcription_units(self, gene): - """ - Description - Given a gene, return all of the transcription units which - contain the gene. - Parms - gene - An instance of class Genes, a frame id or PFrame - - Return value - A list of instances of class Transcription-Units. - """ - return self.sendPgdbFnCallList('gene-transcription-units', may_be_frameid(gene)) - - def cotranscribed_genes(self, gene): - """ - Description - Return all co-transcribed genes (i.e., genes which are a part of - one or more of the same transcription units) of the given gene. - Parms - gene - An instance of class Genes, a frame id or PFrame - - Return value - A list of instances of class Genes. - """ - return self.sendPgdbFnCallList('cotranscribed-genes', may_be_frameid(gene)) - - def terminators_affecting_gene(self, gene): - """ - Description - Find terminators in the same transcription unit and upstream of - the given gene. - Parms - gene - An instance of class Genes, a frame id or PFrame - - Return value - A list of instances of class Terminators. - """ - return self.sendPgdbFnCallList('terminators-affecting-gene', may_be_frameid(gene)) - - def chromosome_of_object(self, item): - """ - Description - Given a frame object, the replicon where it is located is returned. - If there is no associated replicon for the object, nil is - returned. If the object is on more than one replicon, an error - is thrown. - Parms - item, a frame id or PFrame - An instance of class All-Genes, Transcription-Units, - Promoters, Terminators, Misc-Features, or - DNA-Binding-Sites. - - Return value - An instance of class Genetic-Elements. - """ - return self.sendPgdbFnCall('chromosome-of-object', may_be_frameid(item)) - - def activation_p(self, reg_frame): - """ - Description - A predicate that determines if a given regulation frame is - describing activation. - Parms - reg_frame - An instance of class Regulation, a frame id or PFrame - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('activation-p', may_be_frameid(reg_frame)) - - def inhibition_p(self, reg_frame): - """ - Description - A predicate that determines if a given regulation frame is - describing inhibition. - Parms - reg_frame - An instance of class Regulation, a frame id or PFrame - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('inhibition-p', may_be_frameid(reg_frame)) - - def direct_regulators(self, item, filter_fn=None): - """ - Description - Return all regulators that are connected to a regulated object - by a single regulation object. - Parms - item - A frame id or PFrame. - filter_fn - Keyword, A predicate used to filter the regulation objects - used to find the regulators. - - Return value - A list of frames that regulate item. - """ - kwargs = {'filter-fn': filter_fn} - return self.sendPgdbFnCallList('direct-regulators', may_be_frameid(item), **kwargs) - - def direct_activators(self, item): - """ - Description - Return all activators that are connected to an activated object - by a single regulation object. - Parms - item - A frame id or PFrame. - - Return value - A list of frames that activate item. - """ - return self.sendPgdbFnCallList('direct-activators', may_be_frameid(item)) - - def direct_inhibitors(self, item): - """ - Description - Return all inhibitors that are connected to an inhibited object - by a single regulation object. - Parms - item - A frame id or PFrame. - - Return value - A list of frames that inhibit item. - """ - return self.sendPgdbFnCallList('direct-inhibitors', may_be_frameid(item)) - - def transcription_factor_p(self, protein, include_inactive=None): - """ - Description - A predicate that determines if the given protein is a - transcription factor, or a component of a transcription factor. - Parms - protein - An instance frame of class Proteins, a frame id or PFrame. - include_inactive - Keyword, If True, then the function checks to see - if any of its components or containers is a transcription - factor as well. - - Return value - A boolean value. - """ - kwargs = {'include-inactive?': include_inactive} - return self.sendPgdbFnCallBool('transcription-factor-p', may_be_frameid(protein), **kwargs) - - def regulator_of_type(self, protein, class_name): - """ - Description - A predicate that determines if the given protein is a regulator - of the specified class. - Parms - protein - An instance frame of class Proteins, a frame id or PFrame. - class - A subclass of Regulation. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('regulator-of-type', may_be_frameid(protein), class_name) - - def regulon_of_protein(self, protein): - """ - Description - Returns all transcription units regulated by any form of the - given protein. - Parms - protein - An instance frame of class Proteins, a frame id or PFrame. - - Return value - A list of instances of the class Transcription-Units. - """ - return self.sendPgdbFnCallList('regulon-of-protein', may_be_frameid(protein)) - - def regulation_frame_transcription_units(self, reg_frame): - """ - Description - Given a regulation object, return the transcription units when - one of the regulated entities is a promoter or terminator of the - transcription unit. - Parms - reg_frame - An instance of the class Regulation-of-Transcription, a frame id or PFrame. - - Return value - A list of instances of the class Transcription-Units. - """ - return self.sendPgdbFnCallList('regulation-frame-transcription-units', may_be_frameid(reg_frame)) - - def transcription_unit_regulation_frames(self, tu): - """ - Description - Returns a list of regulation frames that regulate the - transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - A list of instances of the class Regulation. - """ - return self.sendPgdbFnCallList('transcription-unit-regulation-frames', may_be_frameid(tu)) - - def transcription_unit_activation_frames(self, tu): - """ - Description - Returns a list of regulation frames that activate the - transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - A list of instances of the class Regulation. - """ - return self.sendPgdbFnCallList('transcription-unit-activation-frames', may_be_frameid(tu)) - - def transcription_unit_inhibition_frames(self, tu): - """ - Description - Returns a list of regulation frames that inhibit the - transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - A list of instances of the class Regulation. - """ - return self.sendPgdbFnCallList('transcription-unit-inhibition-frames', may_be_frameid(tu)) - - def transcription_units_of_protein(self, protein): - """ - Description - Return all of the transcription units for which the given - protein, or its modified form, acts as a regulator. - Parms - protein - An instance of the class Proteins, a frame id or PFrame. - - Return value - A list of instances of the class Transcription-Units. - """ - return self.sendPgdbFnCallList('transcription-units-of-protein', may_be_frameid(protein)) - - def genes_regulated_by_protein(self, protein): - """ - Description - Return all of the genes for which the given protein, or its - modified form, acts as a regulator. - Parms - protein - An instance of the class Proteins, a frame id or PFrame. - - Return value - A list of instances of the class Genes. - """ - return self.sendPgdbFnCallList('genes-regulated-by-protein', may_be_frameid(protein)) - - def DNA_binding_sites_of_protein(self, tf, all_forms=None): - """ - Description - Given a transcription factor, return all of its DNA binding sites. - Parms - tf - An instance of the class Proteins, a frame id or PFrame. - all_forms - Keyword, When True, then return the DNA binding - sites of modified forms and subunits of tf as well. - - Return value - A list of instances of the class DNA-Binding-Sites. - """ - kwargs = {'all-forms?': all_forms} - return self.sendPgdbFnCallList('DNA-binding-sites-of-protein', may_be_frameid(tf), **kwargs) - - def regulator_proteins_of_transcription_unit(self, tu): - """ - Description - Returns all transcription factors that regulate the given - transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - A list of instances of the class Proteins. - """ - return self.sendPgdbFnCallList('regulator-proteins-of-transcription-unit', may_be_frameid(tu)) - - def transcription_factor_ligands(self, tfs, mode): - """ - Description - For a single transcription factor or list of transcription - factors, return all transcription factor ligands. - Parms - tfs, a frame id or PFrame or a list of these. - An instance or a list of instances of the class - Proteins. If tfs is not the active form, then the - active form is determined automatically. - mode - One of the following values: 'activator', 'inhibitor', or - 'both'. - - Return value - A list of instances of the class Chemicals or strings. - """ - return self.sendPgdbFnCallList('transcription-factor-ligands', may_be_frameid(tfs), mkey(mode)) - - def transcription_factor_active_forms(self, tfs): - """ - Description - For a given transcription factor, find all active forms (i.e, - form of the protein that regulates) of the transcription factor. - Parms - tfs, a frame id or PFrame. - An instance of the class Proteins. - - Return value - A list of instances of the class Proteins. - """ - return self.sendPgdbFnCallList('transcription-factor-active-forms', may_be_frameid(tfs)) - - def genes_regulating_gene(self, gene): - """ - Description - Return all genes regulating the given gene by means of a - transcription factor. - Parms - gene - An instance of the class Genes, a frame id or PFrame. - - Return value - A list of instances of class Genes. - """ - return self.sendPgdbFnCallList('genes-regulating-gene', may_be_frameid(gene)) - - def genes_regulated_by_gene(self, gene): - """ - Description - Return all genes regulated by the given gene by means of a - transcription factor. - Parms - gene - An instance of the class Genes, a frame id or PFrame. - - Return value - A list of instances of class Genes. - """ - return self.sendPgdbFnCallList('genes-regulated-by-gene', may_be_frameid(gene)) - - def regulators_of_gene_transcription(self, gene, by_function=None): - """ - Description - Returns a list of proteins that are regulators of the given gene. - Parms - gene - An instance of the class Genes, a frame id or PFrame. - by_function - Keyword, If True, then return two values: a list of - activator proteins and a list of inhibitor proteins. - - Return value - A list of instances of class Proteins. If by_function is - True, then two values are returned. The first value is a list - of activator proteins, and the second value is a list of - inhibitor proteins. - """ - kwargs = {'by-function?' : by_function} - return self.sendPgdbFnCall('regulators-of-gene', may_be_frameid(gene), **kwargs) - - def transcription_unit_activators(self, tu): - """ - Description - Returns all activator proteins of the given transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - A list of instances of class Proteins. - """ - return self.sendPgdbFnCallList('transcription-unit-activators', may_be_frameid(tu)) - - def transcription_unit_inhibitors(self, tu): - """ - Description - Returns all inhibitor proteins of the given transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - A list of instances of class Proteins. - """ - return self.sendPgdbFnCallList('transcription-unit-inhibitors', may_be_frameid(tu)) - - def regulators_of_operon_transcription(self, operon_list, by_function=None): - """ - Description - Returns a list of transcription factors of an operon. - Parms - operon_list - A list of instances of the class Transcription-Units, a frame id or PFrame. - by_function - Keyword, If True, then return two values: a list of - activator proteins and a list of inhibitor proteins. - - Return value - A list of instances of class Proteins. If the modified form - of the protein is the transcription factor, then that is the - protein returned. - """ - # Parameter by_function is optional for the Lisp fn. - return self.sendPgdbFnCallList('regulators-of-operon-transcription', may_be_frameid(operon_list), by_function) - - def transcription_unit_promoter(self, tu): - """ - Description - Returns the promoter of the given transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - An instance of class Promoters. - """ - return self.sendPgdbFnCall('transcription-unit-promoter', may_be_frameid(tu)) - - def transcription_unit_genes(self, tu): - """ - Description - Returns the genes of the given transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - A list of instances of class Genes. - """ - return self.sendPgdbFnCallList('transcription-unit-genes', may_be_frameid(tu)) - - def transcription_unit_first_gene(self, tu): - """ - Description - Returns the first gene of the given transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - An instance of class Genes. - """ - return self.sendPgdbFnCall('transcription-unit-first-gene', may_be_frameid(tu)) - - def transcription_unit_binding_sites(self, tu): - """ - Description - Returns the binding sites of the given transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - A list of instances of class DNA-Binding-Sites. - """ - return self.sendPgdbFnCallList('transcription-unit-binding-sites', may_be_frameid(tu)) - - def transcription_unit_transcription_factors(self, tu): - """ - Description - Returns the binding sites of the given transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - A list of instances of class DNA-Binding-Sites. - """ - return self.sendPgdbFnCallList('transcription-unit-transcription-factors', may_be_frameid(tu)) - - def transcription_unit_mrna_binding_sites(self, tu): - """ - Description - Returns the mRNA binding sites of the given transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - A list of instances of class mRNA-Binding-Sites. - """ - return self.sendPgdbFnCallList('transcription-unit-mrna-binding-sites', may_be_frameid(tu)) - - def chromosome_of_operon(self, tu): - """ - Description - Returns the replicon of the given transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - An instance of class Genetic-Elements. - """ - return self.sendPgdbFnCall('chromosome-of-operon', may_be_frameid(tu)) - - def binding_sites_affecting_gene(self, gene): - """ - Description - Returns all binding sites which are present in the same - transcription units as the given gene. - Parms - gene - An instance of the class Genes, a frame id or PFrame. - - Return value - A list of instances of class DNA-Binding-Sites. - """ - return self.sendPgdbFnCallList('binding-sites-affecting-gene', may_be_frameid(gene)) - - def binding_site_to_regulators(self, bsite): - """ - Description - Returns all of the transcription factors of the given binding site. - Parms - bsite - An instance of class DNA-Binding-Sites, a frame id or PFrame. - - Return value - A list of instances of class Proteins. - """ - return self.sendPgdbFnCallList('binding-site->regulators', may_be_frameid(bsite)) - - def transcription_units_of_promoter(self, promoter): - """ - Description - Returns all transcription units of a given promoter. - Parms - promoter - An instance of class Promoters, a frame id or PFrame. - - Return value - A list of instances of class Transcription-Units. - """ - return self.sendPgdbFnCallList('transcription-units-of-promoter', may_be_frameid(promoter)) - - def promoter_binding_sites(self, promoter): - """ - Description - Returns all of the binding sites associated with the given - promoter, across multiple transcription units. - Parms - promoter - An instance of class Promoters, a frame id or PFrame. - - Return value - A list of instances of class DNA-Binding-Sites. - """ - return self.sendPgdbFnCallList('promoter-binding-sites', may_be_frameid(promoter)) - - def transcription_unit_terminators(self, operon): - """ - Description - Returns the terminators of the given transcription unit. - Parms - operon - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - A list of instances of class Terminators. - """ - return self.sendPgdbFnCallList('transcription-unit-terminators', may_be_frameid(operon)) - - def containing_tus(self, site): - """ - Description - Given a site (whether a DNA binding site, a promoter, a gene, or - a terminator) along a transcription unit, return the - correspodning transcription units. - Parms - site, a frame id or PFrame. - An instance of class Transcription-Units, - mRNA-Binding-Sites, DNA-Binding-Sites, - Promoters, Genes, or Terminators. - - Return value - A list of instances of class Transcription-Units. - """ - return self.sendPgdbFnCallList('containing-tus', may_be_frameid(site)) - - def containing_chromosome(self, site): - """ - Description - Given a site (whether a DNA binding site, a promoter, a gene, or - a terminator) along a transcription unit, return the - correspodning regulon. - Parms - site, a frame id or PFrame. - An instance of class Transcription-Units, - mRNA-Binding-Sites, DNA-Binding-Sites, - Promoters, Genes, or Terminators. - - Return value - An instance of class Genetic-Elements. - """ - return self.sendPgdbFnCall('containing-chromosome', may_be_frameid(site)) - - def binding_site_promoters(self, tu): - """ - Description - Returns the promoters of the given DNA binding site. - Parms - tu - An instance of the class DNA-Binding-Sites, a frame id or PFrame. - - Return value - A list of instances of class Promoters. - """ - return self.sendPgdbFnCallList('binding-site-promoters', may_be_frameid(tu)) - - def transcription_unit_all_components(self, tu): - """ - Description - Returns all components (binding sites, promoters, genes, - terminators) of the given transcription unit. - Parms - tu - An instance of the class Transcription-Units, a frame id or PFrame. - - Return value - A list of instances of class Transcription-Units, - mRNA-Binding-Sites, DNA-Binding-Sites, Promoters, - Genes, or Terminators. - """ - return self.sendPgdbFnCallList('transcription-unit-all-components', may_be_frameid(tu)) - - def binding_site_transcription_units(self, promoter): - """ - Description - Returns all transcription units of a given binding site. - Parms - promoter, a frame id or PFrame. - An instance of class DNA-Binding-Sites or - mRNA-Binding-Sites. - - Return value - A list of instances of class Transcription-Units. - """ - return self.sendPgdbFnCallList('binding-site-transcription-units', may_be_frameid(promoter)) - - def reactions_of_compound(self, cpd, non_specific_too=None,transport_only=None,compartment=None,enzymatic=None): - """ - Description - Return all reactions in which the given compound participates as - a substrate. - Parms - cpd, a frame id or PFrame. - A child of class Compounds. - non_specific_too - Keyword, If True, returns all generic - reactions where cpd, or a parent of cpd, appears as a - substrate. - transport_only - Keyword, If True, return only transport reactions. - compartment - Keyword, If True, return only reactions within - the specified compartment. - enzymatic - Keyword, If True, return only enzymatic reactions. - - Return value - A list of children of class Reactions. - """ - kwargs = {'non-specific-too?': non_specific_too, - 'transport-only?': transport_only, - 'compartment': compartment, - 'enzymatic?': enzymatic } - return self.sendPgdbFnCallList('reactions-of-compound', may_be_frameid(cpd), **kwargs) - - def substrate_of_generic_rxn(self, cpd, rxn): - """ - Description - A predicate that determines if a parent of the given compound is - a substrate of the given generic reaction. - Parms - cpd - An instance of class Compounds, a frame id or PFrame. - rxn - An instance of class Reactions, a frame id or PFrame. - - Return value - A boolean value. - """ - return self.sendPgdbFnCallBool('substrate-of-generic-rxn', may_be_frameid(cpd), may_be_frameid(rxn)) - - def pathways_of_compound(self, cpd, non_specific_too=None, modulators=None, phys_relevant=None, include_rxns=None): - """ - Description - Returns all pathways in which the given compound appears as a - substrate. - Parms - cpd - An instance of class Compounds, a frame id or PFrame. - non-specific_too - Keyword, If True, returns all generic - reactions where cpd, or a parent of cpd, appears as a - substrate. - modulators - Keyword, If True, returns pathways where cpd - appears as a regulator as well. - phys-relevant - Keyword, If True, then only return inhibitors - that are associated with Regulation instances that have - the physiologically-relevant? slot set to True. - include-rxns - Keyword, If True, then return a list of - reaction-pathway pairs. - - Return value - A list of instances of class Pathways. If include-rxns? is - True, then a list of lists, where each sub-list consists of - an instance of class Reactions and an instance of class - Pathways. - """ - kwargs = {'non-specific-too?': non_specific_too, - 'modulators?': modulators, - 'phys-relevant?': phys_relevant, - 'include-rxns?': include_rxns } - return self.sendPgdbFnCallList('pathways-of-compound', may_be_frameid(cpd), **kwargs) - - def deactivated_or_inhibited_by_compound(self, cpds, mode=None, mechanisms=None, phys_relevant=None, slots=None): - """ - Description - Returns all pathways in which the given compound appears as a - substrate. - Parms - cpds - An instance or list of instances of class Compounds, a frame id or PFrame. - mode - Keyword, Represents the type of regulation. Can - take on the values of "+", "-", or None. - mechanisms - Keyword, Keywords from the mechanism slot of - the corresponding sub-class of the class Regulation. If - True, only regulation objects with mechanisms in this - list will be explored for regulated objects. - phys_relevant - Keyword, If True, then only return inhibitors - that are associated with Regulation instances that have - the physiologically-relevant? slot set to True. - slots - Keyword, A list of enzymatic reaction slots. - - Return value - A list of instances of class Enzymatic-Reactions. - """ - kwargs = {'mode': mode, - 'mechanisms': mechanisms, - 'phys-relevant?': phys_relevant, - 'slots': slots } - return self.sendPgdbFnCallList('deactivated-or-inhibited-by-compound', may_be_frameid(cpds), **kwargs) - - def tfs_bound_to_compound(self, cpd, include_inactive=None): - """ - Description - Returns a list of protein complexes that, when bound to the - given compound, act as a transcription factor. - Parms - cpd - An instance of class Compounds, a frame id or PFrame. - include_inactive - Keyword, If True, then the inactive form of - the protein is also checked. See the function - transcription-factor? for more information. - - Return value - A list of instances of class Proteins. - """ - kwargs = {'include-inactive?': include_inactive} - return self.sendPgdbFnCallList('tfs-bound-to-compound', may_be_frameid(cpd), **kwargs) - - - def get_name_string(self, item, rxn_eqn_as_name=None, rxn_common_name_as_name=None, - direction=None, name_slot=None, strip_html=None, - include_species_strain_name=None, - italicize_species=None, short_name=None, - species_initials=None, primary_class=None): - """ - Description - Given an object, compute the string name. The method used to - compute the name varies per the object class. - Parms - item - A frame id or PFrame. - rxn_eqn_as_name - Keyword, If True, then we use the reaction - equation in string form as the name of the reaction. - Defaults to True. - rxn_common_name_as_name - Keyword, If True, then we use the reaction's - common name as the name of the reaction. - direction - Keyword, An argument of 'l2r' or 'r2l' can be - given to specify the desired reaction orientiation when - printed in reaction equation form. If this is not provided, - then the reaction direction will be determined using pathway - evidence. - name_slot - Keyword, The specified slotunit frame name, as a - symbol, will be used for extracting the name of the frame. - strip_html - Keyword, Remove any HTML mark-up from the string - form of the object name. - include_species_strain_name - Keyword, Provide proper italicization for the - organism strain name. - italicize_species - Keyword, Provide proper italicization for the - organism species name. - short_name - Keyword, If the ABBREV-NAME slot is populated - for the frame, then its value will be used. - species_initials - Keyword, Print the name of the organism as initials. - primary_class - Keyword, Specify explicitly the primary class of - the given frame. This can be used to override the internal - reasoning of this function, and you can give a suggestion to - the function to treat the frame as another class. - - Return value - A string representing the name of the frame. - """ - kwargs = {'rxn-eqn-as-name': rxn_eqn_as_name, - 'rxn-common-name-as-name': rxn_common_name_as_name, - 'direction': direction, - 'name-slot': name_slot, - 'strip-html?': strip_html, - 'include-species-strain-name?': include_species_strain_name, - 'italicize-species?': italicize_species, - 'short-name?': short_name, - 'species-initials': species_initials, - 'primary-class': Symbol(primary_class)} - return self.sendPgdbFnCall('get-name-string', may_be_frameid(item), **kwargs) - - def full_enzyme_name(self, enzyme, use_frame_name=None, name=None, activity_names=None): - """ - Description - Compute the full name of an enzyme as the concatenation of the - common name of the protein followed by the common names of its - enzymatic reactions. Note that two enzrxns for the same enzyme - could have the same common name, so we avoid including the same - name twice. - Parms - enzyme - An instance of the class Proteins, that is, a frame id or a PFrame. - use_frame_name - Keyword, If True, then the frameid of the enzyme - instance is used in computing the enzyme name. Defaults to - True. - name - Keyword, A string that bypasses the function, and will be - returned as the value of the function. - activity_names - Keyword, A provided list of strings, that represent the - names of the known catalytic activities of enzyme. - - Return value - A string. - """ - # Parameters use_frame_name, name and activity_names are optional for the Lisp fn version. - return self.sendPgdbFnCall('full-enzyme-name', may_be_frameid(enzyme), use_frame_name, - name, activity_names) - - def enzyme_activity_name(self, enzyme, reaction=None): - """ - Description - Computes the name of an enzyme in the context of a particular - reaction. If the reaction is not provided, then we return the - full enzyme name. - - Parms - enzyme - An instance of the class Proteins, that is, a frame id or a PFrame. - reaction - Keyword, An instance of the class Reactions. - - Return value - A string. - """ - # Parameter reaction is optional for the Lisp fn version. - return self.sendPgdbFnCall('enzyme-activity-name', may_be_frameid(enzyme), may_be_frameid(reaction)) - - + """ + Please consult the the tutorial.html file under the doc directory + for an introduction on how to use this class. + """ + + def __init__(self, orgid): + """ + Once a PGDB object is created, it has been validated that the organism (orgid) + exists on the running Pathway Tools server. From that PGDB object (e.g. ecoli), + many classes of objects can be retrieved by using the attribute syntax of + Python, such as ecoli.reactions. + """ + if pythoncyc.config._debug: + print("PGDB __init__") + self._orgid = "unknown" + self._error = False + + # All PFrame objects of the PGDB are stored in attribute _frames, keyed by their frame ids. + self._frames = {} + + # Verify that the running Pathway Tools has the PGDB (organism). + try: + r = PTools.sendQueryToPTools('(orgid-exist-p \'' + orgid + ')') + except PToolsError as msg: + raise PythonCycError('Pathway Tools was unable to verify if organism (orgid) {:s} is known in your running Pathway Tools. More specifically: {:s}'.format(orgid, msg)) + if not r: + raise PythonCycError("The organism orgid {:s} is unknown. Use pythoncyc.all_orgids() to get a list of known orgids.".format(orgid)) + self._error = True + else: + self._orgid = orgid + return None + + def __getinitargs__(self): + """ For the Pickle module. """ + return (self._orgid, ) + + def __getstate__(self): + """ For the Pickle module """ + return self.__dict__.copy() + + def __setstate__(self, dict): + """ For the Pickle module """ + self.__dict__ = dict + + def __repr__(self): + return self.__str__() + + def __str__(self): + return '' + + def __dir__(self): + return (dir(self.__class__) + self.__dict__.keys()) + + def _nb_pframes(self): + """ + Return the number of PFrame objects accessible as attributes for a PGDB object. + """ + return len(self._frames) + + def __setattr__(self, attr, val): + if attr.startswith('_'): + self.__dict__[attr] = val + return None + attrId = convertLispIdtoPythonId(attr) + if isinstance(val, PFrame): + self._frames[attrId] = val + else: + self.__dict__[attrId] = val + return None + + def __getattr__(self, attr): + """ + Attributes for a PGDB may refer to frame ids. A frame id that has dashes in + Pathway Tools, is converted to attribute with underscores '_' instead. If an + attribute does not exist yet, a request to Pathway Tools is done to verify if it + may exist as an instance or as a class. PFrame instances and classes are created + automatically when the corresponding instances or classes exist in the PGDB. + """ + if pythoncyc.config._debug: + print("PGDB ", self._orgid, "__getattr__", attr) + + # If the converted attribute exists as an attribute. + attrId = convertLispIdtoPythonId(attr) + if attrId in self.__dict__: + return self.__dict__[attrId] + if isinstance(attr,int): + return self._frames[attr] + if attrId in self._frames: + return self._frames[attrId] + + # It could be an access to a class of objects (e.g. genes -> |Genes|). + realClassName = self.is_a_class_name(attr) + if realClassName: + # Use realClassName for the frame id, not attr. + return self.get_class_data(realClassName) + + # It could be an instance in the PGDB. Try to create a frame for it. + realInstanceName = self.is_an_instance_name(attr) + if realInstanceName: + # Use the realname for the frame-id so that retrieving the + # object from Pathway Tools will work. + frame = PFrame(realInstanceName, self, getFrameData=True, isClass=False) + return frame + else: + return None + + if 'IPython' in sys.modules: + def _ipython_display_(self): + table = "" + # A PGDB frame may contain thousands of attributes, one + # for each instance. This output is too large to printin + # most cases. Print a succinct representation of the PGDB frame. + table = table + "" + table = table + "" + table = table + "
orgid" + self._orgid + "
Number of PFrames" + str(self._nb_pframes()) + "
" + display(HTML(table)) + + def __setitem__(self, attr, val): + attrId = convertLispIdtoPythonId(attr) + if isinstance(val, PFrame): + self._frames[attrId] = val + else: + self.__dict__[attrId] = val + return None + + def __getitem__(self, index): + if pythoncyc.config._debug: + print("PGDB __getitem__", index) + if (isinstance(index,int) or isinstance(index,slice)) : + if self._frames: + return self._frames[index] + else: + raise PythonCycError('This PGDB has no _frames attribute.') + + # Accessing an item such as ecoli['trp'], index is a string not a number. + if index in self._frames: + return self._frames[index] + else: + attrId = convertLispIdtoPythonId(index) + if attrId in self._frames: + return self._frames[attrId] + else: + return self.__getattr__(index) + + def __eq__(self, other): + # The name of the orgid determines the object. + if isinstance(other, PGDB): + return self._orgid == other._orgid + else: + return False + + def __ne__(self, o): + return not self.__eq__(o) + + def save_pgdb(self): + """ + Save a PGDB that has been modified in the running Pathway Tools server. The PGDB + that will be saved is based on the orgid of this PGDB object. + """ + return self.sendPgdbFnCallBool('save-kb') + + def get_major_classes(self): + """ + Get from Pathway Tools the classes Reactions, Pathways, Genes, Compounds, + Proteins, and all their instances with their data. This method is very time + consuming has several ten of thousands of frames need to be transferred from + Pathway Tools and the corresponding PFrames need to be created. + """ + self.reactions + self.pathways + self.genes + self.compounds + self.proteins + self.get_frame_objects([f.frameid for f in self.reactions.instances]) + self.get_frame_objects([f.frameid for f in self.pathways.instances]) + self.get_frame_objects([f.frameid for f in self.genes.instances]) + self.get_frame_objects([f.frameid for f in self.compounds.instances]) + self.get_frame_objects([f.frameid for f in self.proteins.instances]) + + def sendPgdbQuery(self, query): + """ + Send a query for a specific PGDB using its orgid. + Use the macro with-organism for the Lisp Python server. + + Parm + query, a string. That string should be acceptable to the Lisp Python server. + + Return + the result (as a Python object) of the execution of the query in Pathway Tools. + """ + # Evaluate a query in the context of this PGDB. + if self._orgid == "unknown": + print("Cannot send any query because the selected organism is unknown.") + return None + else: + lisp_query = '(with-organism (:org-id \'' + self._orgid + ') ' + query + ')' + if pythoncyc.config._debug: + print(lisp_query) + return PTools.sendQueryToPTools(lisp_query) + + def sendPgdbFnCall(self, fn, *args, **kwargs): + """ + Send a PGDB query to Pathway Tools based on function fn and arguments args and + kwargs (keyword args) and return the result. If multiple values are + returned by fn, the Pathway Tools Python server transforms them into a list. + """ + if pythoncyc.config._debug: + print(fn) + fnCall = prepareFnCall(fn, *args, **kwargs) + return self.sendPgdbQuery(fnCall) + + def sendPgdbFnCallBool(self, fn, *args, **kwargs): + """ + Send a PGDB query to Pathway Tools that will return a Bool value. + This method takes care of translating no value or an empty list to False. + """ + result = self.sendPgdbFnCall(fn, *args, **kwargs) + if result == None or result == []: + return False + else: + return result + + def sendPgdbFnCallList(self, fn, *args, **kwargs): + """ + Send a PGDB query to Pathway Tools that will return a List value. + This method takes care of translating no value or False to an empty list. + """ + result = self.sendPgdbFnCall(fn, *args, **kwargs) + if result == None or result == False: + return [] + else: + return result + + def is_a_class_name(self, className): + """ + Verify that className is a known class in Pathway Tools. + Return the real name of that class because the className may have + been transformed by fn class-name-p to generate the closest real class name. + + Parm + className, a string, the class name to verify. + + Return + a string, either className itself, or modified by replacing + '_' to '-' or some case letters changed to match an existing class + name in Pathway Tools. + """ + return self.sendPgdbFnCallBool('class-name-p', className) + + def get_class_data(self, realClassName, getInstancesData=False): + """ + Retrieve the class slots and their values, creating a PFrame for the class. + Retrieve also the list of instances from Pathway Tools and create a PFrame for + each instance. Store the list of PFrames in attribute 'instances' of the class + object. If getInstancesData is True, get also all instances slots and their + data. + + Parms + realClassName, a string, the real name of the class to retrieve. + getInstancesData, boolean, True => get the slots and data of all instances. + + Returns + A PFrame representing the class with all its slot names + as Python attributes. + """ + fclass = PFrame(realClassName, self, getFrameData=True, isClass = True) + attrId = convertLispIdtoPythonId(realClassName) + frameids = self.sendPgdbFnCallList('get-class', fclass) + if not (frameids == None): + if getInstancesData: + # Create PFrame instances with all their slots and data. + instances = self.get_frame_objects(frameids) + else: + # Create PFrame instances but the data for each frame is not brought in now. + # Reuse a PFrame for a frameid, if it already exists for this PGDB. + instances = self.create_frame_objects(frameids) + fclass.__dict__['instances'] = instances + return fclass + + def create_frame_objects(self, frameids): + """ + Create all the required PFrames for the given frameids. If a PFrame already + exist for a frameid on the PGDB, reuse that PFrame, otherwise create a PFrame. + No data is transferred from Pathway Tools. + + Parm + frameids, list of frame ids (strings) + + Side-Effects + self is modified to contain new PFrames indexed on new frameids + + Return + list of PFrames + """ + pframes = [] + for frameid in frameids: + attrID = convertLispIdtoPythonId(frameid) + if attrID in self.__dict__: + f = self.__dict__[attrID] + else: + f = PFrame(frameid, self) + self.__dict__[attrID] = f + pframes.append(f) + return pframes + + def get_frame_objects(self, frameids): + """ + For each frame id of the list frameids, retrieve the slots + and their data. Reuse the PFrame of frameid if it already exist for this PGDB, + otherwise create one and attach it to this PGDB. + + Parm + frameids, list of frame ids (strings). + + Return + list of PFrames, one for each frame id. + """ + frameObjects = self.sendPgdbFnCallList('get-frame-objects', may_be_frameid(frameids)) + pframes = [] + for frameid, slotsData in frameObjects.items(): + attrID = convertLispIdtoPythonId(frameid) + if attrID in self.__dict__: + f = self.__dict__[attrID] + else: + f = PFrame(frameid, self) + self.__dict__[attrID] = f + pframes.append(f) + f._gotframe = True + for slot, data in slotsData.items(): + f.__dict__[convertLispIdtoPythonId(slot)] = data + return pframes + + def is_an_instance_name(self, frameid): + """ + Similar to method is_a_class_name but for a frame that is not a class. + If frameid is a real frame id of an object of this PGDB, returns frameid as is. + If not, try to convert frameid to an exist frame id by transforming cases of + letters and underscores to dashes in frameid. + + Parm + frameid, a string. + + Returns + a string representing an existing frame id in the PGDB. + """ + return self.sendPgdbFnCallBool('frameid-instance-p', Symbol(frameid)) + + def get_class_all_instances(self, className): + """ + Get all instances of the given class name for this PGDB. ClassName must be + exactly as Pathway Tools expect the name of the class, no conversion is applied. + + Parm + className, a symbol specified as a string (e.g., '|Reactions|') + + Returns + list of frameids + """ + return self.sendPgdbFnCallList('gcai', Symbol(className)) + + def get_class_all_subs(self, classArg): + """ + Get all subclasses of the given class name for this PGDB. If classArg is a + string, it must be exactly as Pathway Tools expect the name of the class, no + conversion is applied. + + Parm + classArg, a symbol specified as a string (e.g., '|Reactions|') or as a PFrame. + + Returns + list of frameids corresponding to the subclasses of the classArg. + """ + return self.sendPgdbFnCallList('get-class-all-subs', classArg) + + def run_fba(self, fileName): + """ + In PythonCyc, there is a run_fba method defined globally in the pythoncyc module + and there is this version which is run under a specific PGDB. Notice, though, + that the FBA input file provided will decide which organism is used for running + FBA and may override this PGDB. + + Parms + fileName + a string which is the name of the FBA input file on the running + Pathway Tools machine. + + Returns + A list with the following positional values: + 1) True <=> success, the FBA completed without error (for growth, see 5) + 2) List of error messages, if any + 3) List of output messages generated by MetaFlux (FBA module) during parsing + and execution + 4) The solver (SCIP) status symbol + 5) The flux of the objective biomass, non-zero if growth + 6) Number of growth cases if FBA input file is a knockout run, + or the number of active reactions if the FBA input file is solving a model + 7) The list of reactions that were in the model after instantiation + 8) The list of reactions that were active (non zero flux) with their fluxes + """ + return self.sendPgdbFnCall('python-run-fba', fileName) + + def get_slot_values(self, frameid, slotName): + """ + Return the slot values of a frame object. + + Parms + frameid + a string representing the unique identifier for a frame object. + slotName + a string representing the slot of the frame object. + + Returns + list of values of the given slot. Values can be frameids, booleans, + strings, or numbers. + + Example: + To get the substrates participating on the left of reaction RXN-9000: + meta.get_slot_values('RXN-9000', 'LEFT') + where meta is a variable bound to a PGDB object. + """ + return self.sendPgdbFnCallList('get-slot-values', Symbol(frameid), Symbol(slotName)) + + def put_slot_values(self, frameid, slotName, val): + """ + Modify the slot values of a frame object with the given val. Val is typically + a list of objects. + + Important: + The modified frame is not updated for any PFrame object that might has been + previously loaded from that PGDB. This operation should be used only for its + effect on the PGDB in the running Pathway Tools application. + + Parms + frameid + a string representing the unique identifier for a frame object. + slotName + a string representing the slot of the frame object. + val + a value to store in the slot, typically a list of values or objects. + + Side-Effects + The slot of that frame is replaced with the new value. + + Returns + Nothing + + Example: + To put the substrates participating on the left of reaction RXN-9000: + put_slot_values('RXN-9000', 'LEFT', ['CPD-9459','CPD-9460']) + """ + return self.sendPgdbFnCallList('put-slot-values', Symbol(frameid), Symbol(slotName), val) + + def put_slot_value(self, frameid, slotName, val): + """ + Modify the slot value of a frame object with the given val. Val is a single + value (e.g., not a list). + + Important: + The modified frame is not updated for any PFrame object that might has been + previously loaded from that PGDB. This operation should be used only for its + effect on the PGDB in the running Pathway Tools application. + + Parms + frameid + a string representing the unique identifier for a frame object. + slotName + a string representing the slot of the frame object. + val + a value to store in the slot. + + Side-Effects + The slot of that frame is replaced with the new value + + Returns + Nothing + + Example: + To put the Gibbs free energy of reaction RXN-9000: + put_slot_value('RXN-9000', 'GIBBS-0', 7.52) + """ + return self.sendPgdbFnCall('put-slot-value', Symbol(frameid), Symbol(slotName), val) + + def get_slot_value(self, frameid, slotName): + """ + Return the single slot value of a frame object. + + Parms + frameid + a string representing the unique identifier for a frame object. + slotName + a string representing the slot of the frame object. + + Example: + To get the substrates participating on the left of reaction RXN-9000: + get_slot_values('RXN-9000', 'LEFT') + """ + return self.sendPgdbFnCall('get-slot-value', Symbol(frameid), Symbol(slotName)) + + # Section 5.1 Enumeration operations + def all_pathways(self, selector='all', base=False): + """ + Description + Returns a list of pathway instance frames of a specified type. + + Parms + selector + Selects whether all pathways, or just small-molecule metabolism base pathways. + Can take either 'all' or 'small-molecule'. Defaults to 'all'. + base + If this boolean parameter is True, only includes base pathways. Otherwise, all + pathways, including superpathways, will be returned. + + Return value + A list of instances of class Pathways. + """ + return self.sendPgdbFnCallList('all-pathways', mkey(selector), base) + + def all_reactions(self, type_of_reactions='metab-smm'): + """ + Description + same as all_rxns() + """ + return self.all_rxns(type_of_reactions) + + def all_rxns(self, type_of_reactions='metab-smm'): + """ + Description + Returns a set of reactions that fall within a particular category. + + Parms + type_of_reactions + The type of reaction to return. Defaults to 'metab-smm'. + + The possible values are: + 'all' + All reactions. + 'protein-small-molecule-reaction' + One of the substrates of the reaction is a + macromolecule, and one of the substrates of the reaction + is a small molecule. + 'protein-reaction' + All substrates of the reaction are proteins. + 'trna-reaction' + One of the substrates of the reaction is a tRNA. + 'spontaneous' + Spontaneous reactions. + 'spontaneous-ht' + 'enzyme' + All enzyme-catalyzed reactions (i.e., instances of + either EC-Reactions class or Unclassified-Reactions class). + 'enzyme-ht' + 'small-molecule' + All reactions whose substrates are all small molecules, + as opposed to macromolecules. Excludes transport reactions. + 'small-molecule-ht' + 'metab-pathways' + All reactions found within metabolic pathways. Includes + reactions that are pathway holes. May include a handfull + of reactions whose substrates are macromolecules, e.g., + ACP. Excludes transport reactions. + 'all-rxns-metab-pathways-with-duplicates-ht' + 'metab-smm' + All reactions of small molecule metabolism, whether or + not they are present in a pathway. Subsumes + metab-pathways. + 'smm' + 'metab-smm-ht' + 'metab-complete-smm' + 'metab-all' + All enzyme-catalyzed reactions. Subsumes metab-smm. + 'transport-ht' + 'transport' + All transport reactions. + 'enzyme-not-in-pwy' + + Return value + A list of reaction frame ids. + """ + return self.sendPgdbFnCallList('all-rxns', mkey(type_of_reactions)) + + def all_substrates(self, rxns): + """ + Description + Returns all unique substrates used in the reactions specified by + the parameter rxns. + Parms + rxns + A list of reaction PFrames or frame ids. + + Return value + A list of compound frame ids. There might be strings in the list, + as the left and right slots of a reaction frame can contain strings. + """ + return self.sendPgdbFnCallList('all-substrates', may_be_frameid(rxns)) + + def all_cofactors(self): + """ + Description + Return a list of all cofactors used in the current PGDB. + + Return value + A list of cofactor frame ids. + """ + return self.sendPgdbFnCallList('all-cofactors') + + def all_modulators(self): + """ + Description + Enumerate all of the modulators, or direct regulators, in the + current PGDB. + + Return value + A list of regulator frame ids. + """ + return self.sendPgdbFnCallList('all-modulators') + + def all_sigma_factors(self): + """ + Description + Enumerate all RNA polymerase sigma factors. + + Return value + A list of all instances of the class Sigma-Factors. + """ + return self.sendPgdbFnCallList('all-sigma-factors') + + def all_operons(self): + """ + Description + Enumerates all operons. In this case, an operon is defined as a + list of overlapping instances of Transcription-Units. + + Return value + A list of lists of Transcription-Units, where all + Transcription-Units in the list belong to the same operon. + """ + return self.sendPgdbFnCallList('all-operons') + + def all_transporters(self): + """ + Description + Enumerate all transport proteins. + + Return value + A list of instances of class Proteins. + """ + return self.sendPgdbFnCallList('all-transporters') + + def all_transported_chemicals(self, from_compartment=None, to_compartment=None, show_compartment=None, primary_only=False): + """ + Description + Enumerates all chemicals transported by transport reactions in + the current PGDB. + + Parms + from_compartment + Keyword, The compartment that the chemical is + coming from (see Cellular Component Ontology). + to_compartment + Keyword, The compartment that the chemical is + going to (see Cellular Component Ontology). + primary_only + Keyword, If True, filter out common transport + compounds, such as protons and Na+. + + Return value + A list of compound frame ids. + """ + kwargs = { + 'from-compartment' : may_be_frameid(from_compartment), + 'to-compartment' : may_be_frameid(to_compartment), + 'show-compartment' : may_be_frameid(show_compartment), + 'primary-only?' : primary_only + } + return self.sendPgdbFnCallList('all-transported-chemicals', **kwargs) + + def all_protein_complexes(self, filter='all'): + """ + Description + Enumerates different types of protein complexes. + + Parms + filter + Keyword, The type of protein complexes to return. + + The argument must be one of the following values: + 'all' + Return all protein complexes. + 'hetero' + Return all heteromultimers. + 'homo' + Return all homomultimers. + + Return value + A list of protein complex frame ids. + """ + kwargs = { + 'filter' : mkey(filter) + } + return self.sendPgdbFnCallList('all-protein-complexes', **kwargs) + + def all_transcription_factors(self, allow_modified_forms=True): + """ + Description + Enumerates all transcription factors, or just unmodified forms + of transcription factors. + + Parms + allow_modified_forms + Keyword, A boolean value. If True, modified and unmodified forms of the protein + are returned. If false, then only unmodified forms of the proteins are returned. + The default value is True. + + Return value + A list of protein frame ids that are transcription factors. + """ + kwargs = { + 'allow-modified-forms?' : allow_modified_forms + } + return self.sendPgdbFnCallList('all-transcription-factors', **kwargs) + + def all_genetic_regulation_proteins(self, allow_modified_forms=True, class_name=None): + """ + Description + Enumerates all proteins that are involved in genetic regulation + of a particular given class. Optionally, just unmodified forms + of the proteins are returned. + + Parms + class_name + Keyword, The class Regulation or a subclass. + It defaults to Regulation-of-Transcription-Initiation. + allow_modified_forms + Keyword, A boolean value. If True, modified and + unmodified forms of the protein are returned. If false, then + only unmodified forms of the proteins are returned. The + default value is True. + + Return value + A list of protein frames that are involved in the specified form + of regulation. + """ + kwargs = { + 'allow-modified-forms?' : allow_modified_forms, + 'class' : Symbol(class_name) + } + return self.sendPgdbFnCallList('all-genetic-regulation-proteins', **kwargs) + + def rxns_w_isozymes(self, rxns=None): + """ + Description + Enumerate all reactions that have isozymes (distinct proteins or + protein classes that catalyze the same reaction). + + Parms + rxns + Keyword, A list of instances of the class Reactions. + Defaults to the result of (all-rxns :enzyme). + + Return value + A list of A list of instances of the class Reactions with isozymes. + """ + kwargs = { + 'rxns' : may_be_frameid(rxns) + } + return self.sendPgdbFnCallList('rxns-w-isozymes', **kwargs) + + def rxns_catalyzed_by_complex(self, rxns=None): + """ + Description + Enumerates all reactions catalyzed by an enzyme that is a protein complex. + + Parms + rxns + Keyword, A list of instances of the class Reactions. + Defaults to the result of (all-rxns :enzyme). + + Return value + A list of instances of the class Reactions with a protein + complex as an enzyme. + """ + kwargs = { + 'rxns' : may_be_frameid(rxns) + } + return self.sendPgdbFnCallList('rxns-catalyzed-by-complex', **kwargs) + + def all_enzymes(self, type_of_reactions=None): + """ + Description + Return all enzymes of a given type. + + Parm + type_of_reactions + Keyword, A type as taken from the parameter to + fn enzyme. Defaults to 'chemical-change'. + + Return value + A list of instances of class Proteins. + """ + kwargs = { + 'type' : type_of_reactions + } + return self.sendPgdbFnCallList('all-enzymes', **kwargs) + + # Section 5.1.1 Operations on Reactions + def genes_of_reaction(self, rxn): + """ + Description + Return all genes that encode the enzymes of a given reaction. + + Parms + rxn, An instance of the class Reactions, a frame id or PFrame. + + Return value + A list of instances of class Genes. + """ + return self.sendPgdbFnCallList('genes-of-reaction', may_be_frameid(rxn)) + + def substrates_of_reaction(self, rxn): + """ + Description + Return all of the reactants and products of a given reaction. + + Parms + rxn, An instance of the class Reactions, a frame id or PFrame. + + Return value + A list that may consist of children of class Compounds, + children of class Polymer-Segments, or strings. + """ + return self.sendPgdbFnCallList('substrates-of-reaction', may_be_frameid(rxn)) + + def enzymes_of_reaction(self, rxn, species=None, experimental_only=None, local_only_p=None): + """ + Description + Return the enzymes that catalyze a given reaction. + Parms + rxn + An instance of the class Reactions, a frame id or PFrame. + species + Keyword, A list of species, such that in a + multi-organism PGDB such as MetaCyc, only proteins found in + those organisms will be returned. This list can include + valid org-ids, children of class Organisms, and + strings. Please see the documentation for the species + slot-unit for more information. Default value is nil. + experimental_only + Keyword, When True, only return enzymes that have + a non-computational evidence code associated with it. + local_only_p + Keyword, When True, only return enzymes that + catalyze the specific form of the reaction, as opposed to + enzymes that are known to catalyze a more general form + (i.e., class) of the reaction. + + Return value + A list of children of class Proteins or class + Protein-RNA-Complexes. + """ + + kwargs = { + 'species' : species, + 'experimental-only?' : experimental_only, + 'local-only-p' : local_only_p + } + return self.sendPgdbFnCallList('enzymes-of-reaction', may_be_frameid(rxn), **kwargs) + + def reaction_reactants_and_products(self, rxn, direction=None, pwy=None): + """ + Description + Return the reactants and products of a reaction, based on a specified direction. + The direction can be specified explicity or by giving a pathway as an argument. + It is an error to both specify the pathway and the explicit direction. If + neither an explicit direction or a pathway is given as an argument, then the + direction is computationally inferred from available evidence within the PGDB. + + Parms + rxn + An instance of the class Reactions, that is, a frame id or PFrame. + direction + Keyword, Can take on the following values: + 'L2R' + The reaction direction goes from 'left to right', as + described in the Reactions instance. + 'R2L' + The reaction direction goes from 'right to left'; the + opposite of what is described in the Reactions + instance. + pwy + Keyword, An instance of the class Pathways, a frame id or PFrame. + + Return value + Returns multiple values as a list. The first value is a list of reactants as + determined by the direction of the reaction, and the second value is a list of + the products as determined by the direction of the reaction. Both lists have + items that are children of class Compounds, children of class Polymer-Segments, + or strings. + """ + kwargs = { + 'direction' : direction, + 'pwy' : may_be_frameid(pwy) + } + return self.sendPgdbFnCall('reaction-reactants-and-products', may_be_frameid(rxn), **kwargs) + + def reaction_type(self, rxn): + """ + Description + Returns a keyword describing the type of reaction. + + Parms + rxn, An instance of the class Reactions, a frame id or PFrame. + + Return value + A string from the following list: + 'small-molecule' + All substrates are small molecules, or small-molecule classes. + 'transport' + A substrate is marked with different compartment annotations + in the left and right slots. + 'protein-small-molecule-reaction' + At least one substrate is a protein and at least one is a + small molecule. + 'protein-reaction' + All substrates are proteins. + 'trna-reaction' + At least one substrate is a tRNA. + 'null-reaction' + No substrates or reactants are specified. + 'other' + None of the preceding cases apply. + """ + return self.sendPgdbFnCall('reaction-type', may_be_frameid(rxn)) + + def rxn_without_sequenced_enzyme_p(self, rxn): + """ + Description + A predicate that tests if a given reaction has genes with no + associated sequence information. + Parms + rxn + An instance of the class Reactions, that is, a frame id or PFrame. + complete + Keyword, if True, the predicate will return True when there + is any associated gene without a sequence. If False, the + predicate will return True when all associated genes are + without a sequence. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('reaction-without-sequenced-enzyme-p', may_be_frameid(rxn)) + + def pathway_hole_p(self, rxn): + """ + Description + A predicate that determines if the current reaction is + considered to be a 'pathway hole', or without an associated enzyme. + + Parms + rxn, An instance of the class Reactions, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('pathway-hole-p', may_be_frameid(rxn)) + + def rxn_present_p(self, rxn, include_spontaneous=None): + """ + Description + A predicate that determines if there is evidence for the + occurrence of the given reaction in the current PGDB. + + Parms + rxn, An instance of the class Reactions, that is, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('rxn-present?', may_be_frameid(rxn)) + + def rxn_specific_form_of_rxn_p(self, specific_rxn, generic_rxn): + """ + Description + A predicate that is True if the given generic reaction is a + generalized form of the given specific reaction. + + Parms + specific_rxn + A child of the class Reactions, that is, a frame id or PFrame. + generic_rxn + A child of the class Reactions, that is, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('rxn-specific-form-of-rxn-p', may_be_frameid(specific_rxn), may_be_frameid(generic_rxn)) + + def nonspecific_forms_of_rxn(self, rxn): + """ + Description + Return all of the generic forms of the given specific reaction. + Not every reaction will necessarily have a generic form. + + Parms + rxn, An instance of the class Reactions, that is, a frame id or PFrame. + + Return value + A list of children of the class Reactions. + """ + return self.sendPgdbFnCallList('nonspecific-forms-of-rxn', may_be_frameid(rxn)) + + def specific_forms_of_rxn(self, rxn): + """ + Description + Return all of the specific forms of the given generic reaction. + Not every reaction will necessarily have a specific form. + + Parms + rxn, A child of the class Reactions, that is, a frame id or PFrame. + + Return value + A list of instances of the class Reactions. + """ + return self.sendPgdbFnCallList('specific-forms-of-rxn', may_be_frameid(rxn)) + + def rxn_in_compartment_p(self, rxn, compartments, default_ok=None, pwy=None, loose=None): + """ + Description + A predicate that checks if the given reaction is present in a + list of cellular compartments. + + Parms + rxn + An instance of the class Reactions, a frame id or PFrame. + compartments + A list of cellular compartments, as defined in the Cellular + Components Ontology. See frame CCO. + default_ok + Keyword, If True, then we return True if the + reaction has no associated compartment information, or one + of its associated locations is a super-class of one of the + members of the compartments parameter. + pwy + Keyword, a frame id or PFrame. + If supplied, the search for associated + enzymes of the parameter rxn is limited to the given child + of Pathways. + loose + Keyword, boolean. If True, then the compartments + CCO-CYTOPLASM and CCO-CYTOSOL are treated as being the + same compartment. + + Return value + A boolean value. + """ + kwargs = { + 'default-ok?' : default_ok, + 'pwy' : may_be_frameid(pwy), + 'loose' : loose + } + return self.sendPgdbFnCallBool('rxn-in-compartment-p', may_be_frameid(rxn), compartments, **kwargs) + + def compartment_of_rxn(self, rxn, default=None): + """ + Description + Returns the compartment of the reaction for non-transport + reactions. + + Parms + rxn + An instance of the class Reactions, that is, a frame id or PFrame. + default + Keyword, The default compartment for reactions without any + compartment annotations on their substrates. The default + value is CCO-CYTOSOL. + + Return value + A child of the class Cell Compartment Ontology. + """ + return self.sendPgdbFnCall('compartment-of-rxn', may_be_frameid(rxn)) + + def compartments_of_reaction(self, rxn, sides=None, default_compartment=None): + """ + Description + Returns the compartments associated with the given reaction. + + Parms + rxn + An instance of the class Reactions, a frame id or PFrame. + sides + Keyword, The slots of the reaction to consider. + The default value is (LEFT RIGHT). + default_compartment + Keyword, + The default compartment, as determined by the function + (default-compartment), which currently is set to + CCO-CYTOSOL. + + Return value + A list of children of the class CCO. + """ + kwargs = { + 'sides' : sides, + 'default-compartment' : may_be_frameid(default_compartment) + } + return self.sendPgdbFnCallList('compartments-of-reaction', may_be_frameid(rxn), **kwargs) + + def transported_chemicals(self, rxn, side=None, primary_only=None, from_compartment=None, to_compartment=None, show_compartment=None): + """ + Description + Return the compounds in a transport reaction that change + compartments. + + Parms + rxn + An instance of the class Reactions, a frame id or PFrame. + side + Keyword, The side of the reaction from which to + return the transported compound. + primary_only + Keyword, If True, then filter out common + exchangers (currently defined as (PROTON NA CPD-1)+). If + True, and the only transported compounds are in this list, + then the filter doesn't apply. + from_compartment + Keyword, A compartment (child of class CCO). + If specified, then only return compounds transported from + that compartment. + to_compartment + Keyword, A compartment (child of class CCO). + If specified, then only return compounds transported to that + compartment. + show_compartment + Keyword, A compartment (child of class CCO). + If specified, and the compound is modified during transport, + then only return the form of the compound as found in this + compartment. + + Return value + A list of children of class Compounds. + """ + kwargs = { + 'side' : side, + 'primary-only?' : primary_only, + 'from-compartment' : may_be_frameid(from_compartment), + 'to-compartment' : may_be_frameid(to_compartment), + 'show-compartment' : may_be_frameid(show_compartment) + } + return self.sendPgdbFnCallList('transported-chemicals', may_be_frameid(rxn), **kwargs) + + def get_predecessors(self, rxn, pwy): + """ + Description + Return a list of all reactions that are direct predecessors + (i.e., occurr earlier in the pathway) of the given reaction in + the given pathway. + + Parms + rxn + An instance of the class Reactions, a frame id or PFrame. + pwy + A child of the class Pathways. + + Return value + A list of instances of the class Reactions. + """ + return self.sendPgdbFnCallList('get-predecessors', may_be_frameid(rxn), may_be_frameid(pwy)) + + def get_successors(self, rxn, pwy): + """ + Description + Return a list of all reactions that are direct successors (i.e., + occurr later in the pathway) of the given reaction in the given + pathway. + + Parms + rxn + An instance of the class Reactions, a frame id or PFrame. + pwy + A child of the class Pathways. + + Return value + A list of instances of the class Reactions. + """ + return self.sendPgdbFnCallList('get-successors', may_be_frameid(rxn), may_be_frameid(pwy)) + + def rxn_w_isozymes_p(self, rxn): + """ + Description + A predicate that tests if a given reaction has any associated + isozymes (distinct proteins or protein classes that catalyze the + same reaction). + + Parms + rxn, An instance of the class Reactions, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('rxn-w-isozymes-p', may_be_frameid(rxn)) + + # Section 5.1.2 Operations on Pathways + def genes_of_pathway(self, pwy, sorted=None): + """ + Description + Return all genes coding for enzymes in the given pathway. + + Parms + pwy + An instance of the class Pathways, a frame id or PFrame. + sorted? + Keyword, If True, the genes are sorted in the + order in which the corresponding reaction occurrs in the + sequence of the pathway. + + Return value + A list of instances of class Genes. + """ + kwargs = { + 'sorted?' : sorted + } + return self.sendPgdbFnCallList('genes-of-pathway', may_be_frameid(pwy), **kwargs) + + def enzymes_of_pathway(self, pwy, species=None, experimental_only=None, sorted=None): + """ + Description + Return all enzymes that are present in the given pathway. + Parms + + pwy + An instance of the class Pathways, a frame id or PFrame. + species + Keyword, A list of species, such that in a + multi-organism PGDB such as MetaCyc, only proteins found in + those organisms will be returned. This list can include + valid org-ids, children of class Organisms, and + strings. Please see the documentation for the species + slot-unit for more information. + experimental_only + Keyword, When True, only return enzymes that have + a non-computational evidence code associated with it. + sorted + Keyword, If True, the enzymes are sorted in the + order in which the corresponding reaction occurrs in the + sequence of the pathway. + + Return value + A list of children of class Proteins or class + Protein-RNA-Complexes. + """ + kwargs = { + 'species' : species, + 'experimental-only?' : experimental_only, + 'sorted?' : sorted + } + return self.sendPgdbFnCallList('enzymes-of-pathway', may_be_frameid(pwy), **kwargs) + + def compounds_of_pathway(self, pwy): + """ + Description + Return all substrates of all reactions that are within the given + pathway. + + Parms + pwy, An instance of the class Pathways, a frame id or PFrame. + + Return value + A list of children of class Compounds, children of class + Polymer-Segments, or strings. + """ + return self.sendPgdbFnCallList('compounds-of-pathway', may_be_frameid(pwy)) + + def substrates_of_pathway(self, pwy): + """ + Description + Bearing in mind the direction of all reactions within a pathway, this function + returns the substrates of the reactions in four groups: a list of all reactant + compounds (compounds occurring on the left side of some reaction in the given + pathway), the list of proper reactants (the subset of reactants that are not + also products), a list of all products, and a list of all proper products. + + Parms + pwy, An instance of the class Pathways, a frame id or PFrame. + + Return value + Four values as a list, each of which is a list of substrates. A substrate + may be a child of class Compounds, a child of class Polymer-Segments, or a string. + """ + return self.sendPgdbFnCall('substrates-of-pathway', may_be_frameid(pwy)) + + def variants_of_pathway(self, pwy): + """ + Description + Returns all variants of a pathway. + + Parms + pwy, An instance of the class Pathways, a frame id or PFrame. + + Return value + A list of instance of the class Pathways. + """ + return self.sendPgdbFnCallList('variants-of-pathway', may_be_frameid(pwy)) + + def pathway_components(self, pwy, rxn_list=None, pred_list=None): + """ + Description + Returns all of the connected components of a pathway. A connected component of a + pathway is a set of reactions in the pathway such that for all reactions R1 in + the connected component, a predecessor relationship holds between R1 and some + other reaction R2 in the connected component, and each connected component is of + maximal size. Every pathway will have from 1 to N connected components, where N + is the number of reactions in the pathway. Most pathways have one connected + component, but not all. + + Parms + pwy, a frame id or PFrame. + An instance of the class Pathways, which is not a + super-pathway (i.e., does not have any entries in its + sub-pathways slot). + rxn_list + Keyword, The list of reactions to use as the starting list + of connected component clusters. Defaults to + the content of slot reaction-list in pwy. + pred_list + Keyword, The list of reaction predecessors to iterate from + in order to cluster the reactions in rxn-list. Defaults to + list in slot predecessors of pwy. + + Return value + Returns three values as a list: the connected components as a list of + lists of the form ((r1 r2 r3) (r4 r5) (r6 r7 r8)) where each + sub-list contains all reactions in one connected component, the + number of connected components, and the length of the reaction + list. + """ + kwargs = { + 'rxn-list' : may_be_frameid(rxn_list), + 'pred-list': may_be_frameid(pred_list) + } + return self.sendPgdbFnCall('pathway-components', may_be_frameid(pwy), **kwargs) + + def noncontiguous_pathway_p(self, pwy): + """ + Description + A predicate that determines if the pathway contains more than + one connected component. See function pathway-components for + more explanation. + + Parms + pwy, An instance of the class Pathways, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('noncontiguous-pathway-p', may_be_frameid(pwy)) + + def rxns_adjacent_in_pwy_p(self, rxn1, rxn2, pwy): + """ + Description + A predicate to determine if two given reactions are adjacent to + one another in the given pathway. + + Parms + rxn1 + An instance of the class Reactions, a frame id or PFrame. + rxn2 + An instance of the class Reactions, a frame id or PFrame. + pwy + An instance of the class Pathways, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('rxns-adjacent-in-pwy-p', may_be_frameid(rxn1), may_be_frameid(rxn2), may_be_frameid(pwy)) + + # Section 5.1.3 Operations on Enzymatic-Reactions + def cofactors_and_pgroups_of_enzrxn(self, enzrxn): + """ + Description + Returns the cofactors and prosthetic groups of an enzymatic + reaction. + + Parm + enzrxn, An instance of the class Enzymatic-Reactions, a frame id or PFrame. + + Return value + A list of children of class Chemicals or strings, representing + cofactors and/or prosthetic groups. + """ + return self.sendPgdbFnCallList('cofactors-and-pgroups-of-enzrxn', may_be_frameid(enzrxn)) + + def enzrxn_activators(self, enzrxn, phys_relevant_only=None): + """ + Description + Returns the list of activators (generally small molecules) of + the enzymatic reaction frame. + + Parms + enzrxn + An instance of the class Enzymatic-Reactions, a frame id or PFrame. + phys_relevant_only + Keyword, If True, then only return activators that are + associated with Regulation instances that have the + physiologically-relevant? slot set to True. + + Return value + A list of children of the class Chemicals. + """ + # phys_relevant_only is optional for the Lisp version + return self.sendPgdbFnCallList('enzrxn-activators', may_be_frameid(enzrxn), phys_relevant_only) + + def enzrxn_inhibitors(self, enzrxn, phys_relevant_only=None): + """ + Description + Returns the list of inhibitors (generally small molecules) of + the enzymatic reaction frame. + + Parms + enzrxn + An instance of the class Enzymatic-Reactions, a frame id or PFrame. + phys_relevant_only + Keyword, If True, then only return inhibitors that are + associated with Regulation instances that have the + physiologically-relevant? slot set to True. + + Return value + A list of children of the class Chemicals. + """ + # phys_relevant_only is optional for the Lisp version + return self.sendPgdbFnCallList('enzrxn-inhibitors', may_be_frameid(enzrxn), phys_relevant_only) + + def pathways_of_enzrxn(self, enzrxn, include_super_pwys=None): + """ + Description + Returns the list of pathways in which the given enzymatic + reaction participates. + + Parms + enzrxn + An instance of the class Enzymatic-Reactions, a frame id or PFrame. + include_super_pwys + Keyword, If True, then not only will the + direct pathways in which enzrxn is associated in be + returned, but also any enclosing super-pathways. If enzrxn + is associated with a reaction that is directly associated + with a super-pathway, then the function might return + super-pathways even if this option is nil. + + Return value + A list of instances of class Pathways. + """ + kwargs = { + 'include-super-pwys?' : include_super_pwys + } + return self.sendPgdbFnCallList('pathways-of-enzrxn', may_be_frameid(enzrxn), **kwargs) + + def pathway_allows_enzrxn(self, pwy, rxn, enzrxn, single_species=None): + """ + Description + A predicate which returns a True value if the given pathway + allows the given enzymatic reaction to catalyze the given + reaction. Certain pathways have a list of enzymatic reactions + that are known not to catalyze certain reactions. See the + documentation of slot-unit enzyme-use for more information. + + Parms + pwy + An instance of the class Pathways, a frame id or PFrame. + rxn + An instance of the class Reactions, a frame id or PFrame. + enzrxn + An instance of the class Enzymatic-Reactions, a frame id or PFrame. + single_species + Keyword, An instance of the class Organisms If set, + then enzrxn has the further constraint that it must be an + enzymatic reaction present in the organism specified by the + value passed to single-species. + + Return value + A boolean value. + """ + # single_species is optional for the Lisp version. + # TODO + return self.sendPgdbFnCallBool('pathway-allows-enzrxn?', may_be_frameid(pwy), may_be_frameid(rxn), may_be_frameid(enzrxn), single_species) + + # Section 5.1.4 Operations on Proteins + def monomers_of_protein(self, protein, coefficients=None, unmodify=None): + """ + Description + Returns the monomers of the given protein complex. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + coefficients + Keyword, If True, then the second return value of + the function will be a list of monomer coefficients. + Defaults to True. + unmodify + Keyword, If True, obtain the monomers of the + unmodified form of p. + + Return value + First value is a list of instances of the class Proteins. If + coefficients? is True, then the second value is the + corresponding coefficients of the monomers fromthe first return + value. + """ + kwargs = { + 'coefficients?' : coefficients, + 'unmodify?' : unmodify + } + return self.sendPgdbFnCallList('monomers-of-protein', may_be_frameid(protein), **kwargs) + + def base_components_of_protein(self, protein, exclude_small_molecules=None): + """ + Description + Same as function monomers-of-protein, but also returns + components of the protein that are RNAs or compounds, not just + polypeptides. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + exclude_small_molecules + Keyword, If nil, then small molecule components + are also returned. Default value is True. + + Return value + Two values as a list. The first value is a list of the components, which + can be instances of the following classes: Polypeptides, + RNA, and Compounds. The second value is a list of the + corresponding coefficients of the components in the first value. + """ + kwargs = {'exclude-small-molecules?': exclude_small_molecules} + return self.sendPgdbFnCall('base-components-of-protein', may_be_frameid(protein), **kwargs) + + def containers_of(self, protein, exclude_self=None): + """ + Description + Return all complexes of which the given protein is a direct or indirect component. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + exclude_self + Keyword, If True, then protein will not be included in + the return value. + + Return value + A list of instances of the class Proteins. + """ + # exclude_self is an optional parameter for the Lisp fn version. + return self.sendPgdbFnCallList('containers-of', may_be_frameid(protein), exclude_self) + + def protein_or_rna_containers_of(self, protein, exclude_self=None): + """ + Description + This function is the same as the function containers-of, except that it only + includes containers that are instances of either class Protein-Complexes, or + class Protein-RNA-Complexes. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + exclude_self + Keyword, If True, then protein will not be included in + the return value. + + Return value + A list of instances of the class Proteins. + """ + # exclude_self is an optional parameter for the Lisp fn version. + return self.sendPgdbFnCallList('protein-or-rna-containers-of', may_be_frameid(protein), exclude_self) + + def homomultimeric_containers_of(self, protein, exclude_self=None): + """ + Description + This function is the same as the function containers-of, + except that it only includes containers that are homomultimers. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + exclude_self + Keyword, If True, then protein will not be included in + the return value. + + Return value + A list of instances of the class Proteins. + """ + # exclude_self is an optional parameter for the Lisp fn version. + return self.sendPgdbFnCallList('homomultimeric-containers-of', may_be_frameid(protein), exclude_self) + + def polypeptide_or_homomultimer_p(self, protein): + """ + Description + A predicate that determines if the given protein is a + polypeptide or a homomultimer. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('polypeptide-or-homomultimer-p', may_be_frameid(protein)) + + def unmodified_form(self, protein): + """ + Description + Return the unmodified form of the given protein, which might be + the same as the given protein. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + + Return value + An instance of the class Proteins. + """ + return self.sendPgdbFnCall('unmodified-form', may_be_frameid(protein)) + + def unmodified_or_unbound_form(self, protein): + """ + Description + Return the unmodified form or unbound (to a small molecule) form + of the given protein, which might be the same as the given protein. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + + Return value + An instance of the class Proteins. + """ + return self.sendPgdbFnCall('unmodified-or-unbound-form', may_be_frameid(protein)) + + def reduce_modified_proteins(self, prots, debind=None): + """ + Description + Given a list of proteins, the function converts all of the + proteins to their unmodified form, and then removes any + duplicates from the subsequent list. + + Parms + prots + A list of instances of the class Proteins, a frame id or PFrame. + debind + Keyword, When True, the proteins are further + simplified by obtaining the unbound form of the protein, if + it is bound to a small molecule. + + Return Value + A list of instances of the class Proteins. + """ + kwargs = { + 'debind?' : debind + } + if isinstance(prots, list): + return self.sendPgdbFnCallList('reduce-modified-proteins', may_be_frameid(prots), **kwargs) + else: + return self.sendPgdbFnCallList('reduce-modified-proteins', may_be_frameid([prots]), **kwargs) + + def all_direct_forms_of_protein(self, protein): + """ + Description + Given a protein, this function will return all of the directly + related proteins of its modified and unmodified forms, meaning + all of their direct subunits and all of their direct containers. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + + Return Value + A list of instances of the class Proteins. + """ + return self.sendPgdbFnCallList('all-direct-forms-of-protein', may_be_frameid(protein)) + + def all_forms_of_protein(self, protein): + """ + Description + Given a protein, this function will return all of the related + proteins of its modified and unmodified forms, meaning all of + their subunits and all of their containers. Unlike + all_direct_forms_of_protein, this function is not limited to + the direct containers only. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + + Return value + A list of instances of the class Proteins. + """ + return self.sendPgdbFnCallList('all-forms-of-protein', may_be_frameid(protein)) + + def modified_forms(self, protein, exclude_self=None, all_variants=None): + """ + Description + Returns all modified forms of a protein. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + exclude_self + Keyword, If True, then protein will not be included in + the return value. + all_variants + Keyword, If True, and protein is a modified form, then + we return all of the modified forms of the unmodified forms + of protein. + + Return value + A list of instances of the class Proteins. + """ + # Parameters exclude_self and all_variants are optionals for the Lisp fn version. + return self.sendPgdbFnCallList('modified-forms', may_be_frameid(protein), exclude_self, all_variants) + + def modified_and_unmodified_forms(self, protein): + """ + Description + Returns all of the modified and unmodified forms of the given + protein. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + + Return value + A list of instances of the class Proteins. + """ + return self.sendPgdbFnCallList('modified-and-unmodified-forms', may_be_frameid(protein)) + + def modified_containers(self, protein): + """ + Description + Returns all containers of a protein (including itself), and all + modified forms of the containers. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + + Return value + A list of instances of the class Proteins. + """ + return self.sendPgdbFnCallList('modified-containers', may_be_frameid(protein)) + + def top_containers(self, protein): + """ + Description + Return the top-most containers (i.e., they are not a component + of any other protein complex) of the given protein. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + + Return value + A list of instances of the class Proteins. + """ + return self.sendPgdbFnCallList('top-containers', may_be_frameid(protein)) + + def small_molecule_cplxes_of_prot(self, protein): + """ + Description + Return all of the forms of the given protein that are complexes + with small molecules. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + + Return value + A list of instances of the class Proteins. + """ + return self.sendPgdbFnCallList('small-molecule-cplxes-of-prot', may_be_frameid(protein)) + + def genes_of_protein(self, protein): + """ + Description + Given a protein, return the set of genes which encode all of the + monomers of the protein. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + + Return value + A list of instances of the class Genes. + """ + return self.sendPgdbFnCallList('genes-of-protein', may_be_frameid(protein)) + + def genes_of_proteins(self, prots): + """ + Description + The same as genes_of_protein, except that it takes a list of + proteins and returns a set of genes. + + Parms + prots + A list of instances of the class Proteins, a frame id or PFrame. + + Return value + A list of instances of the class Genes. + """ + if isinstance(prots, list): + return self.sendPgdbFnCallList('genes-of-proteins', may_be_frameid(prots)) + else: + return self.sendPgdbFnCallList('genes-of-proteins', may_be_frameid([prots])) + + def reactions_of_enzyme(self, protein, kb=None, include_specific_forms=None, include_subreactions=None): + """ + Description + Return all of the reactions associated with a given protein via + enzymatic reactions. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + kb + Keyword, The KB object of the KB in which to find + the associated reactions. Defaults to self. + include_specific_forms + Keyword, When True, specific forms of associated + generic reactions are also returned. Default value is True. + + Return value + A list of instances of the class Reactions. + """ + kwargs = { + 'kb' : kb, + 'include-specific-forms?' : include_specific_forms, + 'include-subreactions?' : include_subreactions + } + return self.sendPgdbFnCallList('reactions-of-enzyme', may_be_frameid(protein), **kwargs) + + def species_of_protein(self, protein): + """ + Description + Get the associated species for the given protein. + + Parms + protein + A list of instances of the class Proteins, a frame id or PFrame. + + Return value + An instance of the class Organisms, or a string. + """ + return self.sendPgdbFnCall('species-of-protein', may_be_frameid(protein)) + + def enzyme_p(self, protein, type_of_reactions=None): + """ + Description + Predicate that determines whether a specified protein is an + enzyme or not. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + type_of_reactions + Keyword, Can take on one of the following values to select + more precisely what is meant by an "enzyme": + + 'any' + Any protein that catalyzes a reaction is considered an + enzyme. + 'chemical-change' + If the reactants and products of the catalyzed reactin + differ, and not just by their cellular location, then + the protein is considered an enzyme. + 'small-molecule' + If the reactants of the catalyzed reaction differ and + are small molecules, then the protein is considered an + enzyme. + 'transport' + If the protein catalyzes a transport reaction. + 'non-transport' + If the protein only catalyzes non-transport reactions. + 'non-transport-non-pathway' + If the protein only catalyzes non-transport reactions and + it is not present in any pathway + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('enzyme-p', may_be_frameid(protein), mkey(type_of_reactions)) + + def leader_peptide_p(self, protein): + """ + Description + A predicate that determines whether the given protein is a + leader peptide. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('leader-peptide?', may_be_frameid(protein)) + + def protein_p(self, frame): + """ + Description + A predicate that determines whether the given frame is a protein. + + Parms + frame + a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('protein-p', may_be_frameid(frame)) + + def complex_p(self, frame): + """ + Description + A predicate that determines whether the given frame is a + protein complex. + + Parms + frame + a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('complex-p', may_be_frameid(frame)) + + def reactions_of_protein(self, protein, check_protein_components=None, check_protein_containers=None): + """ + Description + Returns all of the associated reactions that the given protein, + or its components, catalyzes. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + check_protein_components? + Keyword, If True, check all components of this protein for + catalyzed reactions. Defaults to True. + check_protein_containers? + Keyword, If True, check the containers and modified forms + of the protein for catalyzed reactions. + + Return value + A list of instances of class Reactions. + """ + return self.sendPgdbFnCallList('reactions-of-protein', may_be_frameid(protein), check_protein_components, check_protein_containers) + + def protein_in_compartment_p(self, rxn, compartments, default_ok=None, pwy=None, loose=None): + """ + Description + A predicate that checks if the given reaction is present in a + list of cellular compartments. + + Parms + rxn + An instance of the class Reactions, a frame id or PFrame. + compartments + A list of cellular compartments, as defined in the Cellular + Components Ontology. See frame CCO. + default_ok + Keyword, If True, then we return True if the + reaction has no associated compartment information, or one + of its associated locations is a super-class of one of the + members of the compartments parameter. + pwy + Keyword, a frame id or PFrame. If supplied, the search for associated + enzymes of the parameter rxn is limited to the given child + of Pathways. + loose + Keyword, If True, then the compartments CCO-CYTOPLASM and CCO-CYTOSOL + are treated as being the same compartment. + + Return value + A boolean value. + """ + kwargs = { + 'default-ok?' : default_ok, + 'pwy' : may_be_frameid(pwy), + 'loose?': loose + } + return self.sendPgdbFnCallBool('protein-in-compartment-p', may_be_frameid(rxn), may_be_frameid(compartments), **kwargs) + + def all_transporters_across(self, membranes=None, method=None): + """ + Description + Returns a list of transport proteins that transport across one + of the given membranes. + Parms + membranes + Keyword, Either :all or a list of instances of the class membranes. + Defaults to :all (CCO-MEMBRANE). + method + Keyword, + Either 'location' or 'reaction-compartments'. 'location' + will check the locations slot, while + 'reaction-compartments' will examine the compartments of + reaction substrates. Default value is 'location'. + + Return value + A list of instances of class Proteins. + """ + kwargs = { + #'membranes' : may_be_frameid(membranes), + 'membranes' : mkey(membranes), + 'method': method + } + return self.sendPgdbFnCallList('all-transporters-across', **kwargs) + + def autocatalytic_reactions_of_enzyme(self, protein): + """ + Description + Returns a list of reaction frames, where the protein + participates as a substrate of the reaction, and the reaction + has no associated Enzymatic Reaction frame. This implies that + the protein substrate of the reaction might autocatalyzing the + reaction. + + Parms + protein + An instance frame of class Proteins, a frame id or PFrame. + + Return value + A list of instances of class Reactions. + """ + return self.sendPgdbFnCallList('autocatalytic-reactions-of-enzyme', may_be_frameid(protein)) + + # Section 5.1.5 Operations on Genes + def gene_p(self, gene): + """ + Description + A predicate to determine if the given frame is a gene. + + Parms + gene + a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('gene-p', may_be_frameid(gene)) + + def enzymes_of_gene(self, gene): + """ + Description + Collects all of the enzymes encoded by the given gene, including + modified forms and complexes in which it is a sub-component. + + Parms + gene + An instance of class Genes, a frame id or PFrame. + + Return value + A list of instances of class Proteins. + """ + return self.sendPgdbFnCallList('enzymes-of-gene', may_be_frameid(gene)) + + def all_products_of_gene(self, gene): + """ + Description + Collects all proteins (not necessarily enzymes) that are encoded + by the given gene. + + Parms + gene + An instance of class Genes, a frame id or PFrame. + + Return value + A list of instances of class Proteins. + """ + return self.sendPgdbFnCallList('all-products-of-gene', may_be_frameid(gene)) + + def reactions_of_gene(self, gene): + """ + Description + Returns all reactions catalyzed by enzymes encoded by the given + gene. + + Parms + gene + An instance of class Genes, a frame id or PFrame. + + Return value + A list of instances of class Reactions. + """ + return self.sendPgdbFnCallList('reactions-of-gene', may_be_frameid(gene)) + + def pathways_of_gene(self, gene, include_super_pwys=None, include_gene_prod_as_substrate=None): + """ + Description + Returns the pathways of enzymes encoded by the given gene. + + Parms + gene + An instance of class Genes, a frame id or PFrame. + include_super_pwys + Keyword, If True, then not only will the + direct pathways in which gene encodes an enzyme be + returned, but also any enclosing super-pathways. If gene + is associated with a reaction that is directly associated + with a super-pathway, then the function might return + super-pathways even if this option is nil. + + Return value + A list of instances of class Pathways. + """ + kwargs = { + 'include-super-pwys?' : include_super_pwys, + 'include-gene-prod-as-substrate?' : include_gene_prod_as_substrate + } + return self.sendPgdbFnCallList('pathways-of-gene', may_be_frameid(gene), **kwargs) + + def chromosome_of_gene(self, gene): + """ + Description + Returns the replicon on which the gene is located. If the gene + is located on a contig that is, in turn, part of a chromosome, + then the contig is returned. + + Parms + gene + An instance of class Genes, a frame id or PFrame. + + Return value + An instance of class Genetic-Elements. + """ + return self.sendPgdbFnCall('chromosome-of-gene', may_be_frameid(gene)) + + def unmodified_gene_product(self, gene): + """ + Description + Returns the first element of the list returned by the function + unmodified-gene-products. This is useful if you are sure that + there are no alternative splice forms of your gene. + + Parms + gene + An instance of class Genes, a frame id or PFrame. + + Return value + An instance of either class Polypeptides or 'RNA. + """ + return self.sendPgdbFnCall('unmodified-gene-product', may_be_frameid(gene)) + + def unmodified_gene_products(self, gene): + """ + Description + Return all of the unmodified gene products (i.e. alternative + splice forms) of the given gene. + + Parms + gene + An instance of class Genes, a frame id or PFrame. + + Return value + A list of instances of either class Polypeptides or 'RNA. + """ + return self.sendPgdbFnCallList('unmodified-gene-products', may_be_frameid(gene)) + + def next_gene_on_replicon(self, gene): + """ + Description + Return the next gene on the replicon. + + Parms + gene + An instance of class Genes, a frame id or PFrame. + + Return value + Returns two values as a list. The first value is the next gene, or nil if + there is not a next gene (i.e., the gene is at the end of a + linear replicon). The second value is 'last' if the gene is the + last gene on a linear replicon. + """ + return self.sendPgdbFnCall('next-gene-on-replicon', may_be_frameid(gene)) + + def previous_gene_on_replicon(self, gene): + """ + Description + Return the previous gene on the replicon. + + Parms + gene + An instance of class Genes, a frame id or PFrame. + + Return value + Returns two values as a list. The first value is the previous gene, or nil + if there is not a previous gene (i.e., the gene is at the + beginning of a linear replicon). The second value is 'first' if + the gene is the first gene on a linear replicon. + """ + return self.sendPgdbFnCall('previous-gene-on-replicon', may_be_frameid(gene)) + + def adjacent_genes_p(self, g1, g2): + """ + Description + Given two genes, this predicate will return True if they are on + the same replicon, and adjacent to one another. + Parms + g1 + An instance of class Genes, a frame id or PFrame. + g2 + An instance of class Genes, a frame id or PFrame. + + Return value + A list if genes are in the same replicon. Otherwise False. + """ + if g1 == g2: + print("both queries are the same.") + return None + else: + return self.sendPgdbFnCallBool('adjacent-genes?', may_be_frameid(g1), may_be_frameid(g2)) + + def neighboring_genes_p(self, g1, g2, max_gap=10): + """ + Description + Given two genes, this predicate determines if the two genes are + "neighbors", or within a certain number of genes from one + another along the replicon. + Parms + g1 + An instance of class Genes, a frame id or PFrame. + g2 + An instance of class Genes, a frame id or PFrame. + max_gap + Keyword, An integer representing the number of genes g1 + and g2 can be from one another. Default value is 10. + + Return value + A boolean value. + """ + if g1 == g2: + print("both queries are the same.") + return None + else: + return self.sendPgdbFnCallBool('neighboring-genes-p', may_be_frameid(g1), may_be_frameid(g2), max_gap) + + def gene_clusters(self, genes, max_gap=10): + """ + Description + Groups together genes based on whether each gene is a gene + neighbor with other genes. + + Parms + genes + A list of instances of class Genes, a frame id or PFrame. + max_gap + Keyword, An integer representing the number of genes any + pair from genes can be from one another. Default value is 10. + + Return value + A dictionary of lists if genes are located below max_gap, where the key is a + gene from genes, and the value is a list with all of the gene neighbors of the + first gene. Otherwise returns an empty list. + """ + return self.sendPgdbFnCallList('gene-clusters', may_be_frameid(genes), max_gap) + + def rna_coding_gene(self, gene): + """ + Description + A predicate that determines if the given gene encodes an RNA. + + Parms + gene + An instance of the class Genes, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('rna-coding-gene?', may_be_frameid(gene)) + + def protein_coding_gene(self, gene): + """ + Description + A predicate that determines if the given gene encodes a protein + (as opposed to an RNA). + + Parms + gene + An instance of the class Genes, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCall('protein-coding-gene?', may_be_frameid(gene)) + + def pseudo_gene_p(self, gene): + """ + Description + A predicate that determines if the given gene is a pseudo-gene. + + Parms + gene + An instance of the class Genes, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('pseudo-gene-p', may_be_frameid(gene)) + + def phantom_gene_p(self, gene): + """ + Description + A predicate that determines if the given gene is a phantom gene. + + Parms + gene + An instance of the class Genes, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('phantom-gene-p', may_be_frameid(gene)) + + def dna_binding_site_p(self, gene): + """ + Description + A predicate that determines if the given frame is an instance of + the class DNA-Binding-Sites. + + Parms + gene + An instance of the class Genes, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('dna-binding-site-p', may_be_frameid(gene)) + + def terminator_p(self, gene): + """ + Description + A predicate that determines if the given object is an instance + of the class Terminators. + + Parms + gene + An instance of the class Genes, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('terminatorp', may_be_frameid(gene)) + + def operon_of_gene(self, gene): + """ + Description + Given a gene, return a list of transcription units that form the + operon containing the gene. + + Parms + gene + An instance of class Genes, a frame id or PFrame + + Return value + A list of instances of class Transcription-Units. + """ + return self.sendPgdbFnCallList('operon-of-gene', may_be_frameid(gene)) + + def genes_in_same_operon(self, gene): + """ + Description + Given a gene, return all other genes in the same operon. + + Parms + gene + An instance of class Genes, a frame id or PFrame. + + Return value + A list of instances of class Genes. + """ + return self.sendPgdbFnCallList('genes-in-same-operon', may_be_frameid(gene)) + + def gene_transcription_units(self, gene): + """ + Description + Given a gene, return all of the transcription units which + contain the gene. + + Parms + gene + An instance of class Genes, a frame id or PFrame + + Return value + A list of instances of class Transcription-Units. + """ + return self.sendPgdbFnCallList('gene-transcription-units', may_be_frameid(gene)) + + def cotranscribed_genes(self, gene): + """ + Description + Return all co-transcribed genes (i.e., genes which are a part of + one or more of the same transcription units) of the given gene. + + Parms + gene + An instance of class Genes, a frame id or PFrame + + Return value + A list of instances of class Genes. + """ + return self.sendPgdbFnCallList('cotranscribed-genes', may_be_frameid(gene)) + + def terminators_affecting_gene(self, gene): + """ + Description + Find terminators in the same transcription unit and upstream of + the given gene. + + Parms + gene + An instance of class Genes, a frame id or PFrame + + Return value + A list of instances of class Terminators. + """ + return self.sendPgdbFnCallList('terminators-affecting-gene', may_be_frameid(gene)) + + def chromosome_of_object(self, item): + """ + Description + Given a frame object, the replicon where it is located is returned. If there is + no associated replicon for the object, nil is returned. If the object is on more + than one replicon, an error is thrown. + + Parms + item, a frame id or PFrame + An instance of class All-Genes, Transcription-Units, + Promoters, Terminators, Misc-Features, or + DNA-Binding-Sites. + + Return value + An instance of class Genetic-Elements. + """ + return self.sendPgdbFnCall('chromosome-of-object', may_be_frameid(item)) + + # Section 5.1.6 Operations on Regulation Frames + def activation_p(self, reg_frame): + """ + Description + A predicate that determines if a given regulation frame is + describing activation. + + Parms + reg_frame + An instance of class Regulation, a frame id or PFrame + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('activation-p', may_be_frameid(reg_frame)) + + def inhibition_p(self, reg_frame): + """ + Description + A predicate that determines if a given regulation frame is + describing inhibition. + Parms + reg_frame + An instance of class Regulation, a frame id or PFrame + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('inhibition-p', may_be_frameid(reg_frame)) + + def direct_regulators(self, item, filter_fn=None): + """ + Description + Return all regulators that are connected to a regulated object + by a single regulation object. + + Parms + item + A frame id or PFrame. + filter_fn + Keyword, A predicate used to filter the regulation objects + used to find the regulators. + + Return value + A list of frames that regulate item. + """ + kwargs = { + 'filter-fn' : filter_fn + } + return self.sendPgdbFnCallList('direct-regulators', may_be_frameid(item), **kwargs) + + def direct_activators(self, item): + """ + Description + Return all activators that are connected to an activated object + by a single regulation object. + + Parms + item + A frame id or PFrame. + + Return value + A list of frames that activate item. + """ + return self.sendPgdbFnCallList('direct-activators', may_be_frameid(item)) + + def direct_inhibitors(self, item): + """ + Description + Return all inhibitors that are connected to an inhibited object + by a single regulation object. + + Parms + item + A frame id or PFrame. + + Return value + A list of frames that inhibit item. + """ + return self.sendPgdbFnCallList('direct-inhibitors', may_be_frameid(item)) + + def transcription_factor_p(self, protein, include_inactive=None): + """ + Description + A predicate that determines if the given protein is a + transcription factor, or a component of a transcription factor. + + Parms + protein + An instance frame of class Proteins, a frame id or PFrame. + include_inactive + Keyword, If True, then the function checks to see + if any of its components or containers is a transcription + factor as well. + + Return value + A boolean value. + """ + kwargs = { + 'include-inactive?' : include_inactive + } + return self.sendPgdbFnCallBool('transcription-factor?', may_be_frameid(protein), **kwargs) + + def regulator_of_type(self, protein, class_name): + """ + Description + A predicate that determines if the given protein is a regulator + of the specified class. + + Parms + protein + An instance frame of class Proteins, a frame id or PFrame. + class + A subclass of Regulation. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('regulator-of-type?', may_be_frameid(protein), class_name) + + def regulon_of_protein(self, protein): + """ + Description + Returns all transcription units regulated by any form of the + given protein. + + Parms + protein + An instance frame of class Proteins, a frame id or PFrame. + + Return value + A list of instances of the class Transcription-Units. + """ + return self.sendPgdbFnCallList('regulon-of-protein', may_be_frameid(protein)) + + def regulation_frame_transcription_units(self, reg_frame): + """ + Description + Given a regulation object, return the transcription units when + one of the regulated entities is a promoter or terminator of the + transcription unit. + + Parms + reg_frame + An instance of the class Regulation-of-Transcription, a frame id or PFrame. + + Return value + A list of instances of the class Transcription-Units. + """ + return self.sendPgdbFnCallList('regulation-frame-transcription-units', may_be_frameid(reg_frame)) + + def transcription_unit_regulation_frames(self, tu): + """ + Description + Returns a list of regulation frames that regulate the transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + A list of instances of the class Regulation. + """ + return self.sendPgdbFnCallList('transcription-unit-regulation-frames', may_be_frameid(tu)) + + def transcription_unit_activation_frames(self, tu): + """ + Description + Returns a list of regulation frames that activate the transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + A list of instances of the class Regulation. + """ + return self.sendPgdbFnCallList('transcription-unit-activation-frames', may_be_frameid(tu)) + + def transcription_unit_inhibition_frames(self, tu): + """ + Description + Returns a list of regulation frames that inhibit the transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + A list of instances of the class Regulation. + """ + return self.sendPgdbFnCallList('transcription-unit-inhibition-frames', may_be_frameid(tu)) + + def transcription_units_of_protein(self, protein): + """ + Description + Return all of the transcription units for which the given + protein, or its modified form, acts as a regulator. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + + Return value + A list of instances of the class Transcription-Units. + """ + return self.sendPgdbFnCallList('transcription-units-of-protein', may_be_frameid(protein)) + + def genes_regulated_by_protein(self, protein): + """ + Description + Return all of the genes for which the given protein, or its + modified form, acts as a regulator. + + Parms + protein + An instance of the class Proteins, a frame id or PFrame. + + Return value + A list of instances of the class Genes. + """ + return self.sendPgdbFnCallList('genes-regulated-by-protein', may_be_frameid(protein)) + + def DNA_binding_sites_of_protein(self, tf, all_forms=None): + """ + Description + Given a transcription factor, return all of its DNA binding sites. + + Parms + tf + An instance of the class Proteins, a frame id or PFrame. + all_forms + Keyword, When True, then return the DNA binding + sites of modified forms and subunits of tf as well. + + Return value + A list of instances of the class DNA-Binding-Sites. + """ + kwargs = { + 'all-forms?' : all_forms + } + return self.sendPgdbFnCallList('DNA-binding-sites-of-protein', may_be_frameid(tf), **kwargs) + + def regulator_proteins_of_transcription_unit(self, tu): + """ + Description + Returns all transcription factors that regulate the given + transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + A list of instances of the class Proteins. + """ + return self.sendPgdbFnCallList('regulator-proteins-of-transcription-unit', may_be_frameid(tu)) + + def transcription_factor_ligands(self, tfs, mode): + """ + Description + For a single transcription factor or list of transcription + factors, return all transcription factor ligands. + + Parms + tfs, a frame id or PFrame or a list of these. + An instance or a list of instances of the class + Proteins. If tfs is not the active form, then the + active form is determined automatically. + mode + One of the following values: 'activator', 'inhibitor', or + 'both'. + + Return value + A list of instances of the class Chemicals or strings. + """ + return self.sendPgdbFnCallList('transcription-factor-ligands', may_be_frameid(tfs), mkey(mode)) + + def transcription_factor_active_forms(self, tfs): + """ + Description + For a given transcription factor, find all active forms (i.e, + form of the protein that regulates) of the transcription factor. + + Parms + tfs, a frame id or PFrame. An instance of the class Proteins. + + Return value + A list of instances of the class Proteins. + """ + return self.sendPgdbFnCallList('transcription-factor-active-forms', may_be_frameid(tfs)) + + def genes_regulating_gene(self, gene): + """ + Description + Return all genes regulating the given gene by means of a + transcription factor. + + Parms + gene + An instance of the class Genes, a frame id or PFrame. + + Return value + A list of instances of class Genes. + """ + return self.sendPgdbFnCallList('genes-regulating-gene', may_be_frameid(gene)) + + def genes_regulated_by_gene(self, gene): + """ + Description + Return all genes regulated by the given gene by means of a + transcription factor. + + Parms + gene + An instance of the class Genes, a frame id or PFrame. + + Return value + A list of instances of class Genes. + """ + return self.sendPgdbFnCallList('genes-regulated-by-gene', may_be_frameid(gene)) + + def regulators_of_gene_transcription(self, gene, by_function=None): + """ + Description + Returns a list of proteins that are regulators of the given gene. + + Parms + gene + An instance of the class Genes, a frame id or PFrame. + by_function + Keyword, If True, then return two values: a list of + activator proteins and a list of inhibitor proteins. + + Return value + A list of instances of class Proteins. If by_function is + True, then two values are returned. The first value is a list + of activator proteins, and the second value is a list of + inhibitor proteins. + """ + kwargs = { + 'by-function?' : by_function + } + return self.sendPgdbFnCall('regulators-of-gene', may_be_frameid(gene), **kwargs) + + def transcription_unit_activators(self, tu): + """ + Description + Returns all activator proteins of the given transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + A list of instances of class Proteins. + """ + return self.sendPgdbFnCallList('transcription-unit-activators', may_be_frameid(tu)) + + def transcription_unit_inhibitors(self, tu): + """ + Description + Returns all inhibitor proteins of the given transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + A list of instances of class Proteins. + """ + return self.sendPgdbFnCallList('transcription-unit-inhibitors', may_be_frameid(tu)) + + def regulators_of_operon_transcription(self, operon, by_function=None): + """ + Description + Returns a list of transcription factors of an operon. + + Parms + operon + An instance or list of instances of the class Transcription-Units, a frame id or PFrame. + by_function + Keyword, If True, then return two values: a list of + activator proteins and a list of inhibitor proteins. + + Return value + A list of instances of class Proteins. If the modified form + of the protein is the transcription factor, then that is the + protein returned. + """ + # Parameter by_function is optional for the Lisp fn. + if isinstance(operon, list): + return self.sendPgdbFnCallList('regulators-of-operon-transcription', may_be_frameid(operon), by_function) + else: + return self.sendPgdbFnCallList('regulators-of-operon-transcription', may_be_frameid([operon]), by_function) + + def transcription_unit_promoter(self, tu): + """ + Description + Returns the promoter of the given transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + An instance of class Promoters. + """ + return self.sendPgdbFnCall('transcription-unit-promoter', may_be_frameid(tu)) + + def transcription_unit_genes(self, tu): + """ + Description + Returns the genes of the given transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + A list of instances of class Genes. + """ + return self.sendPgdbFnCallList('transcription-unit-genes', may_be_frameid(tu)) + + def transcription_unit_first_gene(self, tu): + """ + Description + Returns the first gene of the given transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + An instance of class Genes. + """ + return self.sendPgdbFnCall('transcription-unit-first-gene', may_be_frameid(tu)) + + def transcription_unit_binding_sites(self, tu): + """ + Description + Returns the binding sites of the given transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + A list of instances of class DNA-Binding-Sites. + """ + return self.sendPgdbFnCallList('transcription-unit-binding-sites', may_be_frameid(tu)) + + def transcription_unit_transcription_factors(self, tu): + """ + Description + Returns the binding sites of the given transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + A list of instances of class DNA-Binding-Sites. + """ + return self.sendPgdbFnCallList('transcription-unit-transcription-factors', may_be_frameid(tu)) + + def transcription_unit_mrna_binding_sites(self, tu): + """ + Description + Returns the mRNA binding sites of the given transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + A list of instances of class mRNA-Binding-Sites. + """ + return self.sendPgdbFnCallList('transcription-unit-mrna-binding-sites', may_be_frameid(tu)) + + def chromosome_of_operon(self, tu): + """ + Description + Returns the replicon of the given transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + An instance of class Genetic-Elements. + """ + return self.sendPgdbFnCall('chromosome-of-operon', may_be_frameid(tu)) + + def binding_sites_affecting_gene(self, gene): + """ + Description + Returns all binding sites which are present in the same + transcription units as the given gene. + + Parms + gene + An instance of the class Genes, a frame id or PFrame. + + Return value + A list of instances of class DNA-Binding-Sites. + """ + return self.sendPgdbFnCallList('binding-sites-affecting-gene', may_be_frameid(gene)) + + def binding_site_to_regulators(self, binding_site): + """ + Description + Returns all of the transcription factors of the given binding site. + + Parms + binding_site + An instance of class DNA-Binding-Sites, a frame id or PFrame. + + Return value + A list of instances of class Proteins. + """ + return self.sendPgdbFnCallList('binding-site->regulators', may_be_frameid(binding_site)) + + def transcription_units_of_promoter(self, promoter): + """ + Description + Returns all transcription units of a given promoter. + + Parms + promoter + An instance of class Promoters, a frame id or PFrame. + + Return value + A list of instances of class Transcription-Units. + """ + return self.sendPgdbFnCallList('transcription-units-of-promoter', may_be_frameid(promoter)) + + def promoter_binding_sites(self, promoter): + """ + Description + Returns all of the binding sites associated with the given + promoter, across multiple transcription units. + + Parms + promoter + An instance of class Promoters, a frame id or PFrame. + + Return value + A list of instances of class DNA-Binding-Sites. + """ + return self.sendPgdbFnCallList('promoter-binding-sites', may_be_frameid(promoter)) + + def transcription_unit_terminators(self, operon): + """ + Description + Returns the terminators of the given transcription unit. + + Parms + operon + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + A list of instances of class Terminators. + """ + return self.sendPgdbFnCallList('transcription-unit-terminators', may_be_frameid(operon)) + + def containing_tus(self, binding_site): + """ + Description + Given a site (whether a DNA binding site, a promoter, a gene, or + a terminator) along a transcription unit, return the + correspodning transcription units. + + Parms + binding_site, a frame id or PFrame. + An instance of class Transcription-Units, + mRNA-Binding-Sites, DNA-Binding-Sites, + Promoters, Genes, or Terminators. + + Return value + A list of instances of class Transcription-Units. + """ + return self.sendPgdbFnCallList('containing-tus', may_be_frameid(binding_site)) + + def containing_chromosome(self, binding_site): + """ + Description + Given a site (whether a DNA binding site, a promoter, a gene, or + a terminator) along a transcription unit, return the + correspodning regulon. + + Parms + binding_site, a frame id or PFrame. + An instance of class Transcription-Units,site + mRNA-Binding-Sites, DNA-Binding-Sites, + Promoters, Genes, or Terminators. + + Return value + An instance of class Genetic-Elements. + """ + return self.sendPgdbFnCall('containing-chromosome', may_be_frameid(binding_site)) + + def binding_site_promoters(self, tu): + """ + Description + Returns the promoters of the given DNA binding site. + + Parms + tu + An instance of the class DNA-Binding-Sites, a frame id or PFrame. + + Return value + A list of instances of class Promoters. + """ + return self.sendPgdbFnCallList('binding-site-promoters', may_be_frameid(tu)) + + def transcription_unit_all_components(self, tu): + """ + Description + Returns all components (binding sites, promoters, genes, + terminators) of the given transcription unit. + + Parms + tu + An instance of the class Transcription-Units, a frame id or PFrame. + + Return value + A list of instances of class Transcription-Units, + mRNA-Binding-Sites, DNA-Binding-Sites, Promoters, + Genes, or Terminators. + """ + return self.sendPgdbFnCallList('transcription-unit-all-components', may_be_frameid(tu)) + + def binding_site_transcription_units(self, promoter): + """ + Description + Returns all transcription units of a given binding site. + + Parms + promoter, a frame id or PFrame. + An instance of class DNA-Binding-Sites or + mRNA-Binding-Sites. + + Return value + A list of instances of class Transcription-Units. + """ + return self.sendPgdbFnCallList('binding-site-transcription-units', may_be_frameid(promoter)) + + # Section 5.1.7 Operations on Compounds + def reactions_of_compound(self, cpd, non_specific_too=None, transport_only=None, compartment=None, enzymatic=None): + """ + Description + Return all reactions in which the given compound participates as + a substrate. + + Parms + cpd + a frame id or PFrame. A child of class Compounds. + non_specific_too + Keyword, If True, returns all generic + reactions where cpd, or a parent of cpd, appears as a + substrate. + transport_only + Keyword, If True, return only transport reactions. + compartment + Keyword, If True, return only reactions within + the specified compartment. + enzymatic + Keyword, If True, return only enzymatic reactions. + + Return value + A list of children of class Reactions. + """ + kwargs = { + 'non-specific-too?' : non_specific_too, + 'transport-only?' : transport_only, + 'compartment' : compartment, + 'enzymatic?' : enzymatic + } + return self.sendPgdbFnCallList('reactions-of-compound', may_be_frameid(cpd), **kwargs) + + def substrate_of_generic_rxn(self, cpd, rxn): + """ + Description + A predicate that determines if a parent of the given compound is + a substrate of the given generic reaction. + + Parms + cpd + An instance of class Compounds, a frame id or PFrame. + rxn + An instance of class Reactions, a frame id or PFrame. + + Return value + A boolean value. + """ + return self.sendPgdbFnCallBool('substrate-of-generic-rxn?', may_be_frameid(cpd), may_be_frameid(rxn)) + + def pathways_of_compound(self, cpd, non_specific_too=None, modulators=None, phys_relevant=None, include_rxns=None): + """ + Description + Returns all pathways in which the given compound appears as a + substrate. + + Parms + cpd + An instance of class Compounds, a frame id or PFrame. + non-specific_too + Keyword, If True, returns all generic + reactions where cpd, or a parent of cpd, appears as a + substrate. + modulators + Keyword, If True, returns pathways where cpd + appears as a regulator as well. + phys-relevant + Keyword, If True, then only return inhibitors + that are associated with Regulation instances that have + the physiologically-relevant? slot set to True. + include-rxns + Keyword, If True, then return a list of + reaction-pathway pairs. + + Return value + A list of instances of class Pathways. If include-rxns? is + True, then a list of lists, where each sub-list consists of + an instance of class Reactions and an instance of class + Pathways. + """ + kwargs = { + 'non-specific-too?' : non_specific_too, + 'modulators?' : modulators, + 'phys-relevant?' : phys_relevant, + 'include-rxns?' : include_rxns} + return self.sendPgdbFnCallList('pathways-of-compound', may_be_frameid(cpd), **kwargs) + + def activated_or_inhibited_by_compound(self, cpds, mode=None, mechanisms=None, phys_relevant=None, slots=None): + """ + Description + Returns all pathways in which the given compound appears as a substrate. + + Parms + cpds + An instance or list of instances of class Compounds, a frame id or PFrame. + mode + Keyword, Represents the type of regulation. Can + take on the values of "+", "-", or None. + mechanisms + Keyword, Keywords from the mechanism slot of + the corresponding sub-class of the class Regulation. If + True, only regulation objects with mechanisms in this + list will be explored for regulated objects. + phys_relevant + Keyword, If True, then only return inhibitors + that are associated with Regulation instances that have + the physiologically-relevant? slot set to True. + slots + Keyword, A list of enzymatic reaction slots. + + Return value + A list of instances of class Enzymatic-Reactions. + """ + kwargs = { + 'mode' : mode, + 'mechanisms' : mechanisms, + 'phys-relevant?' : phys_relevant, + 'slots' : slots + } + return self.sendPgdbFnCallList('ACTIVATED-OR-INHIBITED-BY-COMPOUND', may_be_frameid(cpds), **kwargs) + + def tfs_bound_to_compound(self, cpd, include_inactive=None): + """ + Description + Returns a list of protein complexes that, when bound to the + given compound, act as a transcription factor. + + Parms + cpd + An instance of class Compounds, a frame id or PFrame. + include_inactive + Keyword, If True, then the inactive form of + the protein is also checked. See the function + transcription-factor? for more information. + + Return value + A list of instances of class Proteins. + """ + kwargs = { + 'include-inactive?' : include_inactive + } + return self.sendPgdbFnCallList('tfs-bound-to-compound', may_be_frameid(cpd), **kwargs) + + # Section 5.1.8 Object Name Manipulation Operations + def get_name_string(self, item, + rxn_eqn_as_name=None, + rxn_common_name_as_name=None, + direction=None, + name_slot=None, + strip_html=None, + include_species_strain_name=None, + italicize_species=None, + short_name=None, + species_initials=None, + primary_class=None): + """ + Description + Given an object, compute the string name. The method used to + compute the name varies per the object class. + + Parms + item + A frame id or PFrame. + rxn_eqn_as_name + Keyword, If True, then we use the reaction + equation in string form as the name of the reaction. + Defaults to True. + rxn_common_name_as_name + Keyword, If True, then we use the reaction's + common name as the name of the reaction. + direction + Keyword, An argument of 'l2r' or 'r2l' can be + given to specify the desired reaction orientiation when + printed in reaction equation form. If this is not provided, + then the reaction direction will be determined using pathway + evidence. + name_slot + Keyword, The specified slotunit frame name, as a + symbol, will be used for extracting the name of the frame. + strip_html + Keyword, Remove any HTML mark-up from the string + form of the object name. + include_species_strain_name + Keyword, Provide proper italicization for the + organism strain name. + italicize_species + Keyword, Provide proper italicization for the + organism species name. + short_name + Keyword, If the ABBREV-NAME slot is populated + for the frame, then its value will be used. + species_initials + Keyword, Print the name of the organism as initials. + primary_class + Keyword, Specify explicitly the primary class of + the given frame. This can be used to override the internal + reasoning of this function, and you can give a suggestion to + the function to treat the frame as another class. + + Return value + A string representing the name of the frame. + """ + kwargs = { + 'rxn-eqn-as-name': rxn_eqn_as_name, + 'rxn-common-name-as-name': rxn_common_name_as_name, + 'direction': direction, + 'name-slot': name_slot, + 'strip-html?': strip_html, + 'include-species-strain-name?': include_species_strain_name, + 'italicize-species?': italicize_species, + 'short-name?': short_name, + 'species-initials': species_initials, + 'primary-class': Symbol(primary_class)} + return self.sendPgdbFnCall('get-name-string', may_be_frameid(item), **kwargs) + + def full_enzyme_name(self, enzyme, use_frame_name=None, name=None, activity_names=None): + """ + Description + Compute the full name of an enzyme as the concatenation of the + common name of the protein followed by the common names of its + enzymatic reactions. Note that two enzrxns for the same enzyme + could have the same common name, so we avoid including the same + name twice. + + Parms + enzyme + An instance of the class Proteins, that is, a frame id or a PFrame. + use_frame_name + Keyword, If True, then the frameid of the enzyme + instance is used in computing the enzyme name. Defaults to + True. + name + Keyword, A string that bypasses the function, and will be + returned as the value of the function. + activity_names + Keyword, A provided list of strings, that represent the + names of the known catalytic activities of enzyme. + + Return value + A string. + """ + # Parameters use_frame_name, name and activity_names are optional for the Lisp fn version. + kwargs = { + 'use-frame-name?' : use_frame_name, + 'name' : name, + 'activity_names' : activity_names + } + + #return self.sendPgdbFnCall('full-enzyme-name', may_be_frameid(enzyme), use_frame_name, name, activity_names) + return self.sendPgdbFnCall('full-enzyme-name', may_be_frameid(enzyme), **kwargs) + + def enzyme_activity_name(self, enzyme, reaction=None): + """ + Description + Computes the name of an enzyme in the context of a particular + reaction. If the reaction is not provided, then we return the + full enzyme name. + + Parms + enzyme + An instance of the class Proteins, that is, a frame id or a PFrame. + reaction + Keyword, An instance of the class Reactions. + + Return value + A string. + """ + # Parameter reaction is optional for the Lisp fn version. + return self.sendPgdbFnCall('enzyme-activity-name', may_be_frameid(enzyme), may_be_frameid(reaction)) diff --git a/pythoncyc/PTools.py b/pythoncyc/PTools.py index 5560e1a..8b5a0fe 100644 --- a/pythoncyc/PTools.py +++ b/pythoncyc/PTools.py @@ -1,5 +1,5 @@ # Copyright (c) 2014, SRI International -# +# # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including @@ -7,10 +7,10 @@ # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: -# +# # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -22,175 +22,193 @@ """ This module handles basic operations for receiving and sending messages via a -network socket to Pathway Tools. +network socket to Pathway Tools. No major class is defined in this file, but +only toplevel functions and some simple classes for errors handling. +""" -No major class is defined in this file, but only toplevel functions and -some simple classes for errors handling. +import json, os, sys, socket, time +import pythoncyc.config -""" +def recvAll(open_socket): + """ + Description + Receive the entire message sent by Pathway Tools on an open socket. The message starts + with a single character type, which is either 'A' or 'L'. The 'A' time is used + without providing a length but can take longer to receive because it uses a + timeout technique to read the entire message. The 'L' type assumes that the + length of the message, in characters, is given on the next 10 characters as an + integer. The message length is the number of characters after these 10 + characters. + + Parm + open_socket, an open network socket. + + Return + the message received on socket s as a string. + """ + if pythoncyc.config._debug: + print('recvAll ...') + + # Get the type of message which is one character long. + msg_type = open_socket.recv(1) + + if pythoncyc.config._debug: + print("type ", msg_type) + + if msg_type == b'A': + # The length of the message is not given, use time out approach. + return recvTimeOut(open_socket) + elif msg_type == b'L': + # The next 10 characters give the length. + lengthMsg = int(recvFixedLength(open_socket, 10)) + if pythoncyc.config._debug: + print("lengthMsg {:d}".format(lengthMsg)) + return recvFixedLength(open_socket, lengthMsg) + else: + # Something is broken on the server side, so + # use recv with a long timeout to try flushing + # the sent message. + return recvTimeOut(open_socket, timeOut=5) + +def sendAll(open_socket, query): + sent_len = 0 + query_len = len(query) + while sent_len < query_len: + nb_chars = open_socket.send(query[sent_len:]) + if nb_chars == 0: + raise PythonCycError("Connection to Pathway Tools broke while sending query {:s}.".format(query)) + sent_len = sent_len + nb_chars + +def recvFixedLength(open_socket, lengthMsg): + """ + Description + Receive a fixed length message on an open socket. + + Parm + lengthMsg, an integer, which is the length in characters of the message to receive. + + Return + the message received as a string. + """ + pieces = [] + nbBytesRecv = 0 + while nbBytesRecv < lengthMsg: + piece = open_socket.recv(min(lengthMsg - nbBytesRecv, 4096)) + if piece == '': + # Give up now because nothing was received. + return ''.join(pieces) + pieces.append(piece.decode()) + nbBytesRecv = nbBytesRecv + len(piece) + # print 'Fixed receive: ', ''.join(pieces) + return ''.join(pieces) + +def recvTimeOut(open_socket, timeOut=2): + """ + Description + Receive a message of unknown length on socket. While receiving a message, if no + more characters are sent on socket after timeOut seconds, it is assumed that the + message has ended. Therefore, it will always, whatever the lenght of the + message, take at least timeOut seconds to execute this method. If no character + is received after 60 seconds, this method returns with an empty message. + + Parms + open_socket + an open network socket. + timeOut + number of seconds before timing out between fragments of the received message. -import os -import sys -import socket as so -import json -import time -import config - -def recvAll(s): - """ - Receive the entire message sent by Pathway Tools on socket s. - The message starts with a single character type, which is either 'A' - or 'L'. The 'A' time is used without providing a length but can take - longer to receive because it uses a timeout technique to read the entire - message. The 'L' type assumes that the length of the message, in characters, - is given on the next 10 characters as an integer. The message length is the - number of characters after these 10 characters. - - Parm - s, an open network socket. - Return - the message received on socket s as a string. - """ - - if config._debug: - print 'recvAll ...' - # Get the type of message which is one character long. - type = s.recv(1) - # print "type ", type - if type == 'A': - # The length of the message is not given, use time out approach. - return recvTimeOut(s) - elif type == 'L': - # The next 10 characters give the length. - lengthMsg = int(recvFixedLength(s, 10)) - if config._debug: - print "lengthMsg ", lengthMsg - return recvFixedLength(s, lengthMsg) - else: - # Something is broken on the server side, so - # use recv with a long timeout to try flushing - # the sent message. - return recvTimeOut(s, timeOut=5) - -def sendAll(s, query): - sent_len = 0 - query_len = len(query) - while sent_len < query_len: - nb_chars = s.send(query[sent_len:]) - if nb_chars == 0: - raise PythonCycError("Connection to Pathway Tools broke while sending query %s." % query) - sent_len = sent_len + nb_chars - -def recvFixedLength(s, lengthMsg): - """ - Receive a fixed length message on socket s. - Parm - lengthMsg, an integer, which is the length in characters of the - message to receive. - Return - the message received as a string. - """ - pieces = [] - nbBytesRecv = 0 - while nbBytesRecv < lengthMsg: - piece = s.recv(min(lengthMsg - nbBytesRecv, 4096)) - if piece == '': - # Give up now because nothing was received. - return ''.join(pieces) - pieces.append(piece) - nbBytesRecv = nbBytesRecv + len(piece) - # print 'Fixed receive: ', ''.join(pieces) - return ''.join(pieces) - -def recvTimeOut(socket, timeOut=2): - """ - Receive a message of unknown length on socket. While receiving a message, if no - more characters are sent on socket after timeOut seconds, it is - assumed that the message has ended. Therefore, it will always, whatever the lenght - of the message, take at least timeOut seconds to execute this method. If no character - is received after 60 seconds, this method returns with an empty message. - - Parms - socket, an open network socket. - timeOut, number of seconds before timing out between fragments of the received - message. - Return - The received message, as a string, on socket. - """ - # Keep each received packet in an array. - pieces = [] - # Keep track of time between recvs. - begin = time.time() - while 1: - # If we started to get data and the timeOut occurs, - # we assume that Pathway Tools sent everything. - if pieces and time.time() - begin > timeOut: - break - elif time.time() - begin > 60: - break - # Try to receive some text. - try: - data = socket.recv(4096) - if data: - pieces.append(data) - # Reset beginning time for next recv. - begin = time.time() - else: - # Slow down in case timeOut is small. - time.sleep(0.1) - except so.error: - pass - - # Join all the pieces together. - if pieces == []: - return None - else: - return ''.join(pieces) + Return + The received message, as a string, on socket. + """ + # Keep each received packet in an array. + pieces = [] + + # Keep track of time between recvs. + begin = time.time() + + while 1: + # If we started to get data and the timeOut occurs, + # we assume that Pathway Tools sent everything. + if pieces and time.time() - begin > timeOut: + break + elif time.time() - begin > 60: + break + # Try to receive some text. + try: + data = open_socket.recv(4096) + if data: + print(data) + pieces.append(data.decode()) + # Reset beginning time for next recv. + begin = time.time() + else: + # Slow down in case timeOut is small. + time.sleep(0.1) + except socket.error: + pass + + # Join all the pieces together. + if pieces == []: + return None + else: + return ''.join(pieces) # Call a PTools function synchronously for any PGDB. def sendQueryToPTools(query): - """ - Send a query to a running Pathway Tools application via a socket. - - Parm - query, a string that the Python server in Pathway Tools can evaluate. - Returns - The result of the query, as a Python object, decoded by Json. - """ - if config._debug: - print 'Sending query '+query - if config._hostname == '': - raise PToolsError('The hostname to connect to a running Pathway Tools has not been set. Use function config.set_hostname() to set the host name of your running Pathway Tools.') - try: - s = so.socket(so.AF_INET, so.SOCK_STREAM) - # Make socket non blocking. - s.setblocking(0) - s.settimeout(360) # The query may take a long time in some cases. - s.connect((config._hostname,config._hostport)) - except so.error, msg: - raise PToolsError('Failed to create a connection to a running Pathway Tools at '+ config._hostname+ ' on port '+ str(config._hostport)+'. Make sure Pathway Tools is running with option -python. Error code: '+str(msg[0])+', error message: '+ msg[1]) - # Send, receive and close socket. - sendAll(s,query) - if config._debug: - print 'Sent '+query+' to Pathway Tools.' - response = recvAll(s) - if config._debug and len(response) < 4000: - print 'JSON Received: ', response - r = json.loads(response) - s.close() - if isinstance(r,basestring) and r.startswith(':error'): - raise PToolsError('An internal error occurred in the running Pathway Tools application: %s' % r) - else: - # Return some result. - return r + """ + Description + Send a query to a running Pathway Tools application via a socket. + + Parm + query, a string that the Python server in Pathway Tools can evaluate. + + Returns + The result of the query, as a Python object, decoded by JSON. + """ + if pythoncyc.config._debug: + print('Sending query ' + query) + + if pythoncyc.config._hostname == '': + raise PToolsError('The hostname to connect to a running Pathway Tools has not been set. Use function pythoncyc.config.set_hostname() to set the host name of your running Pathway Tools.') + + try: + open_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + # Make socket non blocking. + open_socket.setblocking(0) + open_socket.settimeout(360) # The query may take a long time in some cases. + open_socket.connect((pythoncyc.config._hostname, pythoncyc.config._hostport)) + + except socket.error as msg: + raise PToolsError('Failed to create a connection to a running Pathway Tools at ' + pythoncyc.config._hostname + ' on port ' + str(pythoncyc.config._hostport) + '. Make sure Pathway Tools is running with option -python. Error code: ' + str(msg[0]) + ', error message: ' + msg[1]) + + # Send, receive and close socket. + sendAll(open_socket, query.encode()) + + if pythoncyc.config._debug: + print('Sent ' + query + ' to Pathway Tools.') + + response = recvAll(open_socket) + if pythoncyc.config._debug and len(response) < 4000: + print('JSON Received: {:s}'.format(response)) + msg = json.loads(response) + open_socket.close() + + if isinstance(msg, str) and msg.startswith(':error'): + raise PToolsError('An internal error occurred in the running Pathway Tools application: {:s}'.format(msg)) + else: + # Return some result. + return msg class PythonCycError(Exception): - """Error generated by one of the module of PythonCyc due to an incorrect - use of its methods or functions. - """ - pass + """ + Error generated by one of the module of PythonCyc due to an incorrect + use of its methods or functions. + """ + pass class PToolsError(Exception): - """Error generated when Pathway Tools send an error due to its own Lisp execution.""" - pass + """ + Error generated when Pathway Tools send an error due to its own Lisp execution. + """ + pass diff --git a/pythoncyc/PToolsFrame.py b/pythoncyc/PToolsFrame.py index e75ad1f..4d935af 100644 --- a/pythoncyc/PToolsFrame.py +++ b/pythoncyc/PToolsFrame.py @@ -1,5 +1,5 @@ # Copyright (c) 2014, SRI International -# +# # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including @@ -7,10 +7,10 @@ # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: -# +# # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -21,243 +21,238 @@ # ---------------------------------------------------------------------- """ - Please consult file tutorial.html under the doc directory - for an introduction on how to use this class. +Please consult file tutorial.html under the doc directory for an introduction on +how to use this class. """ import sys -import config -from PTools import PToolsError, PythonCycError +import pythoncyc.config +from pythoncyc.PTools import PToolsError, PythonCycError + if 'IPython' in sys.modules: - from IPython.display import display, HTML + from IPython.display import display, HTML def convertLispIdtoPythonId(s): - """ - Convert string s such that it can be a valid Python identifier. - """ - return s.replace('-','_').replace('.','_').replace('?','_p').replace('|','').lower() + """ + Convert string s such that it can be a valid Python identifier. + """ + return s.replace('-','_').replace('.','_').replace('?','_p').replace('|','').lower() class Symbol(): - """ - This class can be used to represent Lisp symbols in PythonCyc. - For example, Symbol('trp') represents the symbol trp. It is mainly used - to ensure that some arguments of methods are interpreted as symbols and not - as strings during the translation to send a request to Pathway Tools. - """ - def __init__(self, name): - self._name = name - return None + """ + This class can be used to represent Lisp symbols in PythonCyc. For example, + Symbol('trp') represents the symbol trp. It is mainly used to ensure that some + arguments of methods are interpreted as symbols and not as strings during the + translation to send a request to Pathway Tools. + """ + def __init__(self, name): + self._name = name + return None class PFrame(): - """ - PFrame is a class to represent Pathway Tools' frames. A PFrame can - represent a class frame (e.g., Reactions) as well as an instance frame - (e.g., RXN-9000). - - The required parameters to create a PFrame are the frame id (a string) and a PGDB - object. For example, assuming that 'meta' is bound to a PGDB object, the following - create a PFrame to represent the reaction RXN-9000, - - PFrame('RXN-9000', meta) - - By default, an instance PFrame (not a class PFrame) is created. - To create a PGDB object, use class PGDB, or call method pythoncyc.so. - - IPython - ------- - - A few methods were written to display frames using HTML in IPython. - Naturally, this functionality is only defined when using IPython as a - Python interpreter. - - Please consult file tutorial.html under the doc directory for an introduction - on how to use this class. - - """ - - def __init__(self, frameid, pgdb, getFrameData=False, isClass = False): - """ - The PFrame is created assuming that the frameid is coercible to a frame in the PGDB. - In particular, the frameid string is not converted and must have the appropriate camel case. - Creation of a PFrame is done lazily when getFrameData is False but is retrieved - now when getFrameData is True. - """ - # Always store the frameid surrounded by vertical bars. - self.__dict__['frameid'] = frameid if (frameid.startswith('|') and frameid.endswith('|')) else '|'+frameid+'|' - self._isclass = isClass - if isClass: - self.__dict__['instances'] = [] - # The complete frame (the slot values) is not created by default. - self._gotframe = False - # This is the PGDB object, not the PGDB name. - self.__dict__['pgdb'] = pgdb - # Add this frame on the list of current frames for this pgdb. - pgdb.__dict__['_frames'][convertLispIdtoPythonId(frameid)] = self - # Retrieve the whole frame from Pathway Tools if requested. - # TBD: add the frame on the list of instances for the corresponding class. - if getFrameData: - self.get_frame_data() - return None - - # The following four definitions are for the pickle (or cPickle) module. - # TBD: this is work in progress. - def __getinitargs__(self): - return (self.frameid, self.pgdb) - - def __getstate__(self): - # Use a compact representation of a PFrame. - return self.vectorize_dict() - - def __setstate__(self, values): - # TBD: Use schema of this PFrame to recreate dictionary. - self.__dict__ = dict - - def vectorize_dict(self): - self.__dict__.values() - - # End of definitions for pickle. - - def __getslice__(self, i, j, stride = None): - if config._debug: - print 'PFrame __getslice__ ', i, j, stride - return self.instances[i:j:stride] - - def __getattr__(self, attr): - # Accessing a slot of the frame using attribute syntax (e.g. r.left) - if config._debug: - print 'PFrame __getattr__ ', attr - - if attr in self.__dict__: - return self.__dict__[attr] - else: - attrId = convertLispIdtoPythonId(attr) - if attrId in self.__dict__: - return self.__dict__[attrId] - - if self._gotframe: - return None - # raise PythonCycError('No slot with name %s exists for frame %s.' % (attr, self.frameid)) - else: - # Get the slot value from Pathway Tools. - self.get_frame_slot_value(attr) - if not (attrId in self.__dict__): - return None - # raise PythonCycError('No slot with name %s exists for frame %s.' % (attr, self.frameid)) - else: - return self.__dict__[attrId] - - def __getitem__(self,attr): - if config._debug: - print "PFrame __getitem__ ", attr - # The slice case is for attr = slice(i,j,s) - if (isinstance(attr,int) or isinstance(attr, slice)): - if 'instances' in self.__dict__: - return self.instances[attr] - else: - raise PythonCycError('Indexing cannot be applied because this is a PFrame which is not a vector and this PFrame has no instances attribute.') - - if attr in self.__dict__: - return self.__dict__[attr] - else: - attrId = convertLispIdtoPythonId(attr) - if attrId in self.__dict__: - return self.__dict__[attrId] - else: - return self.__getattr__(attr) - - def __dir__(self): - return (dir(self.__class__) + self.__dict__.keys()) - - def get_frame_slot_value(self, slot): - """ - Retrieve the slot data for frame from Pathway Tools. - - Return - the self PFrame, modified with the new slot with data. - """ - # FrameObject is a dictionary of slot names and values. - [slotName, value] = self.pgdb.sendPgdbFnCall('get-frame-slot-value', self.frameid, Symbol(slot)) - if not slotName: - raise PythonCycError("Slot "+slot+" does not exist for frame "+self.frameid+" from organism (orgid) "+self.pgdb._orgid) - # Modify slot name to allow Python's syntax (e.g., '_' instead of '-'). - self.__dict__[convertLispIdtoPythonId(slotName)] = value - return self - - - def get_frame_data(self): - """ - Retrieve the frame data from Pathway Tools, that is, all slots and their values - for this PFrame are retrieved and stored locally. For a class, the instances - are not retrieved by this method. Instead, use method get_class_data applied to a PGDB - object. - - Return - the self PFrame, modified with the new slots and data. - """ - # FrameObject is a dictionary of slot names and values. - frameObject = self.pgdb.sendPgdbFnCall('get-frame-object', self.frameid) - if not frameObject: - raise PythonCycError("Could not retrieve frame "+self.frameid+" from organism (orgid) "+self.pgdb._orgid) - else: - self._gotframe = True - # Modify slot names to allow Python's syntax (e.g., '_' instead of '-'). - for slot in frameObject: - self.__dict__[convertLispIdtoPythonId(slot)] = frameObject[slot] - return self - - def __setattr__(self, attr, val): - if not attr.startswith('_'): - raise PythonCycError("PFrames are read only objects. Attributes of PFrame objects cannot be modified "+str((self.frameid,attr,val))+". You can only modify slot frames for the PGDB in the running Pathway Tools by using methods put_slot_value or put_slot_values using a PGDB object.") - self.__dict__[attr] = val - return None - - def __setitem__(self, attr, val): - if not attr.startswith('_'): - raise PythonCycError("PFrames are read only objects. Attributes of PFrame objects cannot be modified "+str((self.frameid,attr,val))+". You can only modify slot frames for the PGDB in the running Pathway Tools by using methods put_slot_value or put_slot_values using a PGDB object.") - self.__dict__[attr] = val - return None - - def __str__(self): - if self._isclass: - return '' - else: - return '' - - def __repr__(self): - if self._isclass: - return self.__str__() - else: - return str(self.__dict__) - - if 'IPython' in sys.modules: - def _ipython_display_(self): - table = '' - if not self._isclass: - for attr in sorted(self.__dict__): - if not (attr.startswith('_')): - table = table+""+str(attr)+""+str(self.__dict__[attr])+"" - else: - table = table+'Class '+self.frameid+' has '+str(self._nb_pframes())+' instances' - if table == '': - table = '' + self.__str__() + '' - table = ''+ table + '
' - display(HTML(table)) - - def _nb_pframes(self): - return len(self.instances) - - def __eq__(self, frame): - # If the given frame is a string, it is assumed to be a frameid. - if isinstance(frame, str): - return self.frameid == frame - # Otherwise it could be a Frame. - elif isinstance(frame, PFrame): - # TBD: should we consider the name of the pgdb? - return (self.pgdb == frame.pgdb) and (self.frameid == frame.frameid) - # Otherwise it cannot be equal to this object. - else: return False - - def __ne__(self, frame): - return not self.__eq__(frame) - - + """ + PFrame is a class to represent Pathway Tools' frames. A PFrame can represent a + class frame (e.g., Reactions) as well as an instance frame (e.g., RXN-9000). + + The required parameters to create a PFrame are the frame id (a string) and a + PGDB object. For example, assuming that 'meta' is bound to a PGDB object, the + following create a PFrame to represent the reaction RXN-9000, + + PFrame('RXN-9000', meta) + + By default, an instance PFrame (not a class PFrame) is created. + To create a PGDB object, use class PGDB, or call method pythoncyc.so. + + IPython + ------- + + A few methods were written to display frames using HTML in IPython. Naturally, + this functionality is only defined when using IPython as a Python interpreter. + + Please consult file tutorial.html under the doc directory for an introduction on + how to use this class. + """ + + def __init__(self, frameid, pgdb, getFrameData=False, isClass = False): + """ + The PFrame is created assuming that the frameid is coercible to a frame in the + PGDB. In particular, the frameid string is not converted and must have the + appropriate camel case. Creation of a PFrame is done lazily when getFrameData is + False but is retrieved now when getFrameData is True. + """ + # Always store the frameid surrounded by vertical bars. + self.__dict__['frameid'] = frameid if (frameid.startswith('|') and frameid.endswith('|')) else '|'+frameid+'|' + self._isclass = isClass + if isClass: + self.__dict__['instances'] = [] + # The complete frame (the slot values) is not created by default. + self._gotframe = False + # This is the PGDB object, not the PGDB name. + self.__dict__['pgdb'] = pgdb + # Add this frame on the list of current frames for this pgdb. + pgdb.__dict__['_frames'][convertLispIdtoPythonId(frameid)] = self + # Retrieve the whole frame from Pathway Tools if requested. + # TBD: add the frame on the list of instances for the corresponding class. + if getFrameData: + self.get_frame_data() + return None + + # The following four definitions are for the pickle (or cPickle) module. + # TBD: this is work in progress. + def __getinitargs__(self): + return (self.frameid, self.pgdb) + + def __getstate__(self): + # Use a compact representation of a PFrame. + return self.vectorize_dict() + + def __setstate__(self, values): + # TBD: Use schema of this PFrame to recreate dictionary. + self.__dict__ = dict + + def vectorize_dict(self): + self.__dict__.values() + + # End of definitions for pickle. + + def __getslice__(self, i, j, stride = None): + if pythoncyc.config._debug: + print('PFrame __getslice__ ', i, j, stride) + return self.instances[i:j:stride] + + def __getattr__(self, attr): + # Accessing a slot of the frame using attribute syntax (e.g. r.left) + if pythoncyc.config._debug: + print('PFrame __getattr__ ', attr) + + if attr in self.__dict__: + return self.__dict__[attr] + else: + attrId = convertLispIdtoPythonId(attr) + if attrId in self.__dict__: + return self.__dict__[attrId] + + if self._gotframe: + return None + # raise PythonCycError('No slot with name %s exists for frame %s.' % (attr, self.frameid)) + else: + # Get the slot value from Pathway Tools. + self.get_frame_slot_value(attr) + if not (attrId in self.__dict__): + return None + # raise PythonCycError('No slot with name %s exists for frame %s.' % (attr, self.frameid)) + else: + return self.__dict__[attrId] + + def __getitem__(self,attr): + if pythoncyc.config._debug: + print("PFrame __getitem__ ", attr) + # The slice case is for attr = slice(i,j,s) + if (isinstance(attr,int) or isinstance(attr, slice)): + if 'instances' in self.__dict__: + return self.instances[attr] + else: + raise PythonCycError('Indexing cannot be applied because this is a PFrame which is not a vector and this PFrame has no instances attribute.') + + if attr in self.__dict__: + return self.__dict__[attr] + else: + attrId = convertLispIdtoPythonId(attr) + if attrId in self.__dict__: + return self.__dict__[attrId] + else: + return self.__getattr__(attr) + + def __dir__(self): + return (dir(self.__class__) + self.__dict__.keys()) + + def get_frame_slot_value(self, slot): + """ + Retrieve the slot data for frame from Pathway Tools. + + Return + the self PFrame, modified with the new slot with data. + """ + # FrameObject is a dictionary of slot names and values. + [slotName, value] = self.pgdb.sendPgdbFnCall('get-frame-slot-value', self.frameid, Symbol(slot)) + if not slotName: + raise PythonCycError("Slot " + slot + " does not exist for frame " + self.frameid + " from organism (orgid) " +self.pgdb._orgid) + # Modify slot name to allow Python's syntax (e.g., '_' instead of '-'). + self.__dict__[convertLispIdtoPythonId(slotName)] = value + return self + + def get_frame_data(self): + """ + Retrieve the frame data from Pathway Tools, that is, all slots and their values + for this PFrame are retrieved and stored locally. For a class, the instances are + not retrieved by this method. Instead, use method get_class_data applied to a + PGDB object. + + Return + the self PFrame, modified with the new slots and data. + """ + # FrameObject is a dictionary of slot names and values. + frameObject = self.pgdb.sendPgdbFnCall('get-frame-object', self.frameid) + if not frameObject: + raise PythonCycError("Could not retrieve frame " + self.frameid + " from organism (orgid) " + self.pgdb._orgid) + else: + self._gotframe = True + # Modify slot names to allow Python's syntax (e.g., '_' instead of '-'). + for slot in frameObject: + self.__dict__[convertLispIdtoPythonId(slot)] = frameObject[slot] + return self + + def __setattr__(self, attr, val): + if not attr.startswith('_'): + raise PythonCycError("PFrames are read only objects. Attributes of PFrame objects cannot be modified " + str((self.frameid,attr,val)) + ". You can only modify slot frames for the PGDB in the running Pathway Tools by using methods put_slot_value or put_slot_values using a PGDB object.") + self.__dict__[attr] = val + return None + + def __setitem__(self, attr, val): + if not attr.startswith('_'): + raise PythonCycError("PFrames are read only objects. Attributes of PFrame objects cannot be modified " + str((self.frameid,attr,val)) + ". You can only modify slot frames for the PGDB in the running Pathway Tools by using methods put_slot_value or put_slot_values using a PGDB object.") + self.__dict__[attr] = val + return None + + def __str__(self): + if self._isclass: + return '' + else: + return '' + + def __repr__(self): + if self._isclass: + return self.__str__() + else: + return str(self.__dict__) + + if 'IPython' in sys.modules: + def _ipython_display_(self): + table = '' + if not self._isclass: + for attr in sorted(self.__dict__): + if not (attr.startswith('_')): + table = table + "" + str(attr) + "" + str(self.__dict__[attr]) + "" + else: + table = table + 'Class ' + self.frameid + ' has ' + str(self._nb_pframes()) + ' instances' + if table == '': + table = '' + self.__str__() + '' + table = ''+ table + '
' + display(HTML(table)) + + def _nb_pframes(self): + return len(self.instances) + + def __eq__(self, frame): + # If the given frame is a string, it is assumed to be a frameid. + if isinstance(frame, str): + return self.frameid == frame + # Otherwise it could be a Frame. + elif isinstance(frame, PFrame): + # TBD: should we consider the name of the pgdb? + return (self.pgdb == frame.pgdb) and (self.frameid == frame.frameid) + # Otherwise it cannot be equal to this object. + else: return False + + def __ne__(self, frame): + return not self.__eq__(frame) diff --git a/pythoncyc/__init__.py b/pythoncyc/__init__.py index 26d6057..15115dc 100644 --- a/pythoncyc/__init__.py +++ b/pythoncyc/__init__.py @@ -1,5 +1,5 @@ # Copyright (c) 2014, SRI International -# +# # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including @@ -7,10 +7,10 @@ # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: -# +# # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -40,9 +40,9 @@ Please consult the tutorial.html file, under directory doc, for more information about how to use PythonCyc. """ - -from PGDB import PGDB -from PTools import sendQueryToPTools +import pythoncyc.config +from pythoncyc.PGDB import PGDB +from pythoncyc.PTools import sendQueryToPTools def select_organism(orgid): """ @@ -56,9 +56,9 @@ def so(orgid): return select_organism(orgid) def all_orgids(): - """ - Returns all organism unique ids (orgids) available - from the current running Pathway Tools. + """ + Returns all organism unique ids (orgids) available + from the current running Pathway Tools. """ orgids = sendQueryToPTools('(all-orgids)') return orgids @@ -66,16 +66,16 @@ def all_orgids(): def biovelo(query): """ Execute a BioVelo query and return the result. - + Parameters query: a string, which is a BioVelo query. - Returns + Returns Whatever the BioVelo query computes. - + Example bv('[(p, reactions-of-pathway(p)): p<-ecoli^^pathways]') """ - return sendQueryToPTools('(biovelo "'+query+'")') + return sendQueryToPTools('(biovelo "' + query + '")') def bv(query): """ @@ -92,5 +92,4 @@ def run_fba(fileName): For the documentation of this function, see method run_fba in file PGDB.py. """ - return sendQueryToPTools('(python-run-fba "'+fileName+'")') - + return sendQueryToPTools('(python-run-fba "' + fileName + '")') diff --git a/pythoncyc/config.py b/pythoncyc/config.py index 04c57d8..cfa28e8 100644 --- a/pythoncyc/config.py +++ b/pythoncyc/config.py @@ -1,5 +1,5 @@ # Copyright (c) 2014, SRI International -# +# # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including @@ -7,10 +7,10 @@ # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: -# +# # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -21,10 +21,10 @@ # ---------------------------------------------------------------------- """ -This module can be used to set various parameters for PythonCyc, -in particular to set debug on or off, the host name and port number -of the running Pathway Tools' Python server. By default, the Pathway Tools -Python server is running locally on port 5008. +This module can be used to set various parameters for PythonCyc, in particular +to set debug on or off, the host name and port number of the running Pathway +Tools' Python server. By default, the Pathway Tools Python server is running +locally on port 5008. """ _debug = False @@ -32,30 +32,31 @@ _hostport = 5008 def set_debug_on(): - """ - Turn on debug mode for PythonCyc. - Turning on debugging should turn on output tracings of the communications between PythonCyc and Pathway Tools. - """ - global _debug - _debug = True - print 'Debug on.' - -def set_debug_off(): - """ - Turn off debug mode for PythonCyc. - Turning off debugging should turn off all output tracings of the communications between PythonCyc and Pathway Tools. + """ + Turn on debug mode for PythonCyc. + Turning on debugging should turn on output tracings of the communications + between PythonCyc and Pathway Tools. + """ + global _debug + _debug = True + print('Debug on.') - """ - global _debug - _debug = False - print 'Debug off.' +def set_debug_off(): + """ + Turn off debug mode for PythonCyc. + Turning off debugging should turn off all output tracings of the communications + between PythonCyc and Pathway Tools. + """ + global _debug + _debug = False + print('Debug off.') def set_host_name(hostname): - global _hostname - _hostname = hostname - print 'PythonCyc will communicate with Pathway Tools running on host name ',_hostname + global _hostname + _hostname = hostname + print('PythonCyc will communicate with Pathway Tools running on host name {:s}'.format(_hostname)) def set_host_port(hostport): - global _hostport - _hostport = hostport - print 'PythonCyc will communicate with Pathway Tools running on host port ',_hostport + global _hostport + _hostport = hostport + print('PythonCyc will communicate with Pathway Tools running on host port {:d}'.format(_hostport)) diff --git a/setup.py b/setup.py index ac4ad2f..84a3f3c 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ # Copyright (c) 2014, SRI International -# +# # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including @@ -7,10 +7,10 @@ # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: -# +# # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -20,15 +20,58 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # ---------------------------------------------------------------------- -from distutils.core import setup - -setup( - name='PythonCyc', - version='1.0', - author='Mario Latendresse', - author_email='latendre@ai.sri.com', - packages=['pythoncyc'], - license='LICENSE', - description='A Python interface to Pathway Tools', - long_description=open('README.md').read() - ) +# Always prefer setuptools over distutils +from setuptools import setup, find_packages +# To use a consistent encoding +from codecs import open +from os import path, walk + +def main(): + # additional files + data_files = [] + for dirpath, dirnames, filenames in walk('examples'): + tmp = [] + for filename in filenames: + tmp.append(path.join(dirpath, filename)) + data_files.append((dirpath, tmp)) + #print(data_files) + + # Get the long description from the README file + here = path.abspath(path.dirname(__file__)) + with open(path.join(here, 'README.md'), encoding='utf-8') as f: + long_description = f.read() + + setup( + name='PythonCyc', + license='SRI International', + version='2.0.2', + description='A Python interface to Pathway Tools, 2019 update', + long_description=long_description, + #long_description_content_type='text/markdown', + url='https://github.com/networkbiolab/PythonCyc', + author='Rodrigo Santibáñez', + author_email='glucksfall@users.noreply.github.com', + + python_requires='~=3.0', + keywords=[], + install_requires=[], + + # include files + # MANIFEST.in, sdist + include_package_data=True, + # bdist_wheel (only for non-python files inside of the package) + packages=find_packages(exclude=['contrib', 'docs', 'tests']), + #package_data = { + #'PythonCyc' : ['test/*.txt'] + #}, + data_files=data_files, + + project_urls={ + 'Manual': 'https://pythoncyc-v20.readthedocs.io', + 'Bug Reports': 'https://github.com/networkbiolab/PythonCyc/issues', + 'Source': 'https://github.com/networkbiolab/PythonCyc', + }, + ) + +if __name__ == '__main__': + main()