Skip to content

Latest commit

 

History

History
128 lines (81 loc) · 4.3 KB

api.rst

File metadata and controls

128 lines (81 loc) · 4.3 KB

API reference

Graph

.. py:class:: biocomposer.Graph()

   A pipeline: a set of nodes and the directed edges between them. Building a graph
   only describes the pipeline; nothing runs until :py:meth:`execute` is called.

   .. py:method:: add_input_node(**values)

      Add an :doc:`input node <nodes/input>` holding the values you supply, as
      keyword arguments (file paths and scalar parameters). Keys must match the
      input names declared by the downstream tool. Returns an
      :py:class:`~biocomposer.InputNode`.

   .. py:method:: add_node(tool_name, gpu=None, args_override=None, entrypoint_override=None)

      Add a :doc:`tool node <nodes/tool>` for a tool from the registry. Returns a
      :py:class:`~biocomposer.Node`.

      :param str tool_name: registry name of the tool, e.g. ``"clustalo"``.
      :param str gpu: optional GPU type to request for this tool.
      :param str args_override: replace the tool's default argument template for
         this node only.
      :param str entrypoint_override: run a different program exposed by the tool's
         image.

   .. py:method:: add_gather_node(tool_name, split_key, gpu=None, args_override=None, entrypoint_override=None)

      Add a :doc:`gather node <nodes/gather>`, which runs a one-item-per-run tool
      once for each item of an upstream collection and gathers the outputs into
      lists. Returns a :py:class:`~biocomposer.GatherNode`.

      :param str split_key: name of the upstream output that holds the collection.

      The remaining parameters are the same as for :py:meth:`add_node`.

   .. py:method:: add_decision_node(score_fn, conditions, modifier_tool)

      Add a :doc:`decision node <nodes/decision>`, which re-runs its upstream tool
      until a scored condition holds. Returns a :py:class:`~biocomposer.DecisionNode`.

      :param score_fn: a Python function or the name of a registry tool that
         produces a numeric score from the upstream output.
      :param list conditions: a list of :py:class:`~biocomposer.Condition`; all must
         hold to stop.
      :param modifier_tool: a Python function or the name of a registry tool that
         produces the upstream's adjusted inputs for the next iteration.

   .. py:method:: add_edge(*edges)

      Wire nodes together. Each edge is a ``(upstream, downstream)`` tuple; several
      may be passed in one call. Either endpoint may be a node or a
      :py:class:`~biocomposer.SubGraph`.

   .. py:method:: set_output_node(node)

      Mark ``node`` as an output of the graph. May be called more than once to
      declare several outputs. See :doc:`nodes/output`.

   .. py:method:: execute()

      Run the graph and return a list with one result per output node, in the order
      the output nodes were set. See :doc:`execute`.

   .. py:method:: set_llm(provider, model, api_key)

      Choose the LLM provider and model used to generate connectors. ``provider``
      is one of ``"anthropic"``, ``"openai"`` or ``"google"``. See :doc:`running`.

Nodes

Nodes are created through the Graph.add_* methods above rather than directly.

.. py:class:: biocomposer.Node

   A tool node. See :doc:`nodes/tool`.

.. py:class:: biocomposer.InputNode

   An input node. See :doc:`nodes/input`.

   .. py:method:: set_input(**values)

      Set or replace the values held by this input node.

.. py:class:: biocomposer.GatherNode

   A gather node. See :doc:`nodes/gather`.

.. py:class:: biocomposer.DecisionNode

   A decision node. See :doc:`nodes/decision`.

.. py:class:: biocomposer.OutputNode

   See :doc:`nodes/output`.

SubGraph

.. py:class:: biocomposer.SubGraph()

   A pipeline with exactly one input node and one output node that behaves as a
   single node in an outer graph. It is built with the same ``add_input_node``,
   ``add_node``, ``add_edge`` and ``set_output_node`` methods as a
   :py:class:`~biocomposer.Graph`. See :doc:`nodes/subgraph`.

   .. py:method:: run(inputs)

      Execute the subgraph directly with a dict of fresh input values.

Conditions

.. py:class:: biocomposer.Condition(comparator, a)

   A comparison applied to a decision node's score, for example
   ``Condition(">=", 3)``. Supported comparators are ``>``, ``<``, ``>=``, ``<=``,
   ``==`` and ``!=``.

   .. py:method:: check(x)

      Return ``True`` if ``x`` satisfies the condition.