Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.pyc
__pycache__
*.egg-info
build/*
dist/*
doc/_build

.ipynb_checkpoints
55 changes: 55 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include examples/*ipynb
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
============================
Expand Down Expand Up @@ -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

Expand Down
272 changes: 272 additions & 0 deletions examples/Operations_on_Compounds.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
Loading