Ask Pathway Tools logo   Pathway Tools Question & Answer forum for SRI's Pathway Tools

Ask Your Question

PythonCyc: obtain only children classes

asked 2017-08-16 11:55:36 -0600

jo gravatar image

Using get_class_all_subs I get access all subclasses with the PythonCyc API. How can I get only the direct subclasses (children) without the other deeper subclasses? Is there something like a parent or children attribute for a class?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-08-18 18:05:06 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.


Indeed, the method getclassall_subs returns all subclasses of a given class. Unfortunately, there is no explicit PythonCyc function to get the direct subclasses and no parent or children attribute exists. Depending on the specific problem you are trying to solve, perhaps there is no need to use a general method to get the subclasses. Also, if you are running in a secure and closed environment you can run the PythonCyc server such that any Lisp expression is accepted and bypassed this limitation by starting Pathway Tools with the option -python-local-only-non-strict. The Lisp fn get-class-direct-subs returns the direct subclasses. For example, evaluating

(get-class-direct-subs '|Reactions|)

returns the list (#<"Unclassified-Reactions" class frame in METABASE[F] @ #x10035ddebf2> #<"Reactions-Classified-By-Substrate" class frame in METABASE[F] @ #x10035ddebc2> #<"Reactions-Classified-By-Conversion-Type" class frame in METABASE[F] @ #x10035ddeb92>)

You could return the names only by applying the get-frame-name fn as in

(mapcar '#get-frame-name (get-class-direct-subs '|Reactions|))

Such Lisp expression would need to be sent using the PythonCyc method sendQueryToPTools defined in module PTools. For the documentation and source of that fn, please see:

Let us know if that answers your question.

-- Mario Latendresse

edit flag offensive delete link more


Great this is working thank you! Using your first command, I can already return only frame names in pythoncyc. Do you know how I can change the database? In my case it is fixed to ECOBASE.

jo gravatar imagejo ( 2017-08-20 09:07:37 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-08-16 11:55:36 -0600

Seen: 3,079 times

Last updated: Aug 18 '17