Tracking records that could not be processed#

Note

These docs now use the new_type core objects via the following setting.

import os

# using new types without requiring an explicit argument
os.environ["COGENT3_NEW_TYPE"] = "1"

The NotCompleted object#

NotCompleted is a special result type that can be produced by a composable app. These objects evaluate to False.

An app can return a NotCompleted result for one of 2 reasons. The object contains information regarding the input data, where the issue arose and whatever message was provided by the code (like an exception traceback).

NotCompleted FALSE type#

The results when a condition was not met. For example, below I create an app that will return alignments with 2 specific sequences. I’m applying this to a data set where a “Mouse” sequence does not exist. This will produce a FALSE type.

from cogent3 import get_app

reader = get_app("load_aligned", format="fasta")
select_seqs = get_app("take_named_seqs", "Mouse", "Human")
aln = reader("data/primate_brca1.fasta")
result = select_seqs(aln)
assert result == False
result
NotCompleted(type=ERROR, origin=take_named_seqs, source="primate_brca1.fasta", message="Traceback (most recent call last):
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/composable.py", line 401, in _call
    result = self.main(val, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/sample.py", line 533, in main
    data = data.take_seqs(self._names, negate=self._negate)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/core/new_alignment.py", line 871, in take_seqs
    raise ValueError(msg)
ValueError: The following provided names not found in collection: {'Mouse'}
")

The NotCompleted instance has attributes identifying what data failed,

result.source
'primate_brca1.fasta'

where the failure occurred

result.origin
'take_named_seqs'

and the reason for the failure

result.message
'Traceback (most recent call last):\n  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/composable.py", line 401, in _call\n    result = self.main(val, *args, **kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/sample.py", line 533, in main\n    data = data.take_seqs(self._names, negate=self._negate)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/core/new_alignment.py", line 871, in take_seqs\n    raise ValueError(msg)\nValueError: The following provided names not found in collection: {\'Mouse\'}\n'

NotCompleted ERROR type#

An ERROR type is returned if an unexpected condition occurs. This can be an exception raised during the calculation. In our example, we illustrate this by trying to open a file with an incorrect path.

result = reader("primate_brca1.fasta")
result
NotCompleted(type=ERROR, origin=load_aligned, source="primate_brca1.fasta", message="Traceback (most recent call last):
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/composable.py", line 401, in _call
    result = self.main(val, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/io.py", line 333, in main
    return _load_seqs(path, cogent3.make_aligned_seqs, self._parser, self.moltype)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/io.py", line 293, in _load_seqs
    data = _read_it(path)
           ^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.10/x64/lib/python3.12/functools.py", line 912, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/io.py", line 283, in _
    return _read_it(Path(path))
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.10/x64/lib/python3.12/functools.py", line 912, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/io.py", line 278, in _
    return path.read_text()
           ^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.10/x64/lib/python3.12/pathlib.py", line 1027, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.10/x64/lib/python3.12/pathlib.py", line 1013, in open
    return io.open(self, mode, buffering, encoding, errors, newline)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/runner/work/cogent3.github.io/cogent3.github.io/c3org/doc/doc/primate_brca1.fasta'
")

Composed functions propagate NotCompleted results#

If you have a composed function, with multiple steps and an error occurs then the resulting NotCompleted result is returned without any of the other steps being applied to it. For example, we make a composed app from both of the above apps.

app = reader + select_seqs
result = app("data/primate_brca1.fasta")
result
NotCompleted(type=ERROR, origin=take_named_seqs, source="primate_brca1.fasta", message="Traceback (most recent call last):
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/composable.py", line 401, in _call
    result = self.main(val, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/sample.py", line 533, in main
    data = data.take_seqs(self._names, negate=self._negate)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/core/new_alignment.py", line 871, in take_seqs
    raise ValueError(msg)
ValueError: The following provided names not found in collection: {'Mouse'}
")

and

result = app("primate_brca1.fasta")
result
NotCompleted(type=ERROR, origin=load_aligned, source="primate_brca1.fasta", message="Traceback (most recent call last):
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/composable.py", line 401, in _call
    result = self.main(val, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/io.py", line 333, in main
    return _load_seqs(path, cogent3.make_aligned_seqs, self._parser, self.moltype)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/io.py", line 293, in _load_seqs
    data = _read_it(path)
           ^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.10/x64/lib/python3.12/functools.py", line 912, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/io.py", line 283, in _
    return _read_it(Path(path))
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.10/x64/lib/python3.12/functools.py", line 912, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cogent3.github.io/cogent3.github.io/.venv/lib/python3.12/site-packages/cogent3/app/io.py", line 278, in _
    return path.read_text()
           ^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.10/x64/lib/python3.12/pathlib.py", line 1027, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.10/x64/lib/python3.12/pathlib.py", line 1013, in open
    return io.open(self, mode, buffering, encoding, errors, newline)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/runner/work/cogent3.github.io/cogent3.github.io/c3org/doc/doc/primate_brca1.fasta'
")