Tracking records that could not be processed#

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=FALSE, origin=take_named_seqs, source="primate_brca1.fasta", message="named seq(s) {'Mouse'} not in ['Galago', 'HowlerMon', 'Rhesus', 'Orangutan', 'Gorilla', 'Human', 'Chimpanzee']")

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
"named seq(s) {'Mouse'} not in ['Galago', 'HowlerMon', 'Rhesus', 'Orangutan', 'Gorilla', 'Human', 'Chimpanzee']"

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 384, 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 307, in main
    return _load_seqs(path, ArrayAlignment, 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 275, in _load_seqs
    data = _read_it(path)
           ^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/functools.py", line 907, 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 271, in _
    return _read_it(Path(path))
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/functools.py", line 907, 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 266, in _
    return path.read_text()
           ^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.7/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.7/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=FALSE, origin=take_named_seqs, source="primate_brca1.fasta", message="named seq(s) {'Mouse'} not in ['Galago', 'HowlerMon', 'Rhesus', 'Orangutan', 'Gorilla', 'Human', 'Chimpanzee']")

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 384, 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 307, in main
    return _load_seqs(path, ArrayAlignment, 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 275, in _load_seqs
    data = _read_it(path)
           ^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/functools.py", line 907, 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 271, in _
    return _read_it(Path(path))
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/functools.py", line 907, 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 266, in _
    return path.read_text()
           ^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.7/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.7/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'
")